unit tests for issue 1560, customfiltersscore min and multiply search modes
This commit is contained in:
parent
3d9e87201e
commit
52e6327467
|
@ -244,5 +244,45 @@ public class CustomScoreSearchTests extends AbstractNodesTests {
|
|||
assertThat(searchResponse.hits().getAt(1).id(), equalTo("1"));
|
||||
assertThat(searchResponse.hits().getAt(1).score(), equalTo(4.0f));
|
||||
logger.info("--> Hit[1] {} Explanation {}", searchResponse.hits().getAt(1).id(), searchResponse.hits().getAt(1).explanation());
|
||||
|
||||
searchResponse = client.prepareSearch("test")
|
||||
.setQuery(customFiltersScoreQuery(matchAllQuery()).scoreMode("min")
|
||||
.add(termFilter("field", "value4"), 2)
|
||||
.add(termFilter("field", "value1"), 3)
|
||||
.add(termFilter("color", "red"), 5))
|
||||
.setExplain(true)
|
||||
.execute().actionGet();
|
||||
|
||||
assertThat(Arrays.toString(searchResponse.shardFailures()), searchResponse.failedShards(), equalTo(0));
|
||||
assertThat(searchResponse.hits().totalHits(), equalTo(4l));
|
||||
assertThat(searchResponse.hits().getAt(0).id(), equalTo("3"));
|
||||
assertThat(searchResponse.hits().getAt(0).score(), equalTo(5.0f));
|
||||
logger.info("--> Hit[0] {} Explanation {}", searchResponse.hits().getAt(0).id(), searchResponse.hits().getAt(0).explanation());
|
||||
assertThat(searchResponse.hits().getAt(1).id(), equalTo("1"));
|
||||
assertThat(searchResponse.hits().getAt(1).score(), equalTo(3.0f));
|
||||
assertThat(searchResponse.hits().getAt(2).id(), equalTo("4"));
|
||||
assertThat(searchResponse.hits().getAt(2).score(), equalTo(2.0f));
|
||||
assertThat(searchResponse.hits().getAt(3).id(), equalTo("2"));
|
||||
assertThat(searchResponse.hits().getAt(3).score(), equalTo(1.0f));
|
||||
|
||||
searchResponse = client.prepareSearch("test")
|
||||
.setQuery(customFiltersScoreQuery(matchAllQuery()).scoreMode("multiply")
|
||||
.add(termFilter("field", "value4"), 2)
|
||||
.add(termFilter("field", "value1"), 3)
|
||||
.add(termFilter("color", "red"), 5))
|
||||
.setExplain(true)
|
||||
.execute().actionGet();
|
||||
|
||||
assertThat(Arrays.toString(searchResponse.shardFailures()), searchResponse.failedShards(), equalTo(0));
|
||||
assertThat(searchResponse.hits().totalHits(), equalTo(4l));
|
||||
assertThat(searchResponse.hits().getAt(0).id(), equalTo("1"));
|
||||
assertThat(searchResponse.hits().getAt(0).score(), equalTo(15.0f));
|
||||
logger.info("--> Hit[0] {} Explanation {}", searchResponse.hits().getAt(0).id(), searchResponse.hits().getAt(0).explanation());
|
||||
assertThat(searchResponse.hits().getAt(1).id(), equalTo("3"));
|
||||
assertThat(searchResponse.hits().getAt(1).score(), equalTo(5.0f));
|
||||
assertThat(searchResponse.hits().getAt(2).id(), equalTo("4"));
|
||||
assertThat(searchResponse.hits().getAt(2).score(), equalTo(2.0f));
|
||||
assertThat(searchResponse.hits().getAt(3).id(), equalTo("2"));
|
||||
assertThat(searchResponse.hits().getAt(3).score(), equalTo(1.0f));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue