From 8958096754f1a75cd86bf8c1e9da1ea9e371e523 Mon Sep 17 00:00:00 2001 From: Michael McCandless Date: Tue, 26 May 2015 04:06:21 -0400 Subject: [PATCH] don't truncate TopDocs after rescoring --- .../search/rescore/RescorePhase.java | 5 ---- .../search/rescore/QueryRescorerTests.java | 24 ++++++++++++++++++- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/elasticsearch/search/rescore/RescorePhase.java b/src/main/java/org/elasticsearch/search/rescore/RescorePhase.java index 88d2b0aae60..48d8407facd 100644 --- a/src/main/java/org/elasticsearch/search/rescore/RescorePhase.java +++ b/src/main/java/org/elasticsearch/search/rescore/RescorePhase.java @@ -60,11 +60,6 @@ public class RescorePhase extends AbstractComponent implements SearchPhase { for (RescoreSearchContext ctx : context.rescore()) { topDocs = ctx.rescorer().rescore(topDocs, context, ctx); } - if (context.size() < topDocs.scoreDocs.length) { - ScoreDoc[] hits = new ScoreDoc[context.size()]; - System.arraycopy(topDocs.scoreDocs, 0, hits, 0, hits.length); - topDocs = new TopDocs(topDocs.totalHits, hits, topDocs.getMaxScore()); - } context.queryResult().topDocs(topDocs); } catch (IOException e) { throw new ElasticsearchException("Rescore Phase Failed", e); diff --git a/src/test/java/org/elasticsearch/search/rescore/QueryRescorerTests.java b/src/test/java/org/elasticsearch/search/rescore/QueryRescorerTests.java index afeb93f9be4..d1cbdc86525 100644 --- a/src/test/java/org/elasticsearch/search/rescore/QueryRescorerTests.java +++ b/src/test/java/org/elasticsearch/search/rescore/QueryRescorerTests.java @@ -45,6 +45,7 @@ import java.util.Arrays; import java.util.Comparator; import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_SHARDS; +import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_REPLICAS; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.*; import static org.hamcrest.Matchers.*; @@ -206,7 +207,7 @@ public class QueryRescorerTests extends ElasticsearchIntegrationTest { RescoreBuilder.queryRescorer(QueryBuilders.matchPhraseQuery("field1", "lexington avenue massachusetts").slop(3)) .setQueryWeight(0.6f).setRescoreQueryWeight(2.0f)).setRescoreWindow(20).execute().actionGet(); - assertThat(searchResponse.getHits().hits().length, equalTo(3)); + assertThat(searchResponse.getHits().hits().length, equalTo(5)); assertHitCount(searchResponse, 9); assertFirstHit(searchResponse, hasId("3")); } @@ -719,4 +720,25 @@ public class QueryRescorerTests extends ElasticsearchIntegrationTest { ensureGreen(); return numDocs; } + + // #11277 + public void testFromSize() throws Exception { + Builder settings = Settings.builder(); + settings.put(SETTING_NUMBER_OF_SHARDS, 1); + settings.put(SETTING_NUMBER_OF_REPLICAS, 0); + assertAcked(prepareCreate("test").setSettings(settings)); + for(int i=0;i<5;i++) { + client().prepareIndex("test", "type", ""+i).setSource("text", "hello world").get(); + } + refresh(); + + SearchRequestBuilder request = client().prepareSearch(); + request.setQuery(QueryBuilders.termQuery("text", "hello")); + request.setFrom(1); + request.setSize(4); + request.addRescorer(RescoreBuilder.queryRescorer(QueryBuilders.matchAllQuery())); + request.setRescoreWindow(50); + + assertEquals(4, request.get().getHits().hits().length); + } }