Closed mowali closed 1 week ago
Maybe I am missing something, but why aren't you using the built-in string comparer (TermOrdValComparer) with reverse support?
If the custom FieldComparer
is required, your main issue is that you are allocating memory inside of the comparison methods. Comparers should only allocate memory in the class constructor and/or field initializers, never in the comparison methods, because this will cause a lot of garbage collection overhead.
public override void Copy(int slot, int doc)
{
termCopy = new BytesRef(); // Expensive allocation. This method will be called a lot.
sortedResults.Get(doc, termCopy);
bvalues[slot] = termCopy;
}
public override int CompareBottom(int doc)
{
BytesRef termOrd = new BytesRef(); // Expensive allocation. This method will be called a lot.
int ord = sortedResults.GetOrd(doc);
sortedResults.LookupOrd(ord, termOrd); // Expensive lookup. The TermOrdValComparer only does lookups in the Copy() method and only when necessary.
var result = DoCompare(bvalues[bottomSlot], termOrd);
return result;
}
Also, the TermOrdValComparer uses ords to do the comparison in most cases, falling back to term comparison only when necessary. See the TermOrdValComparer
docs and FieldComparer<T>
docs.
See response from @NightOwl888 above. Feel free to reopen if you feel like there is more to discuss here. Thanks!
Is there an existing issue for this?
Task description
I updated from Lucene from 3.0 to 4.8, I amended my FieldComparer code. I use a comparator to get results back and I get the results via the call to SetNextReader. I only have 1 indexreader to read from:
the older verison SetNextReader is executed once correctly and returning 100 results of while the new SetNextReader executes multiple time and returning only one result. Attached is my old and new code. The searcher is setup like this: