Search in sources :

Example 51 with FindNodesByQueryResult

use of com.enonic.xp.node.FindNodesByQueryResult in project xp by enonic.

the class TermsAggregationsTest method order_doccount_desc.

@Test
public void order_doccount_desc() throws Exception {
    create_c1_c2_c3_with_2_3_1_category_hits();
    final NodeQuery query = NodeQuery.create().addAggregationQuery(TermsAggregationQuery.create("category").fieldName("category").orderDirection(TermsAggregationQuery.Direction.DESC).orderType(TermsAggregationQuery.Type.DOC_COUNT).build()).build();
    FindNodesByQueryResult result = doFindByQuery(query);
    assertEquals(1, result.getAggregations().getSize());
    final Aggregation agg = result.getAggregations().get("category");
    assertTrue(agg instanceof BucketAggregation);
    final BucketAggregation categoryAgg = (BucketAggregation) agg;
    assertEquals(3, categoryAgg.getBuckets().getSize());
    final Iterator<Bucket> iterator = categoryAgg.getBuckets().iterator();
    Bucket next = iterator.next();
    assertEquals("c2", next.getKey());
    assertEquals(3, next.getDocCount());
    next = iterator.next();
    assertEquals("c1", next.getKey());
    assertEquals(2, next.getDocCount());
    next = iterator.next();
    assertEquals("c3", next.getKey());
    assertEquals(1, next.getDocCount());
}
Also used : BucketAggregation(com.enonic.xp.aggregation.BucketAggregation) Aggregation(com.enonic.xp.aggregation.Aggregation) FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) Bucket(com.enonic.xp.aggregation.Bucket) NodeQuery(com.enonic.xp.node.NodeQuery) BucketAggregation(com.enonic.xp.aggregation.BucketAggregation) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 52 with FindNodesByQueryResult

use of com.enonic.xp.node.FindNodesByQueryResult in project xp by enonic.

the class FindNodesByQueryHandler method execute.

@Override
public Object execute() {
    final NodeQuery nodeQuery = createNodeQuery();
    final FindNodesByQueryResult result = nodeService.findByQuery(nodeQuery);
    return convert(result);
}
Also used : FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) NodeQuery(com.enonic.xp.node.NodeQuery)

Example 53 with FindNodesByQueryResult

use of com.enonic.xp.node.FindNodesByQueryResult in project xp by enonic.

the class CleanUpAuditLogCommand method doCleanUp.

private CleanUpAuditLogResult doCleanUp() {
    final CleanUpAuditLogResult.Builder result = CleanUpAuditLogResult.create();
    final NodeQuery query = createQuery();
    nodeService.refresh(RefreshMode.ALL);
    FindNodesByQueryResult nodesToDelete = nodeService.findByQuery(query);
    long hits = nodesToDelete.getHits();
    final long totalHits = nodesToDelete.getTotalHits();
    if (totalHits == 0) {
        return CleanUpAuditLogResult.empty();
    }
    listener.start(BATCH_SIZE);
    while (hits > 0) {
        for (NodeHit nodeHit : nodesToDelete.getNodeHits()) {
            result.deleted(nodeService.deleteById(nodeHit.getNodeId()).getSize());
            listener.processed();
        }
        nodesToDelete = nodeService.findByQuery(query);
        hits = nodesToDelete.getHits();
    }
    listener.finished();
    return result.build();
}
Also used : CleanUpAuditLogResult(com.enonic.xp.audit.CleanUpAuditLogResult) NodeHit(com.enonic.xp.node.NodeHit) FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) NodeQuery(com.enonic.xp.node.NodeQuery)

Example 54 with FindNodesByQueryResult

use of com.enonic.xp.node.FindNodesByQueryResult in project xp by enonic.

the class SetPublishInfoCommand method findNodesWithoutPublishFirstAndFrom.

private NodeIds findNodesWithoutPublishFirstAndFrom(final NodeIds nodesToPush) {
    if (nodesToPush.isEmpty()) {
        return NodeIds.empty();
    }
    final BooleanFilter containPublishFirstAndFromFilter = BooleanFilter.create().must(ExistsFilter.create().fieldName(ContentIndexPath.PUBLISH_FIRST.getPath()).build()).must(ExistsFilter.create().fieldName(ContentIndexPath.PUBLISH_FROM.getPath()).build()).build();
    final NodeQuery query = NodeQuery.create().addQueryFilter(BooleanFilter.create().mustNot(containPublishFirstAndFromFilter).must(IdFilter.create().fieldName(ContentIndexPath.ID.getPath()).values(nodesToPush).build()).build()).size(NodeQuery.ALL_RESULTS_SIZE_FLAG).build();
    final FindNodesByQueryResult result = this.nodeService.findByQuery(query);
    return result.getNodeIds();
}
Also used : BooleanFilter(com.enonic.xp.query.filter.BooleanFilter) FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) NodeQuery(com.enonic.xp.node.NodeQuery)

Example 55 with FindNodesByQueryResult

use of com.enonic.xp.node.FindNodesByQueryResult in project xp by enonic.

the class FindNodesByQueryResultFactory method create.

static FindNodesByQueryResult create(final SearchResult result) {
    final FindNodesByQueryResult.Builder resultBuilder = FindNodesByQueryResult.create().hits(result.getNumberOfHits()).totalHits(result.getTotalHits()).aggregations(result.getAggregations()).suggestions(result.getSuggestions());
    for (final SearchHit hit : result.getHits()) {
        final NodeHit.Builder nodeHit = NodeHit.create().nodeId(NodeId.from(hit.getId())).score(hit.getScore()).explanation(hit.getExplanation()).highlight(hit.getHighlightedProperties()).sort(hit.getSortValues());
        final String nodePath = (String) hit.getReturnValues().getSingleValue(NodeIndexPath.PATH.getPath());
        if (nodePath != null) {
            nodeHit.nodePath(NodePath.create(nodePath).build());
        }
        resultBuilder.addNodeHit(nodeHit.build());
    }
    return resultBuilder.build();
}
Also used : NodeHit(com.enonic.xp.node.NodeHit) SearchHit(com.enonic.xp.repo.impl.search.result.SearchHit) FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult)

Aggregations

FindNodesByQueryResult (com.enonic.xp.node.FindNodesByQueryResult)84 NodeQuery (com.enonic.xp.node.NodeQuery)61 Test (org.junit.jupiter.api.Test)55 Node (com.enonic.xp.node.Node)32 BucketAggregation (com.enonic.xp.aggregation.BucketAggregation)19 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)19 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)8 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 SingleValueMetricAggregation (com.enonic.xp.aggregation.SingleValueMetricAggregation)2 ContentId (com.enonic.xp.content.ContentId)2 Context (com.enonic.xp.context.Context)2