Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CommonTermsQuery fix for ignored coordination factor #11780

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -64,7 +64,7 @@ public static enum Operator {

private String highFreqMinimumShouldMatch = null;

private Boolean disableCoords = null;
private Boolean disableCoord = null;

private Float cutoffFrequency = null;

Expand Down Expand Up @@ -150,6 +150,11 @@ public CommonTermsQueryBuilder lowFreqMinimumShouldMatch(String lowFreqMinimumSh
this.lowFreqMinimumShouldMatch = lowFreqMinimumShouldMatch;
return this;
}

public CommonTermsQueryBuilder disableCoord(boolean disableCoord) {
this.disableCoord = disableCoord;
return this;
}

/**
* Sets the query name for the filter that can be used when searching for matched_filters per hit.
Expand All @@ -165,8 +170,8 @@ public void doXContent(XContentBuilder builder, Params params) throws IOExceptio
builder.startObject(name);

builder.field("query", text);
if (disableCoords != null) {
builder.field("disable_coords", disableCoords);
if (disableCoord != null) {
builder.field("disable_coord", disableCoord);
}
if (highFreqOperator != null) {
builder.field("high_freq_operator", highFreqOperator.toString());
Expand Down
Expand Up @@ -47,7 +47,7 @@ public class CommonTermsQueryParser implements QueryParser {

static final Occur DEFAULT_LOW_FREQ_OCCUR = Occur.SHOULD;

static final boolean DEFAULT_DISABLE_COORDS = true;
static final boolean DEFAULT_DISABLE_COORD = true;


@Inject
Expand All @@ -72,7 +72,7 @@ public Query parse(QueryParseContext parseContext) throws IOException, QueryPars
String queryAnalyzer = null;
String lowFreqMinimumShouldMatch = null;
String highFreqMinimumShouldMatch = null;
boolean disableCoords = DEFAULT_DISABLE_COORDS;
boolean disableCoord = DEFAULT_DISABLE_COORD;
Occur highFreqOccur = DEFAULT_HIGH_FREQ_OCCUR;
Occur lowFreqOccur = DEFAULT_LOW_FREQ_OCCUR;
float maxTermFrequency = DEFAULT_MAX_TERM_DOC_FREQ;
Expand Down Expand Up @@ -113,7 +113,7 @@ public Query parse(QueryParseContext parseContext) throws IOException, QueryPars
}
queryAnalyzer = analyzer;
} else if ("disable_coord".equals(currentFieldName) || "disableCoord".equals(currentFieldName)) {
disableCoords = parser.booleanValue();
disableCoord = parser.booleanValue();
} else if ("boost".equals(currentFieldName)) {
boost = parser.floatValue();
} else if ("high_freq_operator".equals(currentFieldName) || "highFreqOperator".equals(currentFieldName)) {
Expand Down Expand Up @@ -188,7 +188,7 @@ public Query parse(QueryParseContext parseContext) throws IOException, QueryPars
}
}

ExtendedCommonTermsQuery commonsQuery = new ExtendedCommonTermsQuery(highFreqOccur, lowFreqOccur, maxTermFrequency, disableCoords, fieldType);
ExtendedCommonTermsQuery commonsQuery = new ExtendedCommonTermsQuery(highFreqOccur, lowFreqOccur, maxTermFrequency, disableCoord, fieldType);
commonsQuery.setBoost(boost);
Query query = parseQueryString(commonsQuery, value.toString(), field, parseContext, analyzer, lowFreqMinimumShouldMatch, highFreqMinimumShouldMatch);
if (queryName != null) {
Expand Down
Expand Up @@ -2170,6 +2170,19 @@ public void testCommonTermsQuery3() throws IOException {
assertThat(ectQuery.getLowFreqMinimumNumberShouldMatchSpec(), equalTo("2"));
}

@Test // see #11730
public void testCommonTermsQuery4() throws IOException {
IndexQueryParserService queryParser = queryParser();
Query parsedQuery = queryParser.parse(commonTermsQuery("field", "text").disableCoord(false)).query();
assertThat(parsedQuery, instanceOf(ExtendedCommonTermsQuery.class));
ExtendedCommonTermsQuery ectQuery = (ExtendedCommonTermsQuery) parsedQuery;
assertFalse(ectQuery.isCoordDisabled());
parsedQuery = queryParser.parse(commonTermsQuery("field", "text").disableCoord(true)).query();
assertThat(parsedQuery, instanceOf(ExtendedCommonTermsQuery.class));
ectQuery = (ExtendedCommonTermsQuery) parsedQuery;
assertTrue(ectQuery.isCoordDisabled());
}

@Test(expected = QueryParsingException.class)
public void assureMalformedThrowsException() throws IOException {
IndexQueryParserService queryParser;
Expand Down