The fix I was working on was to remove the optimization altogether. With it removed, recursiveGetNodes() can be rewritten to be remarkably simpler and combined with the Point specialization of this method into one. I've already done this locally and the code is easier to read and debug. However the optimization is probably a noticeable benefit for the TermQuery strategy. Perhaps this implementation could move to TermQueryPrefixTreeStrategy. Alternatively it would be cool if the nodes could be pruned after the fact (in the strategy) but that would be hard since nodes are flattened into a list. I'm leaning towards moving this implementation to the strategy where I can see ways it could even be optimized more by bubbling this pruning up from now only the bottom level but up additional levels. Thoughts?
p.s. the condition subCells.size() == node.getSubCellsSize() && !inclParents is not enough, it must also be true that node.getLevel() != 0 because the 0 node is not indexable (no empty string).