Search in sources :

Example 11 with SearchResult

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

the class FindNodeBranchEntriesByIdCommand method getNodeIds.

private NodeIds getNodeIds(final Context context) {
    if (this.ids.isEmpty()) {
        return NodeIds.empty();
    }
    final NodeQuery.Builder queryBuilder = NodeQuery.create().addQueryFilters(Filters.create().add(IdFilter.create().fieldName(NodeIndexPath.ID.getPath()).values(this.ids).build()).build()).from(0).size(ids.getSize()).batchSize(10000).addQueryFilter(AclFilterBuilderFactory.create(context.getAuthInfo().getPrincipals()));
    if (!this.orderExpressions.isEmpty()) {
        queryBuilder.setOrderExpressions(this.orderExpressions);
    }
    final SearchResult result = this.nodeSearchService.query(queryBuilder.build(), SingleRepoSearchSource.from(ContextAccessor.current()));
    return NodeIds.from(result.getIds());
}
Also used : NodeQuery(com.enonic.xp.node.NodeQuery) SearchResult(com.enonic.xp.repo.impl.search.result.SearchResult)

Example 12 with SearchResult

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

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

the class FindNodesDependenciesCommand method resolveDependencies.

private NodeIds resolveDependencies(final NodeIds nodeIds) {
    Set<NodeId> nonProcessedNodes = nodeIds.getSet().stream().filter((nodeId) -> !processed.contains(nodeId)).collect(Collectors.toSet());
    if (nonProcessedNodes.isEmpty()) {
        return NodeIds.empty();
    }
    final SearchResult result = getReferences(nonProcessedNodes);
    this.processed.addAll(nonProcessedNodes);
    final NodeIds.Builder builder = NodeIds.create();
    if (result.isEmpty()) {
        return NodeIds.empty();
    }
    addNodeIdsFromReferenceReturnValues(result, builder);
    if (this.recursive) {
        NodeIds currentLevelDependencies = builder.build();
        if (recursionFilter != null) {
            currentLevelDependencies = recursionFilter.apply(currentLevelDependencies);
        }
        builder.addAll(resolveDependencies(currentLevelDependencies));
    }
    return builder.build();
}
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) NodeIds(com.enonic.xp.node.NodeIds) NodeId(com.enonic.xp.node.NodeId) SearchResult(com.enonic.xp.repo.impl.search.result.SearchResult)

Example 14 with SearchResult

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

the class FindNodesWithVersionDifferenceCommand method execute.

public NodeVersionDiffResult execute() {
    final InternalContext context = InternalContext.from(ContextAccessor.current());
    final ExcludeEntries excludeEntries = getExcludePaths(context);
    final SearchResult result = this.nodeSearchService.query(NodeVersionDiffQuery.create().source(source).target(target).nodePath(nodePath).excludes(excludeEntries).size(this.size).batchSize(BATCH_SIZE).build(), SingleRepoStorageSource.create(ContextAccessor.current().getRepositoryId(), SingleRepoStorageSource.Type.VERSION));
    return NodeVersionDiffResultFactory.create(result);
}
Also used : InternalContext(com.enonic.xp.repo.impl.InternalContext) ExcludeEntries(com.enonic.xp.repo.impl.version.search.ExcludeEntries) SearchResult(com.enonic.xp.repo.impl.search.result.SearchResult)

Example 15 with SearchResult

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

the class MoveNodeCommand method doMoveNode.

private Node doMoveNode(final NodePath newParentPath, final NodeName newNodeName, final NodeId id) {
    final Node persistedNode = doGetById(id);
    final SearchResult result = this.nodeSearchService.query(NodeQuery.create().parent(persistedNode.path()).from(0).size(NodeSearchService.GET_ALL_SIZE_FLAG).build(), SingleRepoSearchSource.from(ContextAccessor.current()));
    final NodeBranchEntries nodeBranchEntries = this.nodeStorageService.getBranchNodeVersions(NodeIds.from(result.getIds()), false, InternalContext.from(ContextAccessor.current()));
    final Node.Builder nodeToMoveBuilder = Node.create(persistedNode).name(newNodeName).data(processor.process(persistedNode.data())).parentPath(newParentPath).indexConfigDocument(persistedNode.getIndexConfigDocument()).timestamp(Instant.now(CLOCK));
    final Node movedNode;
    final boolean isTheOriginalMovedNode = persistedNode.id().equals(this.nodeId);
    if (isTheOriginalMovedNode) {
        final boolean isRenaming = newParentPath.equals(persistedNode.parentPath());
        if (!isRenaming) {
            updateStoredNodeProperties(newParentPath, nodeToMoveBuilder);
        }
    }
    movedNode = doStore(nodeToMoveBuilder.build());
    this.result.addMovedNode(MoveNodeResult.MovedNode.create().previousPath(persistedNode.path()).node(movedNode).build());
    nodeMoved(1);
    for (final NodeBranchEntry nodeBranchEntry : nodeBranchEntries) {
        doMoveNode(nodeToMoveBuilder.build().path(), getNodeName(nodeBranchEntry), nodeBranchEntry.getNodeId());
    }
    return movedNode;
}
Also used : NodeBranchEntries(com.enonic.xp.node.NodeBranchEntries) Node(com.enonic.xp.node.Node) SearchResult(com.enonic.xp.repo.impl.search.result.SearchResult) NodeBranchEntry(com.enonic.xp.node.NodeBranchEntry)

Aggregations

SearchResult (com.enonic.xp.repo.impl.search.result.SearchResult)17 Node (com.enonic.xp.node.Node)6 NodeQuery (com.enonic.xp.node.NodeQuery)5 NodeIds (com.enonic.xp.node.NodeIds)3 ContextAccessor (com.enonic.xp.context.ContextAccessor)2 ChildOrder (com.enonic.xp.index.ChildOrder)2 NodeBranchEntry (com.enonic.xp.node.NodeBranchEntry)2 NodeId (com.enonic.xp.node.NodeId)2 NodeIndexPath (com.enonic.xp.node.NodeIndexPath)2 NodePath (com.enonic.xp.node.NodePath)2 ExistsFilter (com.enonic.xp.query.filter.ExistsFilter)2 IdFilter (com.enonic.xp.query.filter.IdFilter)2 ReturnFields (com.enonic.xp.repo.impl.ReturnFields)2 ReturnValue (com.enonic.xp.repo.impl.ReturnValue)2 SingleRepoSearchSource (com.enonic.xp.repo.impl.SingleRepoSearchSource)2 NodeBranchQueryResult (com.enonic.xp.repo.impl.branch.search.NodeBranchQueryResult)2 SearchHit (com.enonic.xp.repo.impl.search.result.SearchHit)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 Function (java.util.function.Function)2