use of com.enonic.xp.node.FindNodesByQueryResult in project xp by enonic.
the class TermsAggregationsTest method order_doccount_desc.
@Test
public void order_doccount_desc() 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).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("c2", next.getKey());
assertEquals(3, next.getDocCount());
next = iterator.next();
assertEquals("c1", next.getKey());
assertEquals(2, next.getDocCount());
next = iterator.next();
assertEquals("c3", next.getKey());
assertEquals(1, next.getDocCount());
}
use of com.enonic.xp.node.FindNodesByQueryResult in project xp by enonic.
the class FindNodesByQueryHandler method execute.
@Override
public Object execute() {
final NodeQuery nodeQuery = createNodeQuery();
final FindNodesByQueryResult result = nodeService.findByQuery(nodeQuery);
return convert(result);
}
use of com.enonic.xp.node.FindNodesByQueryResult in project xp by enonic.
the class CleanUpAuditLogCommand method doCleanUp.
private CleanUpAuditLogResult doCleanUp() {
final CleanUpAuditLogResult.Builder result = CleanUpAuditLogResult.create();
final NodeQuery query = createQuery();
nodeService.refresh(RefreshMode.ALL);
FindNodesByQueryResult nodesToDelete = nodeService.findByQuery(query);
long hits = nodesToDelete.getHits();
final long totalHits = nodesToDelete.getTotalHits();
if (totalHits == 0) {
return CleanUpAuditLogResult.empty();
}
listener.start(BATCH_SIZE);
while (hits > 0) {
for (NodeHit nodeHit : nodesToDelete.getNodeHits()) {
result.deleted(nodeService.deleteById(nodeHit.getNodeId()).getSize());
listener.processed();
}
nodesToDelete = nodeService.findByQuery(query);
hits = nodesToDelete.getHits();
}
listener.finished();
return result.build();
}
use of com.enonic.xp.node.FindNodesByQueryResult in project xp by enonic.
the class SetPublishInfoCommand method findNodesWithoutPublishFirstAndFrom.
private NodeIds findNodesWithoutPublishFirstAndFrom(final NodeIds nodesToPush) {
if (nodesToPush.isEmpty()) {
return NodeIds.empty();
}
final BooleanFilter containPublishFirstAndFromFilter = BooleanFilter.create().must(ExistsFilter.create().fieldName(ContentIndexPath.PUBLISH_FIRST.getPath()).build()).must(ExistsFilter.create().fieldName(ContentIndexPath.PUBLISH_FROM.getPath()).build()).build();
final NodeQuery query = NodeQuery.create().addQueryFilter(BooleanFilter.create().mustNot(containPublishFirstAndFromFilter).must(IdFilter.create().fieldName(ContentIndexPath.ID.getPath()).values(nodesToPush).build()).build()).size(NodeQuery.ALL_RESULTS_SIZE_FLAG).build();
final FindNodesByQueryResult result = this.nodeService.findByQuery(query);
return result.getNodeIds();
}
use of com.enonic.xp.node.FindNodesByQueryResult in project xp by enonic.
the class FindNodesByQueryResultFactory method create.
static FindNodesByQueryResult create(final SearchResult result) {
final FindNodesByQueryResult.Builder resultBuilder = FindNodesByQueryResult.create().hits(result.getNumberOfHits()).totalHits(result.getTotalHits()).aggregations(result.getAggregations()).suggestions(result.getSuggestions());
for (final SearchHit hit : result.getHits()) {
final NodeHit.Builder nodeHit = NodeHit.create().nodeId(NodeId.from(hit.getId())).score(hit.getScore()).explanation(hit.getExplanation()).highlight(hit.getHighlightedProperties()).sort(hit.getSortValues());
final String nodePath = (String) hit.getReturnValues().getSingleValue(NodeIndexPath.PATH.getPath());
if (nodePath != null) {
nodeHit.nodePath(NodePath.create(nodePath).build());
}
resultBuilder.addNodeHit(nodeHit.build());
}
return resultBuilder.build();
}
Aggregations