use of org.springframework.data.elasticsearch.core.document.Explanation in project spring-data-elasticsearch by spring-projects.
the class ElasticsearchTemplateTests method shouldNotReturnExplanationWhenNotRequested.
// #725
@Test
@DisplayName("should not return explanation when not requested")
void shouldNotReturnExplanationWhenNotRequested() {
SampleEntity entity = SampleEntity.builder().id("42").message("a message with text").build();
operations.save(entity);
Criteria criteria = new Criteria("message").contains("with");
CriteriaQuery query = new CriteriaQuery(criteria);
SearchHits<SampleEntity> searchHits = operations.search(query, SampleEntity.class);
assertThat(searchHits.getTotalHits()).isEqualTo(1L);
Explanation explanation = searchHits.getSearchHit(0).getExplanation();
assertThat(explanation).isNull();
}
use of org.springframework.data.elasticsearch.core.document.Explanation in project spring-data-elasticsearch by spring-projects.
the class ElasticsearchTemplateTests method shouldReturnExplanationWhenRequested.
// #725
@Test
@DisplayName("should return explanation when requested")
void shouldReturnExplanationWhenRequested() {
SampleEntity entity = SampleEntity.builder().id("42").message("a message with text").build();
operations.save(entity);
Criteria criteria = new Criteria("message").contains("with");
CriteriaQuery query = new CriteriaQuery(criteria);
query.setExplain(true);
SearchHits<SampleEntity> searchHits = operations.search(query, SampleEntity.class);
assertThat(searchHits.getTotalHits()).isEqualTo(1L);
Explanation explanation = searchHits.getSearchHit(0).getExplanation();
assertThat(explanation).isNotNull();
}
use of org.springframework.data.elasticsearch.core.document.Explanation in project spring-data-elasticsearch by spring-projects.
the class DocumentAdaptersUnitTests method shouldAdaptReturnedExplanations.
// #725
@Test
@DisplayName("should adapt returned explanations")
void shouldAdaptReturnedExplanations() {
SearchHit searchHit = new SearchHit(42);
searchHit.explanation(//
org.apache.lucene.search.Explanation.match(//
3.14, //
"explanation 3.14", Collections.singletonList(//
org.apache.lucene.search.Explanation.noMatch(//
"explanation noMatch", Collections.emptyList()))));
SearchDocument searchDocument = DocumentAdapters.from(searchHit);
Explanation explanation = searchDocument.getExplanation();
assertThat(explanation).isNotNull();
assertThat(explanation.isMatch()).isTrue();
assertThat(explanation.getValue()).isEqualTo(3.14);
assertThat(explanation.getDescription()).isEqualTo("explanation 3.14");
List<Explanation> details = explanation.getDetails();
assertThat(details).containsExactly(new Explanation(false, 0.0, "explanation noMatch", Collections.emptyList()));
}
Aggregations