Allow ngrams to be searched even if they appear deeply nested
One of the bullet points of #498. This MR allows ngram terms nested in a tree to be searched, as before it wasn't the case.
DEMO
In order to support nested search, we need to be able to recursively search within the children in a tree -- for this reason I have also added support for loop detection inside buildForest
. This is good for now, but in practice we shouldn't even pass to buildForest
a Map NgramsTerm NgramsElement
with cycles.