Search in sources :

Example 1 with SortValuesProperty

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();
}
Also used : FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) HighlightedProperties(com.enonic.xp.highlight.HighlightedProperties) NodeQuery(com.enonic.xp.node.NodeQuery) SortValuesProperty(com.enonic.xp.sortvalues.SortValuesProperty) ContentId(com.enonic.xp.content.ContentId) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with SortValuesProperty

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();
}
Also used : Content(com.enonic.xp.content.Content) SortValuesProperty(com.enonic.xp.sortvalues.SortValuesProperty)

Aggregations

SortValuesProperty (com.enonic.xp.sortvalues.SortValuesProperty)2 Content (com.enonic.xp.content.Content)1 ContentId (com.enonic.xp.content.ContentId)1 HighlightedProperties (com.enonic.xp.highlight.HighlightedProperties)1 FindNodesByQueryResult (com.enonic.xp.node.FindNodesByQueryResult)1 NodeQuery (com.enonic.xp.node.NodeQuery)1 LinkedHashMap (java.util.LinkedHashMap)1