[TEST] Ensure scores are consistent.

This commit is contained in:
Martijn van Groningen 2014-07-04 17:18:35 +02:00
parent 1e894111b0
commit f936283d65
1 changed files with 6 additions and 7 deletions

View File

@ -2457,27 +2457,26 @@ public class SimpleQueryTests extends ElasticsearchIntegrationTest {
@Test @Test
public void testQueryStringParserCache() throws Exception { public void testQueryStringParserCache() throws Exception {
createIndex("test"); createIndex("test");
indexRandom(true, Arrays.asList( indexRandom(true, false, client().prepareIndex("test", "type", "1").setSource("nameTokens", "xyz"));
client().prepareIndex("test", "type", "1").setSource("nameTokens", "xyz")
));
SearchResponse response = client().prepareSearch("test") SearchResponse response = client().prepareSearch("test")
.setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
.setQuery(QueryBuilders.queryString("xyz").boost(100)) .setQuery(QueryBuilders.queryString("xyz").boost(100))
.get(); .get();
assertThat(response.getHits().totalHits(), equalTo(1l)); assertThat(response.getHits().totalHits(), equalTo(1l));
assertThat(response.getHits().getAt(0).id(), equalTo("1")); assertThat(response.getHits().getAt(0).id(), equalTo("1"));
float score = response.getHits().getAt(0).getScore(); float first = response.getHits().getAt(0).getScore();
for (int i = 0; i < 100; i++) { for (int i = 0; i < 100; i++) {
response = client().prepareSearch("test") response = client().prepareSearch("test")
.setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
.setQuery(QueryBuilders.queryString("xyz").boost(100)) .setQuery(QueryBuilders.queryString("xyz").boost(100))
.get(); .get();
assertThat(response.getHits().totalHits(), equalTo(1l)); assertThat(response.getHits().totalHits(), equalTo(1l));
assertThat(response.getHits().getAt(0).id(), equalTo("1")); assertThat(response.getHits().getAt(0).id(), equalTo("1"));
assertThat(Float.compare(score, response.getHits().getAt(0).getScore()), equalTo(0)); float actual = response.getHits().getAt(0).getScore();
assertThat(i + " expected: " + first + " actual: " + actual, Float.compare(first, actual), equalTo(0));
} }
} }