Search in sources :

Example 26 with FindNodesByQueryResult

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

the class DateRangeAggregationTest method ranges.

@Test
public void ranges() throws Exception {
    createNode(Instant.parse("2014-12-10T10:00:00Z"), "n1", NodePath.ROOT);
    createNode(Instant.parse("2014-12-10T10:30:00Z"), "n2", NodePath.ROOT);
    createNode(Instant.parse("2014-12-10T11:30:00Z"), "n3", NodePath.ROOT);
    createNode(Instant.parse("2014-12-10T12:45:00Z"), "n4", NodePath.ROOT);
    createNode(Instant.parse("2014-12-10T13:59:59Z"), "n5", NodePath.ROOT);
    createNode(Instant.parse("2014-12-10T14:01:00Z"), "n6", NodePath.ROOT);
    final NodeQuery query = NodeQuery.create().addAggregationQuery(DateRangeAggregationQuery.create("myDateRange").fieldName("instant").addRange(DateRange.create().to(Instant.parse("2014-12-10T11:00:00Z")).build()).addRange(DateRange.create().from(Instant.parse("2014-12-10T11:00:00Z")).to(Instant.parse("2014-12-10T14:00:00Z")).build()).addRange(DateRange.create().from(Instant.parse("2014-12-10T14:00:00Z")).build()).build()).build();
    FindNodesByQueryResult result = doFindByQuery(query);
    assertEquals(1, result.getAggregations().getSize());
    final BucketAggregation aggregation = (BucketAggregation) result.getAggregations().get("myDateRange");
    final Buckets buckets = aggregation.getBuckets();
    final Iterator<Bucket> iterator = buckets.iterator();
    verifyBucket(iterator.next(), 2);
    verifyBucket(iterator.next(), 3);
    verifyBucket(iterator.next(), 1);
}
Also used : FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) DateRangeBucket(com.enonic.xp.aggregation.DateRangeBucket) Bucket(com.enonic.xp.aggregation.Bucket) NodeQuery(com.enonic.xp.node.NodeQuery) BucketAggregation(com.enonic.xp.aggregation.BucketAggregation) Buckets(com.enonic.xp.aggregation.Buckets) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 27 with FindNodesByQueryResult

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

the class StatsAggregationTest method terms_stats_aggregation.

@Test
public void terms_stats_aggregation() throws Exception {
    createNode("c1", 2.0, "n1", NodePath.ROOT);
    createNode("c1", 4.0, "n2", NodePath.ROOT);
    createNode("c1", 6.0, "n3", NodePath.ROOT);
    createNode("c1", 8.0, "n4", NodePath.ROOT);
    createNode("c2", 2.0, "n5", NodePath.ROOT);
    createNode("c2", 4.0, "n6", NodePath.ROOT);
    createNode("c3", 2.0, "n7", NodePath.ROOT);
    final NodeQuery query = NodeQuery.create().addAggregationQuery(TermsAggregationQuery.create("category").fieldName("category").orderDirection(TermsAggregationQuery.Direction.ASC).orderType(TermsAggregationQuery.Type.TERM).addSubQuery(StatsAggregationQuery.create("subquery").fieldName("other").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();
    verifyStatsAggregation(bucketIterator.next(), "c1", 2d, 8d, 5d, 20d, 4d);
    verifyStatsAggregation(bucketIterator.next(), "c2", 2d, 4d, 3d, 6d, 2d);
    verifyStatsAggregation(bucketIterator.next(), "c3", 2d, 2d, 2d, 2d, 1d);
}
Also used : BucketAggregation(com.enonic.xp.aggregation.BucketAggregation) StatsAggregation(com.enonic.xp.aggregation.StatsAggregation) 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 28 with FindNodesByQueryResult

use of com.enonic.xp.node.FindNodesByQueryResult 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 29 with FindNodesByQueryResult

use of com.enonic.xp.node.FindNodesByQueryResult 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 30 with FindNodesByQueryResult

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

the class CreateNodeCommand_path_integrity_test method create.

@Test
public void create() {
    final int concurrentAttempts = 5;
    final int expectedSuccessfulAttempts = 1;
    final AtomicInteger exceptionCounter = new AtomicInteger();
    CompletableFuture.allOf(IntStream.range(0, concurrentAttempts).mapToObj(i -> CompletableFuture.runAsync(CreateNodeTask.create().binaryService(this.binaryService).storageService(this.storageService).nodeSearchService(this.searchService).indexServiceInternal(this.indexServiceInternal).context(ContextAccessor.current()).build()).exceptionally(throwable -> {
        exceptionCounter.incrementAndGet();
        return null;
    })).toArray(CompletableFuture[]::new)).join();
    assertEquals(concurrentAttempts - expectedSuccessfulAttempts, exceptionCounter.get());
    refresh();
    final FindNodesByQueryResult result = doFindByQuery(NodeQuery.create().path(NodePath.create(NodePath.ROOT, "myNode").build()).build());
    assertEquals(expectedSuccessfulAttempts, result.getTotalHits());
}
Also used : IntStream(java.util.stream.IntStream) BeforeEach(org.junit.jupiter.api.BeforeEach) NodeStorageService(com.enonic.xp.repo.impl.storage.NodeStorageService) CreateNodeParams(com.enonic.xp.node.CreateNodeParams) NodeSearchService(com.enonic.xp.repo.impl.search.NodeSearchService) NodePath(com.enonic.xp.node.NodePath) CompletableFuture(java.util.concurrent.CompletableFuture) Test(org.junit.jupiter.api.Test) BinaryService(com.enonic.xp.repo.impl.binary.BinaryService) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ContextAccessor(com.enonic.xp.context.ContextAccessor) IndexServiceInternal(com.enonic.xp.repo.impl.index.IndexServiceInternal) Context(com.enonic.xp.context.Context) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) NodeQuery(com.enonic.xp.node.NodeQuery) FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) Test(org.junit.jupiter.api.Test)

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