Search in sources :

Example 1 with NodeHit

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();
}
Also used : NodeHit(com.enonic.xp.node.NodeHit) Nodes(com.enonic.xp.node.Nodes) FindContentByQueryParams(com.enonic.xp.content.FindContentByQueryParams) Collectors(java.util.stream.Collectors) HighlightedProperties(com.enonic.xp.highlight.HighlightedProperties) ContentId(com.enonic.xp.content.ContentId) Contents(com.enonic.xp.content.Contents) Map(java.util.Map) FindContentByQueryResult(com.enonic.xp.content.FindContentByQueryResult) Preconditions(com.google.common.base.Preconditions) NodeQuery(com.enonic.xp.node.NodeQuery) NodeIds(com.enonic.xp.node.NodeIds) FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) Contents(com.enonic.xp.content.Contents) FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) NodeIds(com.enonic.xp.node.NodeIds) HighlightedProperties(com.enonic.xp.highlight.HighlightedProperties) NodeQuery(com.enonic.xp.node.NodeQuery) ContentId(com.enonic.xp.content.ContentId) Nodes(com.enonic.xp.node.Nodes)

Example 2 with NodeHit

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();
}
Also used : CleanUpAuditLogResult(com.enonic.xp.audit.CleanUpAuditLogResult) NodeHit(com.enonic.xp.node.NodeHit) FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) NodeQuery(com.enonic.xp.node.NodeQuery)

Example 3 with NodeHit

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();
}
Also used : NodeHit(com.enonic.xp.node.NodeHit) SearchHit(com.enonic.xp.repo.impl.search.result.SearchHit) FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult)

Example 4 with NodeHit

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();
}
Also used : NodeHit(com.enonic.xp.node.NodeHit)

Aggregations

NodeHit (com.enonic.xp.node.NodeHit)4 FindNodesByQueryResult (com.enonic.xp.node.FindNodesByQueryResult)3 NodeQuery (com.enonic.xp.node.NodeQuery)2 CleanUpAuditLogResult (com.enonic.xp.audit.CleanUpAuditLogResult)1 ContentId (com.enonic.xp.content.ContentId)1 Contents (com.enonic.xp.content.Contents)1 FindContentByQueryParams (com.enonic.xp.content.FindContentByQueryParams)1 FindContentByQueryResult (com.enonic.xp.content.FindContentByQueryResult)1 HighlightedProperties (com.enonic.xp.highlight.HighlightedProperties)1 NodeIds (com.enonic.xp.node.NodeIds)1 Nodes (com.enonic.xp.node.Nodes)1 SearchHit (com.enonic.xp.repo.impl.search.result.SearchHit)1 Preconditions (com.google.common.base.Preconditions)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1