use of com.enonic.xp.node.FindNodesByQueryResult in project xp by enonic.
the class FindAuditLogCommand method runQuery.
private FindAuditLogResult runQuery() {
final NodeQuery query = createQuery();
if (query == null) {
return FindAuditLogResult.empty();
}
FindNodesByQueryResult result = nodeService.findByQuery(query);
List<AuditLog> logs = result.getNodeIds().stream().map(nodeService::getById).map(AuditLogSerializer::fromNode).collect(Collectors.toList());
return FindAuditLogResult.create().total(result.getTotalHits()).hits(AuditLogs.from(logs)).build();
}
use of com.enonic.xp.node.FindNodesByQueryResult in project xp by enonic.
the class FindContentPathsByQueryCommand method execute.
public FindContentPathsByQueryResult execute() {
final NodeQuery nodeQuery = ContentQueryNodeQueryTranslator.translate(this.params.getContentQuery()).addQueryFilters(createFilters()).withPath(true).build();
final FindNodesByQueryResult result = nodeService.findByQuery(nodeQuery);
return FindContentPathsByQueryResult.create().contentPaths(ContentPaths.from(result.getNodeHits().stream().map(NodeHit::getNodePath).map(ContentNodeHelper::translateNodePathToContentPath).collect(Collectors.toSet()))).hits(result.getHits()).totalHits(result.getTotalHits()).build();
}
use of com.enonic.xp.node.FindNodesByQueryResult in project xp by enonic.
the class FindContentByQueryCommand method execute.
FindContentByQueryResult execute() {
final NodeQuery nodeQuery = ContentQueryNodeQueryTranslator.translate(this.params.getContentQuery()).addQueryFilters(createFilters()).build();
final FindNodesByQueryResult result = nodeService.findByQuery(nodeQuery);
final NodeIds nodeIds = result.getNodeIds();
final Map<ContentId, HighlightedProperties> highlight = result.getNodeHits().stream().filter(nodeHit -> nodeHit.getHighlight() != null && nodeHit.getHighlight().size() > 0).collect(Collectors.toMap(hit -> ContentId.from(hit.getNodeId().toString()), NodeHit::getHighlight));
final Nodes foundNodes = this.nodeService.getByIds(nodeIds);
Contents contents = this.translator.fromNodes(foundNodes, true);
return FindContentByQueryResult.create().contents(contents).aggregations(result.getAggregations()).hits(result.getHits()).totalHits(result.getTotalHits()).highlight(highlight).build();
}
use of com.enonic.xp.node.FindNodesByQueryResult 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.node.FindNodesByQueryResult in project xp by enonic.
the class CreateIssueCommand method countTotalIssues.
private long countTotalIssues() {
final IssueQuery query = IssueQuery.create().size(0).count(true).build();
final NodeQuery nodeQuery = IssueQueryNodeQueryTranslator.translate(query);
final FindNodesByQueryResult result = nodeService.findByQuery(nodeQuery);
return result.getTotalHits();
}
Aggregations