use of com.enonic.xp.repo.impl.branch.search.NodeBranchQuery 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;
}
Aggregations