Search in sources :

Example 1 with FindNodesByQueryResult

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();
}
Also used : FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) NodeQuery(com.enonic.xp.node.NodeQuery) AuditLog(com.enonic.xp.audit.AuditLog)

Example 2 with FindNodesByQueryResult

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();
}
Also used : FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) NodeQuery(com.enonic.xp.node.NodeQuery)

Example 3 with FindNodesByQueryResult

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();
}
Also used : NodeHit(com.enonic.xp.node.NodeHit) Nodes(com.enonic.xp.node.Nodes) FindContentByQueryParams(com.enonic.xp.content.FindContentByQueryParams) Collectors(java.util.stream.Collectors) HighlightedProperties(com.enonic.xp.highlight.HighlightedProperties) ContentId(com.enonic.xp.content.ContentId) Contents(com.enonic.xp.content.Contents) Map(java.util.Map) FindContentByQueryResult(com.enonic.xp.content.FindContentByQueryResult) Preconditions(com.google.common.base.Preconditions) NodeQuery(com.enonic.xp.node.NodeQuery) NodeIds(com.enonic.xp.node.NodeIds) FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) Contents(com.enonic.xp.content.Contents) FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) NodeIds(com.enonic.xp.node.NodeIds) HighlightedProperties(com.enonic.xp.highlight.HighlightedProperties) NodeQuery(com.enonic.xp.node.NodeQuery) ContentId(com.enonic.xp.content.ContentId) Nodes(com.enonic.xp.node.Nodes)

Example 4 with FindNodesByQueryResult

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();
}
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 5 with FindNodesByQueryResult

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();
}
Also used : FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) NodeQuery(com.enonic.xp.node.NodeQuery) IssueQuery(com.enonic.xp.issue.IssueQuery)

Aggregations

FindNodesByQueryResult (com.enonic.xp.node.FindNodesByQueryResult)83 NodeQuery (com.enonic.xp.node.NodeQuery)60 Test (org.junit.jupiter.api.Test)54 Node (com.enonic.xp.node.Node)32 BucketAggregation (com.enonic.xp.aggregation.BucketAggregation)18 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)18 Bucket (com.enonic.xp.aggregation.Bucket)14 PropertyTree (com.enonic.xp.data.PropertyTree)13 Nodes (com.enonic.xp.node.Nodes)9 DynamicConstraintExpr (com.enonic.xp.query.expr.DynamicConstraintExpr)9 Aggregation (com.enonic.xp.aggregation.Aggregation)7 Buckets (com.enonic.xp.aggregation.Buckets)6 QueryExpr (com.enonic.xp.query.expr.QueryExpr)4 DateRangeBucket (com.enonic.xp.aggregation.DateRangeBucket)3 NodeHit (com.enonic.xp.node.NodeHit)3 CompareExpr (com.enonic.xp.query.expr.CompareExpr)3 NumericRangeBucket (com.enonic.xp.aggregation.NumericRangeBucket)2 ContentId (com.enonic.xp.content.ContentId)2 Context (com.enonic.xp.context.Context)2 PropertySet (com.enonic.xp.data.PropertySet)2