Skip to content

Commit

Permalink
Fix split package org.apache.lucene.queryparser.classic (#78307)
Browse files Browse the repository at this point in the history
With LUCENE-10115 integrated, we can now remove the package
-private dependency with org.apache.lucene.queryparser.classic.
XQueryParser, and override getFuzzyDistance to customise the
calculation of the similarity distance for fuzzy queries.
  • Loading branch information
ChrisHegarty authored Sep 27, 2021
1 parent 28c74a0 commit 9f3b251
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 40 deletions.
3 changes: 1 addition & 2 deletions server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,7 @@ tasks.named("licenseHeaders").configure {

tasks.named('splitPackagesAudit').configure {
// Lucene packages should be owned by Lucene!
ignoreClasses 'org.apache.lucene.queryparser.classic.XQueryParser',
'org.apache.lucene.queries.BinaryDocValuesRangeQuery',
ignoreClasses 'org.apache.lucene.queries.BinaryDocValuesRangeQuery',
'org.apache.lucene.queries.BlendedTermQuery',
'org.apache.lucene.queries.SpanMatchNoDocsQuery',
'org.apache.lucene.search.grouping.CollapseTopFieldDocs',
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import org.apache.lucene.queries.spans.SpanOrQuery;
import org.apache.lucene.queries.spans.SpanQuery;
import org.apache.lucene.queryparser.classic.ParseException;
import org.apache.lucene.queryparser.classic.QueryParser;
import org.apache.lucene.queryparser.classic.Token;
import org.apache.lucene.queryparser.classic.XQueryParser;
import org.apache.lucene.search.BooleanClause;
import org.apache.lucene.search.BoostAttribute;
import org.apache.lucene.search.BoostQuery;
Expand Down Expand Up @@ -64,12 +64,12 @@
import static org.elasticsearch.index.search.QueryParserHelper.resolveMappingFields;

/**
* A {@link XQueryParser} that uses the {@link MapperService} in order to build smarter
* A {@link QueryParser} that uses the {@link MapperService} in order to build smarter
* queries based on the mapping information.
* This class uses {@link MultiMatchQueryParser} to build the text query around operators and {@link XQueryParser}
* This class uses {@link MultiMatchQueryParser} to build the text query around operators and {@link QueryParser}
* to assemble the result logically.
*/
public class QueryStringQueryParser extends XQueryParser {
public class QueryStringQueryParser extends QueryParser {
private static final String EXISTS_FIELD = "_exists_";

private final SearchExecutionContext context;
Expand Down Expand Up @@ -433,12 +433,11 @@ private Query getRangeQuerySingle(String field, String part1, String part2,
}

@Override
protected Query handleBareFuzzy(String field, Token fuzzySlop, String termImage) throws ParseException {
if (fuzzySlop.image.length() == 1) {
return getFuzzyQuery(field, termImage, fuzziness.asDistance(termImage));
protected float getFuzzyDistance(Token fuzzyToken, String termStr) {
if (fuzzyToken.image.length() == 1) {
return fuzziness.asDistance(termStr);
}
float distance = Fuzziness.fromString(fuzzySlop.image.substring(1)).asDistance(termImage);
return getFuzzyQuery(field, termImage, distance);
return Fuzziness.fromString(fuzzyToken.image.substring(1)).asDistance(termStr);
}

@Override
Expand Down

0 comments on commit 9f3b251

Please sign in to comment.