I am trying to see and use the invidual _score of each hit when performing a search using SearchQuery. This, by the way, is to know in what range of results my results lead. But besides setting up MinScore with searchQuery.withMinScore (float); I cannot find any method to handle dozens of search results.
@Override
public Page<Website> listsearch(SearchBody searchBody, int size, int page) {
BoolQueryBuilder qb = QueryBuilders.boolQuery();
for(SearchUnit unit:searchBody.getSearchBody()){
if(unit.isPriority()) {
qb.must(matchQuery("_all", unit.getWord()).operator(MatchQueryBuilder.Operator.AND)
.fuzziness(Fuzziness.AUTO));
}else {
qb.should(termQuery("_all", unit.getWord())
.boost(unit.getWeight()));
}
}
for(SearchUnit ExUnit:searchBody.getExcludeBody()){
qb.mustNot(matchPhraseQuery("_all",ExUnit.getWord()));
}
SearchQuery searchQuery = new NativeSearchQueryBuilder()
.withIndices("websites_v1")
.withTypes("website")
.withQuery(qb)
.withMinScore(0.05F)
.withPageable(new PageRequest(page, size))
.build();
Page<Website> search = searchRepository.search(searchQuery);
return search;
}
The search function used is org.springframework.data.elasticsearch.repository; defined as
Page<T> search(SearchQuery var1);
So, my question is, anyway, can I access the account of each returned object on the page? Or do I need to switch my request method to something else to achieve this?
source
share