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();
}
use of com.enonic.xp.node.NodeQuery in project xp by enonic.
the class FindContentPathsByQueryCommand method execute.
public FindContentPathsByQueryResult execute() {
final NodeQuery nodeQuery = ContentQueryNodeQueryTranslator.translate(this.params.getContentQuery()).addQueryFilters(createFilters()).withPath(true).build();
final FindNodesByQueryResult result = nodeService.findByQuery(nodeQuery);
return FindContentPathsByQueryResult.create().contentPaths(ContentPaths.from(result.getNodeHits().stream().map(NodeHit::getNodePath).map(ContentNodeHelper::translateNodePathToContentPath).collect(Collectors.toSet()))).hits(result.getHits()).totalHits(result.getTotalHits()).build();
}
use of com.enonic.xp.node.NodeQuery in project xp by enonic.
the class FindContentByQueryCommand method execute.
FindContentByQueryResult execute() {
final NodeQuery nodeQuery = ContentQueryNodeQueryTranslator.translate(this.params.getContentQuery()).addQueryFilters(createFilters()).build();
final FindNodesByQueryResult result = nodeService.findByQuery(nodeQuery);
final NodeIds nodeIds = result.getNodeIds();
final Map<ContentId, HighlightedProperties> highlight = result.getNodeHits().stream().filter(nodeHit -> nodeHit.getHighlight() != null && nodeHit.getHighlight().size() > 0).collect(Collectors.toMap(hit -> ContentId.from(hit.getNodeId().toString()), NodeHit::getHighlight));
final Nodes foundNodes = this.nodeService.getByIds(nodeIds);
Contents contents = this.translator.fromNodes(foundNodes, true);
return FindContentByQueryResult.create().contents(contents).aggregations(result.getAggregations()).hits(result.getHits()).totalHits(result.getTotalHits()).highlight(highlight).build();
}
Aggregations