Skip to content

Commit

Permalink
Fixing termFrequencyStatistics helper.
Browse files Browse the repository at this point in the history
  • Loading branch information
afoucret committed Apr 30, 2024
1 parent 002d21d commit 7771036
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.apache.lucene.index.PostingsEnum;
import org.apache.lucene.index.ReaderUtil;
import org.apache.lucene.index.Term;
import org.apache.lucene.index.TermState;
import org.apache.lucene.index.TermStates;
import org.apache.lucene.index.TermsEnum;
import org.elasticsearch.search.lookup.SearchLookup;
Expand Down Expand Up @@ -65,8 +66,14 @@ private TermsStatsReader buildTermStatsReader(String fieldName, String query) th
TermStates termContext = searchLookup.getTermStates(term);
termStates.put(term, termContext);

TermState state = termContext.get(leafReaderContext);

if (state == null || termContext.docFreq() == 0) {
continue;
}

TermsEnum termsEnum = leafReaderContext.reader().terms(term.field()).iterator();
termsEnum.seekExact(term.bytes(), termContext.get(leafReaderContext));
termsEnum.seekExact(term.bytes(), state);
postingsEnums.put(term, termsEnum.postings(null, PostingsEnum.ALL));
}
}
Expand Down

0 comments on commit 7771036

Please sign in to comment.