Search in sources :

Example 31 with NodeQuery

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

the class TermsAggregationsTest method size.

@Test
public void size() 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).size(2).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(2, 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());
}
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 32 with NodeQuery

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

the class TermsAggregationsTest method order_by_term.

@Test
public void order_by_term() 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.ASC).orderType(TermsAggregationQuery.Type.TERM).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("c1", next.getKey());
    assertEquals(2, next.getDocCount());
    next = iterator.next();
    assertEquals("c2", next.getKey());
    assertEquals(3, 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 33 with NodeQuery

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

the class FindNodesByMultiNodeQueryHandler method execute.

@Override
public Object execute() {
    final NodeQuery nodeQuery = createNodeQuery();
    final MultiRepoNodeQuery multiRepoNodeQuery = new MultiRepoNodeQuery(this.searchTargets, nodeQuery);
    final FindNodesByMultiRepoQueryResult result = this.nodeService.findByQuery(multiRepoNodeQuery);
    return convert(result);
}
Also used : FindNodesByMultiRepoQueryResult(com.enonic.xp.node.FindNodesByMultiRepoQueryResult) MultiRepoNodeQuery(com.enonic.xp.node.MultiRepoNodeQuery) NodeQuery(com.enonic.xp.node.NodeQuery) MultiRepoNodeQuery(com.enonic.xp.node.MultiRepoNodeQuery)

Example 34 with NodeQuery

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

the class CleanUpAuditLogCommand method createQuery.

private NodeQuery createQuery() {
    final NodeQuery.Builder builder = NodeQuery.create().addQueryFilter(ValueFilter.create().fieldName(NodeIndexPath.NODE_TYPE.toString()).addValue(ValueFactory.newString(AuditLogConstants.NODE_TYPE.toString())).build());
    final RangeFilter timeToFilter = RangeFilter.create().fieldName(AuditLogConstants.TIME.toString()).to(ValueFactory.newDateTime(until)).build();
    builder.addQueryFilter(timeToFilter);
    builder.addOrderBy(FieldOrderExpr.create(AuditLogConstants.TIME, OrderExpr.Direction.ASC)).size(BATCH_SIZE);
    return builder.build();
}
Also used : NodeQuery(com.enonic.xp.node.NodeQuery) RangeFilter(com.enonic.xp.query.filter.RangeFilter)

Example 35 with NodeQuery

use of com.enonic.xp.node.NodeQuery 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)

Aggregations

NodeQuery (com.enonic.xp.node.NodeQuery)74 FindNodesByQueryResult (com.enonic.xp.node.FindNodesByQueryResult)59 Test (org.junit.jupiter.api.Test)45 Node (com.enonic.xp.node.Node)24 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)11 DynamicConstraintExpr (com.enonic.xp.query.expr.DynamicConstraintExpr)10 Aggregation (com.enonic.xp.aggregation.Aggregation)8 Buckets (com.enonic.xp.aggregation.Buckets)6 FindNodesByMultiRepoQueryResult (com.enonic.xp.node.FindNodesByMultiRepoQueryResult)6 MultiRepoNodeQuery (com.enonic.xp.node.MultiRepoNodeQuery)6 Nodes (com.enonic.xp.node.Nodes)5 SearchTargets (com.enonic.xp.node.SearchTargets)5 Repository (com.enonic.xp.repository.Repository)5 DateRangeBucket (com.enonic.xp.aggregation.DateRangeBucket)3 ContentId (com.enonic.xp.content.ContentId)3 NumericRangeBucket (com.enonic.xp.aggregation.NumericRangeBucket)2 SingleValueMetricAggregation (com.enonic.xp.aggregation.SingleValueMetricAggregation)2