6060import static org .elasticsearch .index .query .QueryBuilders .termQuery ;
6161import static org .elasticsearch .search .builder .SearchSourceBuilder .searchSource ;
6262import static org .elasticsearch .test .hamcrest .ElasticsearchAssertions .assertNoFailures ;
63+ import static org .hamcrest .Matchers .endsWith ;
6364import static org .hamcrest .Matchers .equalTo ;
6465import static org .hamcrest .Matchers .instanceOf ;
6566import static org .hamcrest .Matchers .lessThanOrEqualTo ;
@@ -147,6 +148,10 @@ public void testDfsQueryThenFetch() throws Exception {
147148 for (int i = 0 ; i < hits .length ; ++i ) {
148149 SearchHit hit = hits [i ];
149150 assertThat (hit .explanation (), notNullValue ());
151+ assertThat (hit .explanation ().getDetails ().length , equalTo (1 ));
152+ assertThat (hit .explanation ().getDetails ()[0 ].getDetails ().length , equalTo (2 ));
153+ assertThat (hit .explanation ().getDetails ()[0 ].getDetails ()[0 ].getDescription (),
154+ endsWith ("idf(docFreq=100, docCount=100)" ));
150155 assertThat ("id[" + hit .id () + "] -> " + hit .explanation ().toString (), hit .id (), equalTo (Integer .toString (100 - total - i - 1 )));
151156 }
152157 total += hits .length ;
@@ -171,6 +176,10 @@ public void testDfsQueryThenFetchWithSort() throws Exception {
171176 for (int i = 0 ; i < hits .length ; ++i ) {
172177 SearchHit hit = hits [i ];
173178 assertThat (hit .explanation (), notNullValue ());
179+ assertThat (hit .explanation ().getDetails ().length , equalTo (1 ));
180+ assertThat (hit .explanation ().getDetails ()[0 ].getDetails ().length , equalTo (2 ));
181+ assertThat (hit .explanation ().getDetails ()[0 ].getDetails ()[0 ].getDescription (),
182+ endsWith ("idf(docFreq=100, docCount=100)" ));
174183 assertThat ("id[" + hit .id () + "]" , hit .id (), equalTo (Integer .toString (total + i )));
175184 }
176185 total += hits .length ;
@@ -317,6 +326,10 @@ public void testDfsQueryAndFetch() throws Exception {
317326 SearchHit hit = searchResponse .getHits ().hits ()[i ];
318327// System.out.println(hit.shard() + ": " + hit.explanation());
319328 assertThat (hit .explanation (), notNullValue ());
329+ assertThat (hit .explanation ().getDetails ().length , equalTo (1 ));
330+ assertThat (hit .explanation ().getDetails ()[0 ].getDetails ().length , equalTo (2 ));
331+ assertThat (hit .explanation ().getDetails ()[0 ].getDetails ()[0 ].getDescription (),
332+ endsWith ("idf(docFreq=100, docCount=100)" ));
320333// assertThat("id[" + hit.id() + "]", hit.id(), equalTo(Integer.toString(100 - i - 1)));
321334 assertThat ("make sure we don't have duplicates" , expectedIds .remove (hit .id ()), notNullValue ());
322335 }
0 commit comments