Search in sources :

Example 46 with NodeQuery

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

the class DeleteNodeByIdsCommandPerformanceTest method deleteNodeByIds.

@Disabled
@Test
public void deleteNodeByIds() throws Exception {
    final Node rootNode = createNode(CreateNodeParams.create().name("rootNode").parent(NodePath.ROOT).build(), false);
    createNodes(rootNode, 50, 3, 1);
    refresh();
    final NodeQuery query = NodeQuery.create().searchMode(SearchMode.COUNT).build();
    final FindNodesByQueryResult result = FindNodesByQueryCommand.create().query(query).searchService(this.searchService).storageService(this.storageService).indexServiceInternal(this.indexServiceInternal).build().execute();
    final Stopwatch started = Stopwatch.createStarted();
    DeleteNodeByIdCommand.create().nodeId(rootNode.id()).searchService(this.searchService).storageService(this.storageService).indexServiceInternal(this.indexServiceInternal).build().execute();
    started.stop();
    System.out.println("Deleted [" + result.getTotalHits() + "] in " + started);
}
Also used : FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) Node(com.enonic.xp.node.Node) NodeQuery(com.enonic.xp.node.NodeQuery) Stopwatch(com.google.common.base.Stopwatch) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 47 with NodeQuery

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

the class ValueCountAggregationTest method terms_stats_aggregation.

@Test
public void terms_stats_aggregation() throws Exception {
    createNode("c1", "n1", NodePath.ROOT);
    createNode("c1", "n2", NodePath.ROOT);
    createNode("c1", "n3", NodePath.ROOT);
    createNode("c1", "n4", NodePath.ROOT);
    createNode("c2", "n5", NodePath.ROOT);
    createNode("c2", "n6", NodePath.ROOT);
    createNode("c3", "n7", NodePath.ROOT);
    final NodeQuery query = NodeQuery.create().addAggregationQuery(TermsAggregationQuery.create("category").fieldName("category").orderDirection(TermsAggregationQuery.Direction.ASC).orderType(TermsAggregationQuery.Type.TERM).addSubQuery(ValueCountAggregationQuery.create("subquery").fieldName("category").build()).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;
    final Iterator<Bucket> bucketIterator = categoryAgg.getBuckets().iterator();
    verifyValueCount(bucketIterator.next(), "c1", 4d);
    verifyValueCount(bucketIterator.next(), "c2", 2d);
    verifyValueCount(bucketIterator.next(), "c3", 1d);
}
Also used : BucketAggregation(com.enonic.xp.aggregation.BucketAggregation) SingleValueMetricAggregation(com.enonic.xp.aggregation.SingleValueMetricAggregation) 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 48 with NodeQuery

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

the class TermsAggregationsTest method nested_term_aggregation.

@Test
public void nested_term_aggregation() throws Exception {
    createNode("c1", "d1", "node1", NodePath.ROOT);
    createNode("c1", "d1", "node2", NodePath.ROOT);
    createNode("c1", "d2", "node3", NodePath.ROOT);
    createNode("c1", "d3", "node4", NodePath.ROOT);
    createNode("c2", "d1", "node5", NodePath.ROOT);
    createNode("c2", "d2", "node6", NodePath.ROOT);
    createNode("c2", "d2", "node7", NodePath.ROOT);
    createNode("c2", "d3", "node8", NodePath.ROOT);
    createNode("c3", "d1", "node9", NodePath.ROOT);
    createNode("c3", "d2", "node10", NodePath.ROOT);
    createNode("c3", "d3", "node11", NodePath.ROOT);
    createNode("c3", "d3", "node12", NodePath.ROOT);
    final NodeQuery query = NodeQuery.create().addAggregationQuery(TermsAggregationQuery.create("category").fieldName("category").orderDirection(TermsAggregationQuery.Direction.ASC).orderType(TermsAggregationQuery.Type.TERM).addSubQuery(TermsAggregationQuery.create("subquery").fieldName("other").orderDirection(TermsAggregationQuery.Direction.ASC).orderType(TermsAggregationQuery.Type.TERM).build()).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;
    final Iterator<Bucket> bucketIterator = categoryAgg.getBuckets().iterator();
    // Verify the number of values for each category, e.g in category
    // c1, there are 2 'd1's, 1 'd2' and 1 'd3'
    verifySubAggregation(bucketIterator.next(), "c1", 2, 1, 1);
    verifySubAggregation(bucketIterator.next(), "c2", 1, 2, 1);
    verifySubAggregation(bucketIterator.next(), "c3", 1, 1, 2);
}
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 49 with NodeQuery

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

the class TermsAggregationsTest method order_doccount_asc.

@Test
public void order_doccount_asc() 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.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("c3", next.getKey());
    assertEquals(1, next.getDocCount());
    next = iterator.next();
    assertEquals("c1", next.getKey());
    assertEquals(2, next.getDocCount());
    next = iterator.next();
    assertEquals("c2", next.getKey());
    assertEquals(3, 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 50 with NodeQuery

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

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