Search in sources :

Example 21 with FindNodesByQueryResult

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

the class GeoDistanceAggregationTest method ranges.

@Test
public void ranges() throws Exception {
    createNode(OSLO, "oslo", NodePath.ROOT);
    createNode(BERLIN, "berlin", NodePath.ROOT);
    createNode(NEW_YORK, "new-york", NodePath.ROOT);
    createNode(TRONDHEIM, "trondheim", NodePath.ROOT);
    createNode(MOSCOW, "moscow", NodePath.ROOT);
    createNode(FREDRIKSTAD, "fredrikstad", NodePath.ROOT);
    createNode(LONDON, "london", NodePath.ROOT);
    final NodeQuery query = NodeQuery.create().addAggregationQuery(GeoDistanceAggregationQuery.create("myGeoDistance").fieldName("geoPoint").origin(OSLO).unit("km").addRange(DistanceRange.create().to(200.0).build()).addRange(DistanceRange.create().from(200.0).to(800.0).build()).addRange(DistanceRange.create().from(800.0).to(1600.0).build()).addRange(DistanceRange.create().from(1600.0).to(2400.0).build()).addRange(DistanceRange.create().from(2400.0).build()).build()).build();
    FindNodesByQueryResult result = doFindByQuery(query);
    assertEquals(1, result.getAggregations().getSize());
    final BucketAggregation aggregation = (BucketAggregation) result.getAggregations().get("myGeoDistance");
    final Buckets buckets = aggregation.getBuckets();
    final Iterator<Bucket> iterator = buckets.iterator();
    // OSLO, FREDRIKSTAD
    verifyBucket(iterator.next(), 2, null);
    // TRONDHEIM
    verifyBucket(iterator.next(), 1, null);
    // BERLIN, LONDON
    verifyBucket(iterator.next(), 2, null);
    // MOSCOW
    verifyBucket(iterator.next(), 1, null);
    // NEW YORK
    verifyBucket(iterator.next(), 1, null);
}
Also used : FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) GeoDistanceRangeBucket(com.enonic.xp.aggregation.GeoDistanceRangeBucket) 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 22 with FindNodesByQueryResult

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

the class NumericRangeAggregationTest method keys.

@Test
public void keys() throws Exception {
    createNode(100d, "n1", NodePath.ROOT);
    createNode(200d, "n4", NodePath.ROOT);
    createNode(300d, "n2", NodePath.ROOT);
    createNode(400d, "n3", NodePath.ROOT);
    createNode(500d, "n6", NodePath.ROOT);
    createNode(600d, "n5", NodePath.ROOT);
    final NodeQuery query = NodeQuery.create().addAggregationQuery(NumericRangeAggregationQuery.create("myNumericRange").fieldName("numeric").addRange(NumericRange.create().key("small").to(350d).build()).addRange(NumericRange.create().key("large").from(350d).build()).build()).build();
    FindNodesByQueryResult result = doFindByQuery(query);
    assertEquals(1, result.getAggregations().getSize());
    final BucketAggregation aggregation = (BucketAggregation) result.getAggregations().get("myNumericRange");
    final Buckets buckets = aggregation.getBuckets();
    final Iterator<Bucket> iterator = buckets.iterator();
    verifyBucket(iterator.next(), 3, "small");
    verifyBucket(iterator.next(), 3, "large");
}
Also used : FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) NumericRangeBucket(com.enonic.xp.aggregation.NumericRangeBucket) 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 23 with FindNodesByQueryResult

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

the class NumericRangeAggregationTest method ranges.

@Test
public void ranges() throws Exception {
    createNode(100d, "n1", NodePath.ROOT);
    createNode(300d, "n2", NodePath.ROOT);
    createNode(400d, "n3", NodePath.ROOT);
    createNode(200d, "n4", NodePath.ROOT);
    createNode(600d, "n5", NodePath.ROOT);
    createNode(500d, "n6", NodePath.ROOT);
    final NodeQuery query = NodeQuery.create().addAggregationQuery(NumericRangeAggregationQuery.create("myNumericRange").fieldName("numeric").addRange(NumericRange.create().to(150d).build()).addRange(NumericRange.create().from(150d).to(250d).build()).addRange(NumericRange.create().from(250d).to(350d).build()).addRange(NumericRange.create().from(350d).build()).build()).build();
    FindNodesByQueryResult result = doFindByQuery(query);
    assertEquals(1, result.getAggregations().getSize());
    final BucketAggregation aggregation = (BucketAggregation) result.getAggregations().get("myNumericRange");
    final Buckets buckets = aggregation.getBuckets();
    final Iterator<Bucket> iterator = buckets.iterator();
    verifyBucket(iterator.next(), 1, null);
    verifyBucket(iterator.next(), 1, null);
    verifyBucket(iterator.next(), 1, null);
    verifyBucket(iterator.next(), 3, null);
}
Also used : FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) NumericRangeBucket(com.enonic.xp.aggregation.NumericRangeBucket) 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 24 with FindNodesByQueryResult

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

the class DateHistogramAggregationsTest method min_doc_count.

@Test
public void min_doc_count() throws Exception {
    // Create 5 nodes with two hours between
    createNode(Instant.parse("2014-12-10T10:00:00Z"), "n1", NodePath.ROOT);
    createNode(Instant.parse("2014-12-10T12:00:00Z"), "n2", NodePath.ROOT);
    createNode(Instant.parse("2014-12-10T14:00:00Z"), "n3", NodePath.ROOT);
    createNode(Instant.parse("2014-12-10T16:00:59Z"), "n4", NodePath.ROOT);
    createNode(Instant.parse("2014-12-10T18:00:00Z"), "n5", NodePath.ROOT);
    final NodeQuery query = NodeQuery.create().addAggregationQuery(DateHistogramAggregationQuery.create("dateHistogramWithZero").fieldName("instant").interval("1h").minDocCount(0L).build()).addAggregationQuery(DateHistogramAggregationQuery.create("dateHistogramWithDefault").fieldName("instant").interval("1h").build()).build();
    FindNodesByQueryResult result = doFindByQuery(query);
    assertEquals(2, result.getAggregations().getSize());
    // The min-doc-count=0 will also return the empty fill-ins
    final BucketAggregation zeroDocCount = (BucketAggregation) result.getAggregations().get("dateHistogramWithZero");
    final BucketAggregation defaultDocCount = (BucketAggregation) result.getAggregations().get("dateHistogramWithDefault");
    assertEquals(9, zeroDocCount.getBuckets().getSize());
    assertEquals(5, defaultDocCount.getBuckets().getSize());
}
Also used : FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) 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 25 with FindNodesByQueryResult

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

the class DateRangeAggregationTest method ranges_with_date_math.

@Test
public void ranges_with_date_math() throws Exception {
    final Instant now = Instant.now();
    createNode(now, "n1", NodePath.ROOT);
    createNode(now.plusSeconds(-3600), "n2", NodePath.ROOT);
    createNode(now.plusSeconds(-3600 * 2), "n3", NodePath.ROOT);
    createNode(now.plusSeconds(-3600 * 3), "n4", NodePath.ROOT);
    createNode(now.plusSeconds(-3600 * 4), "n5", NodePath.ROOT);
    createNode(now.plusSeconds(-3600 * 5), "n6", NodePath.ROOT);
    final NodeQuery query = NodeQuery.create().addAggregationQuery(DateRangeAggregationQuery.create("myDateRange").fieldName("instant").addRange(DateRange.create().to("now-5h").build()).addRange(DateRange.create().from("now-5h").to("now-3h").build()).addRange(DateRange.create().from("now-3h").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(), 1);
    verifyBucket(iterator.next(), 2);
    verifyBucket(iterator.next(), 3);
}
Also used : FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) DateRangeBucket(com.enonic.xp.aggregation.DateRangeBucket) Bucket(com.enonic.xp.aggregation.Bucket) Instant(java.time.Instant) 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)

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