It's the logic used in Lucene. The code in this method is mostly coming from Lucene. I only changed very few things.

Same comment for your other comments on this method.

I haven't spent much time reviewing this as I'm mostly working on seeing how it could fit in Hibernate Search. We should review that later IMHO.