Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ public Weight createWeight(Query query, boolean needsScores) throws IOException

@Override
public Explanation explain(Query query, int doc) throws IOException {
if (aggregatedDfs != null) {
// dfs data is needed to explain the score
return super.explain(createNormalizedWeight(query, true), doc);
}
return in.explain(query, doc);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import static org.elasticsearch.index.query.QueryBuilders.termQuery;
import static org.elasticsearch.search.builder.SearchSourceBuilder.searchSource;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures;
import static org.hamcrest.Matchers.endsWith;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.lessThanOrEqualTo;
Expand Down Expand Up @@ -147,6 +148,10 @@ public void testDfsQueryThenFetch() throws Exception {
for (int i = 0; i < hits.length; ++i) {
SearchHit hit = hits[i];
assertThat(hit.explanation(), notNullValue());
assertThat(hit.explanation().getDetails().length, equalTo(1));
assertThat(hit.explanation().getDetails()[0].getDetails().length, equalTo(2));
assertThat(hit.explanation().getDetails()[0].getDetails()[0].getDescription(),
endsWith("idf(docFreq=100, docCount=100)"));
assertThat("id[" + hit.id() + "] -> " + hit.explanation().toString(), hit.id(), equalTo(Integer.toString(100 - total - i - 1)));
}
total += hits.length;
Expand All @@ -171,6 +176,10 @@ public void testDfsQueryThenFetchWithSort() throws Exception {
for (int i = 0; i < hits.length; ++i) {
SearchHit hit = hits[i];
assertThat(hit.explanation(), notNullValue());
assertThat(hit.explanation().getDetails().length, equalTo(1));
assertThat(hit.explanation().getDetails()[0].getDetails().length, equalTo(2));
assertThat(hit.explanation().getDetails()[0].getDetails()[0].getDescription(),
endsWith("idf(docFreq=100, docCount=100)"));
assertThat("id[" + hit.id() + "]", hit.id(), equalTo(Integer.toString(total + i)));
}
total += hits.length;
Expand Down Expand Up @@ -317,6 +326,10 @@ public void testDfsQueryAndFetch() throws Exception {
SearchHit hit = searchResponse.getHits().hits()[i];
// System.out.println(hit.shard() + ": " + hit.explanation());
assertThat(hit.explanation(), notNullValue());
assertThat(hit.explanation().getDetails().length, equalTo(1));
assertThat(hit.explanation().getDetails()[0].getDetails().length, equalTo(2));
assertThat(hit.explanation().getDetails()[0].getDetails()[0].getDescription(),
endsWith("idf(docFreq=100, docCount=100)"));
// assertThat("id[" + hit.id() + "]", hit.id(), equalTo(Integer.toString(100 - i - 1)));
assertThat("make sure we don't have duplicates", expectedIds.remove(hit.id()), notNullValue());
}
Expand Down