Exemplo n.º 1
0
  @Test
  public void ranges_with_date_math_date() throws Exception {
    final Instant anchor = Instant.parse("2014-12-10T10:00:00Z");

    createNode(anchor, "n1", NodePath.ROOT);
    createNode(anchor.plusSeconds(-3600), "n2", NodePath.ROOT);
    createNode(anchor.plusSeconds(-3600 * 2), "n3", NodePath.ROOT);
    createNode(anchor.plusSeconds(-3600 * 3), "n4", NodePath.ROOT);
    createNode(anchor.plusSeconds(-3600 * 4), "n5", NodePath.ROOT);
    createNode(anchor.plusSeconds(-3600 * 5), "n6", NodePath.ROOT);

    final NodeQuery query =
        NodeQuery.create()
            .addAggregationQuery(
                DateRangeAggregationQuery.create("myDateRange")
                    .fieldName("instant")
                    .addRange(DateRange.create().to("2014-12-10T10:00:00Z||-5h").build())
                    .addRange(
                        DateRange.create()
                            .from("2014-12-10T10:00:00.000Z||-5h")
                            .to("2014-12-10T10:00:00.000Z||-3h")
                            .build())
                    .addRange(DateRange.create().from("2014-12-10T10:00:00Z||-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(), 0);
    verifyBucket(iterator.next(), 2);
    verifyBucket(iterator.next(), 4);
  }
Exemplo n.º 2
0
  @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);
  }