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);
}
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");
}
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);
}
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());
}
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);
}
Aggregations