Search in sources :

Example 1 with SearchHit

use of com.enonic.xp.repo.impl.search.result.SearchHit 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 2 with SearchHit

use of com.enonic.xp.repo.impl.search.result.SearchHit in project xp by enonic.

the class FindNodesDependenciesCommand method addNodeIdsFromReferenceReturnValues.

private void addNodeIdsFromReferenceReturnValues(final SearchResult result, final NodeIds.Builder builder) {
    for (SearchHit hit : result.getHits()) {
        final ReturnValue returnValue = hit.getReturnValues().get(NodeIndexPath.REFERENCE.getPath());
        if (returnValue == null || returnValue.getValues().isEmpty()) {
            continue;
        }
        returnValue.getValues().stream().map((value) -> NodeId.from(value.toString())).filter((value) -> !processed.contains(value)).filter((value) -> !excludedIds.contains(value)).forEach(builder::add);
    }
}
Also used : IdFilter(com.enonic.xp.query.filter.IdFilter) ReturnFields(com.enonic.xp.repo.impl.ReturnFields) ReturnValue(com.enonic.xp.repo.impl.ReturnValue) NodeIndexPath(com.enonic.xp.node.NodeIndexPath) ExistsFilter(com.enonic.xp.query.filter.ExistsFilter) Set(java.util.Set) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) SingleRepoSearchSource(com.enonic.xp.repo.impl.SingleRepoSearchSource) NodeId(com.enonic.xp.node.NodeId) HashSet(java.util.HashSet) SearchResult(com.enonic.xp.repo.impl.search.result.SearchResult) ContextAccessor(com.enonic.xp.context.ContextAccessor) SearchHit(com.enonic.xp.repo.impl.search.result.SearchHit) NodeQuery(com.enonic.xp.node.NodeQuery) NodeIds(com.enonic.xp.node.NodeIds) SearchHit(com.enonic.xp.repo.impl.search.result.SearchHit) ReturnValue(com.enonic.xp.repo.impl.ReturnValue)

Example 3 with SearchHit

use of com.enonic.xp.repo.impl.search.result.SearchHit in project xp by enonic.

the class NodeVersionDiffResultFactory method create.

public static NodeVersionDiffResult create(final SearchResult result) {
    if (result.isEmpty()) {
        return NodeVersionDiffResult.create().totalHits(result.getTotalHits()).build();
    }
    final NodeVersionDiffResult.Builder builder = NodeVersionDiffResult.create();
    builder.totalHits(result.getTotalHits());
    for (final SearchHit hit : result.getHits()) {
        builder.add(NodeId.from(hit.getField(VersionIndexPath.NODE_ID.toString()).getSingleValue().toString()));
    }
    return builder.build();
}
Also used : NodeVersionDiffResult(com.enonic.xp.node.NodeVersionDiffResult) SearchHit(com.enonic.xp.repo.impl.search.result.SearchHit)

Aggregations

SearchHit (com.enonic.xp.repo.impl.search.result.SearchHit)3 ContextAccessor (com.enonic.xp.context.ContextAccessor)1 FindNodesByQueryResult (com.enonic.xp.node.FindNodesByQueryResult)1 NodeHit (com.enonic.xp.node.NodeHit)1 NodeId (com.enonic.xp.node.NodeId)1 NodeIds (com.enonic.xp.node.NodeIds)1 NodeIndexPath (com.enonic.xp.node.NodeIndexPath)1 NodeQuery (com.enonic.xp.node.NodeQuery)1 NodeVersionDiffResult (com.enonic.xp.node.NodeVersionDiffResult)1 ExistsFilter (com.enonic.xp.query.filter.ExistsFilter)1 IdFilter (com.enonic.xp.query.filter.IdFilter)1 ReturnFields (com.enonic.xp.repo.impl.ReturnFields)1 ReturnValue (com.enonic.xp.repo.impl.ReturnValue)1 SingleRepoSearchSource (com.enonic.xp.repo.impl.SingleRepoSearchSource)1 SearchResult (com.enonic.xp.repo.impl.search.result.SearchResult)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1