use of com.enonic.xp.node.NodeHit 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();
}
use of com.enonic.xp.node.NodeHit 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.NodeHit 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();
}
use of com.enonic.xp.node.NodeHit in project xp by enonic.
the class NodeQueryResultMapper method serialize.
private void serialize(final MapGenerator gen, final NodeHits nodeHits) {
gen.array("hits");
for (NodeHit nodeHit : nodeHits) {
gen.map();
gen.value("id", nodeHit.getNodeId());
gen.value("score", Float.isNaN(nodeHit.getScore()) ? 0.0 : nodeHit.getScore());
serialize(gen, nodeHit.getExplanation());
serialize(gen, nodeHit.getHighlight());
gen.end();
}
gen.end();
}
Aggregations