Commit cb038ee8 authored by Matija Obreza's avatar Matija Obreza

ES: Order search results by best score

- Using "must" clause ensures hits are scored
- "filter" doesn't score
parent 38991450
......@@ -1033,6 +1033,7 @@ public class ElasticsearchServiceImpl implements ElasticsearchService, Initializ
}
SearchSourceBuilder sourceBuilder = new SearchSourceBuilder().query(query).from((int) page.getOffset()).size(page.getPageSize());
SearchRequest esRequest = new SearchRequest(indexName).types(COMMON_TYPE_NAME).source(sourceBuilder);
sourceBuilder.sort("_score");
// for (Sort.Order order : page.getSort()) {
// sourceBuilder.sort(SortBuilders.fieldSort(order.getProperty()).order(SortOrder.valueOf(order.getDirection().name())));
......@@ -1041,7 +1042,7 @@ public class ElasticsearchServiceImpl implements ElasticsearchService, Initializ
List<T> content = new ArrayList<>();
searchResponse.getHits().forEach(hit -> {
LOG.trace("Mapping {} id={}", clazz, hit.getId());
LOG.debug("Mapping {} id={} score={}", clazz, hit.getId(), hit.getScore());
T x = loadEntity(clazz, Long.parseLong(hit.getId()));
if (x != null) {
LOG.trace("Adding to results: {}", x);
......@@ -1208,7 +1209,7 @@ public class ElasticsearchServiceImpl implements ElasticsearchService, Initializ
sqsQuery.field(field, 3);
}
}
fulltext.should(sqsQuery);
fulltext.must(sqsQuery);
// SimpleQueryStringBuilder sqsOrQuery = simpleQueryStringQuery(text)
// .lenient(true).defaultOperator(Operator.OR)
......@@ -1221,10 +1222,10 @@ public class ElasticsearchServiceImpl implements ElasticsearchService, Initializ
}
if (esQuery instanceof BoolQueryBuilder) {
esQuery = ((BoolQueryBuilder) esQuery).filter(fulltext);
esQuery = ((BoolQueryBuilder) esQuery).must(fulltext);
} else {
BoolQueryBuilder builder = new BoolQueryBuilder();
esQuery = builder.filter(esQuery).filter(fulltext);
esQuery = builder.filter(esQuery).must(fulltext);
}
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment