Skip to content

Fix alias resolution in match query with synonyms #76688

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

Merged
merged 1 commit into from
Aug 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,9 @@ public Query parse(Type type, String fieldName, Object value) throws IOException
switch (type) {
case BOOLEAN:
if (commonTermsCutoff == null) {
query = builder.createBooleanQuery(fieldName, value.toString(), occur);
query = builder.createBooleanQuery(resolvedFieldName, value.toString(), occur);
} else {
query = createCommonTermsQuery(builder, fieldName, value.toString(), occur, occur, commonTermsCutoff);
query = createCommonTermsQuery(builder, resolvedFieldName, value.toString(), occur, occur, commonTermsCutoff);
}
break;
case BOOLEAN_PREFIX:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
Expand Down Expand Up @@ -488,16 +489,18 @@ public void testMultiWordSynonymsPhrase() throws Exception {
assertEquals(expected, actual);
}


public void testAliasWithSynonyms() throws Exception {
final MatchQueryParser matchQueryParser = new MatchQueryParser(createSearchExecutionContext());
MatchQueryParser matchQueryParser = new MatchQueryParser(createSearchExecutionContext());
matchQueryParser.setAnalyzer(new MockSynonymAnalyzer());
final Query actual = matchQueryParser.parse(Type.PHRASE, TEXT_ALIAS_FIELD_NAME, "dogs");
Query expected = new SynonymQuery.Builder(TEXT_FIELD_NAME)
.addTerm(new Term(TEXT_FIELD_NAME, "dogs"))
.addTerm(new Term(TEXT_FIELD_NAME, "dog"))
.build();
assertEquals(expected, actual);

for (Type type : Arrays.asList(Type.BOOLEAN, Type.PHRASE)) {
Query actual = matchQueryParser.parse(type, TEXT_ALIAS_FIELD_NAME, "dogs");
Query expected = new SynonymQuery.Builder(TEXT_FIELD_NAME)
.addTerm(new Term(TEXT_FIELD_NAME, "dogs"))
.addTerm(new Term(TEXT_FIELD_NAME, "dog"))
.build();
assertEquals(expected, actual);
}
}

public void testMaxBooleanClause() {
Expand Down