use of com.enonic.xp.sortvalues.SortValuesProperty in project xp by enonic.
the class FindContentIdsByQueryCommand method execute.
FindContentIdsByQueryResult execute() {
final NodeQuery nodeQuery = ContentQueryNodeQueryTranslator.translate(this.query).addQueryFilters(createFilters()).build();
final Map<ContentId, HighlightedProperties> highlight = new LinkedHashMap<>();
final Map<ContentId, SortValuesProperty> sortValues = new LinkedHashMap<>();
final Map<ContentId, Float> scoreValues = new LinkedHashMap<>();
final FindNodesByQueryResult result = nodeService.findByQuery(nodeQuery);
result.getNodeHits().forEach(nodeHit -> {
final ContentId contentId = ContentId.from(nodeHit.getNodeId().toString());
scoreValues.put(contentId, nodeHit.getScore());
if (nodeHit.getHighlight() != null && !nodeHit.getHighlight().isEmpty()) {
highlight.put(contentId, nodeHit.getHighlight());
}
if (nodeHit.getSort() != null && nodeHit.getSort().getValues() != null && !nodeHit.getSort().getValues().isEmpty()) {
sortValues.put(contentId, nodeHit.getSort());
}
});
return FindContentIdsByQueryResult.create().contents(ContentNodeHelper.toContentIds(result.getNodeIds())).aggregations(result.getAggregations()).highlight(highlight).sort(sortValues).hits(result.getHits()).score(scoreValues).totalHits(result.getTotalHits()).build();
}
use of com.enonic.xp.sortvalues.SortValuesProperty in project xp by enonic.
the class ContentsResultMapper method serialize.
private void serialize(final MapGenerator gen, final Contents contents) {
gen.array("hits");
for (Content content : contents) {
gen.map();
final SortValuesProperty sort = sortValues != null ? sortValues.get(content.getId()) : null;
final Float score = scoreValues != null ? scoreValues.get(content.getId()) : null;
new ContentMapper(content, sort, score).serialize(gen);
gen.end();
}
gen.end();
}
Aggregations