use of com.enonic.xp.node.NodeQuery 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());
}
use of com.enonic.xp.node.NodeQuery 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());
}
use of com.enonic.xp.node.NodeQuery in project xp by enonic.
the class FindNodesByMultiNodeQueryHandler method execute.
@Override
public Object execute() {
final NodeQuery nodeQuery = createNodeQuery();
final MultiRepoNodeQuery multiRepoNodeQuery = new MultiRepoNodeQuery(this.searchTargets, nodeQuery);
final FindNodesByMultiRepoQueryResult result = this.nodeService.findByQuery(multiRepoNodeQuery);
return convert(result);
}
use of com.enonic.xp.node.NodeQuery in project xp by enonic.
the class CleanUpAuditLogCommand method createQuery.
private NodeQuery createQuery() {
final NodeQuery.Builder builder = NodeQuery.create().addQueryFilter(ValueFilter.create().fieldName(NodeIndexPath.NODE_TYPE.toString()).addValue(ValueFactory.newString(AuditLogConstants.NODE_TYPE.toString())).build());
final RangeFilter timeToFilter = RangeFilter.create().fieldName(AuditLogConstants.TIME.toString()).to(ValueFactory.newDateTime(until)).build();
builder.addQueryFilter(timeToFilter);
builder.addOrderBy(FieldOrderExpr.create(AuditLogConstants.TIME, OrderExpr.Direction.ASC)).size(BATCH_SIZE);
return builder.build();
}
use of com.enonic.xp.node.NodeQuery in project xp by enonic.
the class FindAuditLogCommand method runQuery.
private FindAuditLogResult runQuery() {
final NodeQuery query = createQuery();
if (query == null) {
return FindAuditLogResult.empty();
}
FindNodesByQueryResult result = nodeService.findByQuery(query);
List<AuditLog> logs = result.getNodeIds().stream().map(nodeService::getById).map(AuditLogSerializer::fromNode).collect(Collectors.toList());
return FindAuditLogResult.create().total(result.getTotalHits()).hits(AuditLogs.from(logs)).build();
}
Aggregations