Search in sources :

Example 1 with SearchResult

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

the class BranchServiceImpl method doGetByPath.

private NodeBranchEntry doGetByPath(final NodePath nodePath, final InternalContext context) {
    final BranchDocumentId branchDocumentId = this.pathCache.get(new BranchPath(context.getRepositoryId(), context.getBranch(), nodePath));
    if (branchDocumentId != null) {
        return getFromCache(nodePath, context, branchDocumentId);
    }
    final NodeBranchQuery query = NodeBranchQuery.create().addQueryFilter(ValueFilter.create().fieldName(BranchIndexPath.PATH.getPath()).addValue(ValueFactory.newString(nodePath.toString())).build()).addQueryFilter(ValueFilter.create().fieldName(BranchIndexPath.BRANCH_NAME.getPath()).addValue(ValueFactory.newString(context.getBranch().getValue())).build()).size(1).build();
    final SearchResult result = this.searchDao.search(SearchRequest.create().searchSource(SingleRepoStorageSource.create(context.getRepositoryId(), SingleRepoStorageSource.Type.BRANCH)).returnFields(BRANCH_RETURN_FIELDS).query(query).searchPreference(context.getSearchPreference()).build());
    if (!result.isEmpty()) {
        final NodeBranchEntry nodeBranchEntry = NodeBranchVersionFactory.create(result.getHits().getFirst().getReturnValues());
        doCache(context, nodeBranchEntry.getNodePath(), nodeBranchEntry.getNodeId());
        return nodeBranchEntry;
    }
    return null;
}
Also used : BranchPath(com.enonic.xp.repo.impl.cache.BranchPath) NodeBranchQuery(com.enonic.xp.repo.impl.branch.search.NodeBranchQuery) SearchResult(com.enonic.xp.repo.impl.search.result.SearchResult) NodeBranchEntry(com.enonic.xp.node.NodeBranchEntry)

Example 2 with SearchResult

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

the class GetBranchDataCommand method execute.

public NodeBranchEntries execute() {
    final SearchResult result = doExecute();
    final NodeBranchQueryResult nodeBranchEntries = NodeBranchQueryResultFactory.create(result);
    return NodeBranchEntries.from(nodeBranchEntries.getList());
}
Also used : NodeBranchQueryResult(com.enonic.xp.repo.impl.branch.search.NodeBranchQueryResult) SearchResult(com.enonic.xp.repo.impl.search.result.SearchResult)

Example 3 with SearchResult

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

the class FindNodeIdsByParentCommand method execute.

public FindNodesByParentResult execute() {
    NodePath parentPath = getParentPath();
    if (parentPath == null) {
        return FindNodesByParentResult.empty();
    }
    final ChildOrder order = NodeChildOrderResolver.create(this).nodePath(parentPath).childOrder(childOrder).build().resolve();
    final SearchResult result = this.nodeSearchService.query(createFindChildrenQuery(parentPath, order), SingleRepoSearchSource.from(ContextAccessor.current()));
    if (result.getNumberOfHits() == 0) {
        return FindNodesByParentResult.create().totalHits(result.getTotalHits()).build();
    }
    return FindNodesByParentResult.create().nodeIds(NodeIds.from(result.getIds())).totalHits(result.getTotalHits()).hits(result.getNumberOfHits()).build();
}
Also used : ChildOrder(com.enonic.xp.index.ChildOrder) SearchResult(com.enonic.xp.repo.impl.search.result.SearchResult) NodePath(com.enonic.xp.node.NodePath)

Example 4 with SearchResult

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

the class FindNodesByMultiRepoQueryCommand method execute.

public FindNodesByMultiRepoQueryResult execute() {
    final SearchTargets searchTargets = query.getSearchTargets();
    final MultiRepoSearchSource.Builder searchSourceBuilder = MultiRepoSearchSource.create();
    for (final SearchTarget searchTarget : searchTargets) {
        searchSourceBuilder.add(SingleRepoSearchSource.create().branch(searchTarget.getBranch()).repositoryId(searchTarget.getRepositoryId()).acl(searchTarget.getPrincipalKeys()).build());
    }
    final SearchResult result = nodeSearchService.query(this.query.getNodeQuery(), searchSourceBuilder.build());
    return FindNodesByMultiRepoQueryResultFactory.create(result);
}
Also used : SearchTarget(com.enonic.xp.node.SearchTarget) MultiRepoSearchSource(com.enonic.xp.repo.impl.MultiRepoSearchSource) SearchResult(com.enonic.xp.repo.impl.search.result.SearchResult) SearchTargets(com.enonic.xp.node.SearchTargets)

Example 5 with SearchResult

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

the class FindNodesByParentCommand method execute.

public FindNodesByParentResult execute() {
    NodePath parentPath = params.getParentPath();
    if (parentPath == null) {
        Node parent = GetNodeByIdCommand.create(this).id(params.getParentId()).build().execute();
        if (parent == null) {
            return FindNodesByParentResult.empty();
        }
        parentPath = parent.path();
    }
    final ChildOrder order = NodeChildOrderResolver.create(this).nodePath(parentPath).childOrder(params.getChildOrder()).build().resolve();
    final SearchResult result = this.nodeSearchService.query(NodeQuery.create().parent(parentPath).addQueryFilters(params.getQueryFilters()).from(params.getFrom()).size(params.getSize()).searchMode(params.isCountOnly() ? SearchMode.COUNT : SearchMode.SEARCH).setOrderExpressions(order.getOrderExpressions()).accurateScoring(true).build(), SingleRepoSearchSource.from(ContextAccessor.current()));
    if (result.isEmpty()) {
        return FindNodesByParentResult.create().hits(0).totalHits(result.getTotalHits()).nodeIds(NodeIds.empty()).build();
    }
    return FindNodesByParentResult.create().nodeIds(NodeIds.from(result.getIds())).totalHits(result.getTotalHits()).hits(result.getNumberOfHits()).build();
}
Also used : Node(com.enonic.xp.node.Node) ChildOrder(com.enonic.xp.index.ChildOrder) SearchResult(com.enonic.xp.repo.impl.search.result.SearchResult) NodePath(com.enonic.xp.node.NodePath)

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