Correctly apply boosts in query string.
This applies boosts to phrase queries generated by query string queries both in boolean and dismax mode.
This commit is contained in:
parent
ddad4fe2f7
commit
becbbf53d5
|
@ -283,7 +283,7 @@ public class MapperQueryParser extends QueryParser {
|
|||
Query q = super.getFieldQuery(mField, queryText, slop);
|
||||
if (q != null) {
|
||||
added = true;
|
||||
applyBoost(field, q);
|
||||
applyBoost(mField, q);
|
||||
applySlop(q, slop);
|
||||
disMaxQuery.add(q);
|
||||
}
|
||||
|
@ -297,7 +297,7 @@ public class MapperQueryParser extends QueryParser {
|
|||
for (String mField : fields) {
|
||||
Query q = super.getFieldQuery(mField, queryText, slop);
|
||||
if (q != null) {
|
||||
applyBoost(field, q);
|
||||
applyBoost(mField, q);
|
||||
applySlop(q, slop);
|
||||
clauses.add(new BooleanClause(q, BooleanClause.Occur.SHOULD));
|
||||
}
|
||||
|
|
|
@ -34,13 +34,13 @@ import org.elasticsearch.test.integration.AbstractSharedClusterTest;
|
|||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
||||
import static org.elasticsearch.index.query.FilterBuilders.*;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.*;
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.*;
|
||||
import static org.hamcrest.Matchers.anyOf;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -745,6 +745,34 @@ public class SimpleQueryTests extends AbstractSharedClusterTest {
|
|||
assertThat(searchResponse.getHits().totalHits(), equalTo(1l));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQuotedQueryStringWithBoost() throws InterruptedException, ExecutionException {
|
||||
float boost = 10.0f;
|
||||
client().admin().indices().prepareCreate("test").setSettings(ImmutableSettings.settingsBuilder().put("index.number_of_shards", 1)).execute().actionGet();
|
||||
indexRandom("test", true,
|
||||
client().prepareIndex("test", "type1", "1").setSource("important", "phrase match", "less_important", "nothing important"),
|
||||
client().prepareIndex("test", "type1", "2").setSource("important", "nothing important", "less_important", "phrase match")
|
||||
);
|
||||
|
||||
SearchResponse searchResponse = client().prepareSearch()
|
||||
.setQuery(queryString("\"phrase match\"").field("important", boost).field("less_important"))
|
||||
.execute().actionGet();
|
||||
assertNoFailures(searchResponse);
|
||||
assertThat(searchResponse.getHits().totalHits(), equalTo(2l));
|
||||
assertThat(searchResponse.getHits().getAt(0).id(), equalTo("1"));
|
||||
assertThat(searchResponse.getHits().getAt(1).id(), equalTo("2"));
|
||||
assertThat((double)searchResponse.getHits().getAt(0).score(), closeTo(boost * searchResponse.getHits().getAt(1).score(), .1));
|
||||
|
||||
searchResponse = client().prepareSearch()
|
||||
.setQuery(queryString("\"phrase match\"").field("important", boost).field("less_important").useDisMax(false))
|
||||
.execute().actionGet();
|
||||
assertNoFailures(searchResponse);
|
||||
assertThat(searchResponse.getHits().totalHits(), equalTo(2l));
|
||||
assertThat(searchResponse.getHits().getAt(0).id(), equalTo("1"));
|
||||
assertThat(searchResponse.getHits().getAt(1).id(), equalTo("2"));
|
||||
assertThat((double)searchResponse.getHits().getAt(0).score(), closeTo(boost * searchResponse.getHits().getAt(1).score(), .1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSpecialRangeSyntaxInQueryString() {
|
||||
client().admin().indices().prepareCreate("test").setSettings(ImmutableSettings.settingsBuilder().put("index.number_of_shards", 1)).execute().actionGet();
|
||||
|
|
Loading…
Reference in New Issue