Fixing review comments.
This commit is contained in:
parent
907cdc61f7
commit
5e9106ae5e
|
@ -39,7 +39,7 @@ public class SimpleQueryStringBuilder extends QueryBuilder implements BoostableQ
|
|||
private String queryName;
|
||||
private String minimumShouldMatch;
|
||||
private int flags = -1;
|
||||
private float boost = 1.0f;
|
||||
private float boost = -1.0f;
|
||||
private Boolean lowercaseExpandedTerms;
|
||||
private Boolean lenient;
|
||||
private Boolean analyzeWildcard;
|
||||
|
@ -210,7 +210,7 @@ public class SimpleQueryStringBuilder extends QueryBuilder implements BoostableQ
|
|||
builder.field("minimum_should_match", minimumShouldMatch);
|
||||
}
|
||||
|
||||
if (boost != 1.0f) {
|
||||
if (boost != -1.0f) {
|
||||
builder.field("boost", boost);
|
||||
}
|
||||
|
||||
|
|
|
@ -235,7 +235,10 @@ public class SimpleQueryStringParser implements QueryParser {
|
|||
Queries.applyMinimumShouldMatch((BooleanQuery) query, minimumShouldMatch);
|
||||
}
|
||||
|
||||
if (query != null) {
|
||||
query.setBoost(boost);
|
||||
}
|
||||
|
||||
return query;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,12 +60,14 @@ public class SimpleQueryStringTests extends ElasticsearchIntegrationTest {
|
|||
assertHitCount(searchResponse, 3l);
|
||||
assertSearchHits(searchResponse, "1", "2", "3");
|
||||
|
||||
// Tests boost value setting. In this case doc 1 should always be ranked above the other
|
||||
// two matches.
|
||||
searchResponse = client().prepareSearch().setQuery(
|
||||
boolQuery()
|
||||
.should(simpleQueryStringQuery("foo").boost(-10.0f))
|
||||
.should(simpleQueryStringQuery("\"foo bar\"").boost(10.0f))
|
||||
.should(termQuery("body", "eggplant"))).get();
|
||||
assertHitCount(searchResponse, 3l);
|
||||
assertFirstHit(searchResponse, hasId("4"));
|
||||
assertHitCount(searchResponse, 2l);
|
||||
assertFirstHit(searchResponse, hasId("3"));
|
||||
|
||||
searchResponse = client().prepareSearch().setQuery(
|
||||
simpleQueryStringQuery("foo bar").defaultOperator(SimpleQueryStringBuilder.Operator.AND)).get();
|
||||
|
|
Loading…
Reference in New Issue