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;
}
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());
}
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();
}
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);
}
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();
}
Aggregations