Skip to content

Loading…

unit tests for issue #1560, customfiltersscore min and multiply scoremode #1565

Closed
wants to merge 1 commit into from

2 participants

@apatrida

Forgot the unit tests previously. Want these committed before starting on issue #1561

@kimchy
elastic member

cheers, pushed.

@kimchy kimchy closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
View
40 ...st/java/org/elasticsearch/test/integration/search/customscore/CustomScoreSearchTests.java
@@ -244,5 +244,45 @@ public void testCustomFiltersScore() throws Exception {
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));
}
}
Something went wrong with that request. Please try again.