Skip to content

Commit

Permalink
don't truncate TopDocs after rescoring
Browse files Browse the repository at this point in the history
  • Loading branch information
mikemccand committed May 26, 2015
1 parent e310499 commit 8958096
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
Expand Up @@ -60,11 +60,6 @@ public void execute(SearchContext context) {
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);
Expand Down
Expand Up @@ -45,6 +45,7 @@
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.*;
Expand Down Expand Up @@ -206,7 +207,7 @@ public void testMoreDocs() throws Exception {
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"));
}
Expand Down Expand Up @@ -719,4 +720,25 @@ private int indexRandomNumbers(String analyzer, int shards, boolean dummyDocs) t
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);
}
}

0 comments on commit 8958096

Please sign in to comment.