Query DSL: simple_query_string overrides boost coming from lucene

SimpleQueryStringParser applies whatever boost the query holds, even if the default 1, to the query obtained from parsing of the query string. that might contain its boost, for instance if it resolved to a simple query like term (single term query against a single field). We should rather multiply the existing boost with the boost set to the query, same as we do in query_string

Relates to #13272
Closes #13331
This commit is contained in:
javanna 2015-09-03 22:03:30 +02:00 committed by Luca Cavanna
parent cb12107123
commit bd5613708e
2 changed files with 18 additions and 1 deletions

View File

@ -219,7 +219,7 @@ public class SimpleQueryStringParser implements QueryParser {
}
if (query != null) {
query.setBoost(boost);
query.setBoost(boost * query.getBoost());
}
return query;

View File

@ -2539,6 +2539,23 @@ public class SimpleIndexQueryParserTests extends ESSingleNodeTestCase {
assertThat(parsedQuery, instanceOf(BooleanQuery.class));
}
@Test
public void testSimpleQueryStringBoost() throws Exception {
IndexQueryParserService queryParser = queryParser();
SimpleQueryStringBuilder simpleQueryStringBuilder = new SimpleQueryStringBuilder("test");
simpleQueryStringBuilder.field("body", 5);
Query parsedQuery = queryParser.parse(simpleQueryStringBuilder.toString()).query();
assertThat(parsedQuery, instanceOf(TermQuery.class));
assertThat(parsedQuery.getBoost(), equalTo(5f));
simpleQueryStringBuilder = new SimpleQueryStringBuilder("test");
simpleQueryStringBuilder.field("body", 5);
simpleQueryStringBuilder.boost(2);
parsedQuery = queryParser.parse(simpleQueryStringBuilder.toString()).query();
assertThat(parsedQuery, instanceOf(TermQuery.class));
assertThat(parsedQuery.getBoost(), equalTo(10f));
}
@Test
public void testMatchWithFuzzyTranspositions() throws Exception {
IndexQueryParserService queryParser = queryParser();