Skip to content

Commit

Permalink
get around private term enum constructor in lucene 8.5
Browse files Browse the repository at this point in the history
  • Loading branch information
mdavis95 committed Jun 8, 2020
1 parent 715443a commit 9c1394e
Showing 1 changed file with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.apache.lucene.index.Terms;
import org.apache.lucene.index.TermsEnum;
import org.apache.lucene.search.BoostAttribute;
import org.apache.lucene.search.FuzzyTermsEnum;
import org.apache.lucene.search.FuzzyQuery;
import org.apache.lucene.search.MaxNonCompetitiveBoostAttribute;
import org.apache.lucene.util.AttributeSource;
import org.apache.lucene.util.BytesRef;
Expand All @@ -25,6 +25,18 @@

public class ShardTermsHandler {

public static class PublicFuzzyQuery extends FuzzyQuery {

public PublicFuzzyQuery(Term term, int maxEdits, int prefixLength, int maxExpansions, boolean transpositions) {
super(term, maxEdits, prefixLength, maxExpansions, transpositions);
}

@Override
public TermsEnum getTermsEnum(Terms terms, AttributeSource atts) throws IOException {
return super.getTermsEnum(terms, atts);
}
}

private final DirectoryReader indexReader;

public ShardTermsHandler(DirectoryReader indexReader) {
Expand Down Expand Up @@ -105,8 +117,14 @@ public GetTermsResponse handleShardTerms(GetTermsRequest request) throws IOExcep

if (hasFuzzyTerm) {
ZuliaBase.FuzzyTerm fuzzyTerm = request.getFuzzyTerm();
FuzzyTermsEnum termsEnum = new FuzzyTermsEnum(terms, atts, new Term(fieldName, fuzzyTerm.getTerm()), fuzzyTerm.getEditDistance(),
fuzzyTerm.getPrefixLength(), !fuzzyTerm.getNoTranspositions());

Term term = new Term(fieldName, fuzzyTerm.getTerm());

PublicFuzzyQuery fuzzyQuery = new PublicFuzzyQuery(term, fuzzyTerm.getEditDistance(), fuzzyTerm.getPrefixLength(),
FuzzyQuery.defaultMaxExpansions, !fuzzyTerm.getNoTranspositions());

TermsEnum termsEnum = fuzzyQuery.getTermsEnum(terms, atts);

BytesRef text = termsEnum.term();

handleTerm(termsMap, termsEnum, text, termFilter, termMatch);
Expand Down

0 comments on commit 9c1394e

Please sign in to comment.