use of com.enonic.xp.repo.impl.search.result.SearchResult in project xp by enonic.
the class HasUnpublishedChildrenCommand method execute.
public boolean execute() {
final Node parentNode = doGetById(parent);
if (parentNode == null) {
return false;
}
final SearchResult result = nodeSearchService.query(NodeVersionDiffQuery.create().source(ContextAccessor.current().getBranch()).target(target).nodePath(parentNode.path()).size(0).excludes(ExcludeEntries.create().add(new ExcludeEntry(parentNode.path(), false)).build()).build(), SingleRepoStorageSource.create(ContextAccessor.current().getRepositoryId(), SingleRepoStorageSource.Type.VERSION));
return result.getTotalHits() > 0;
}
use of com.enonic.xp.repo.impl.search.result.SearchResult in project xp by enonic.
the class SetNodeChildOrderCommand method orderChildNodes.
private void orderChildNodes(final Node parentNode) {
final SearchResult result = nodeSearchService.query(NodeQuery.create().parent(parentNode.path()).query(new QueryExpr(parentNode.getChildOrder().getOrderExpressions())).size(NodeSearchService.GET_ALL_SIZE_FLAG).batchSize(BATCH_SIZE).searchMode(SearchMode.SEARCH).build(), SingleRepoSearchSource.from(ContextAccessor.current()));
final NodeIds childNodeIds = NodeIds.from(result.getIds());
final List<NodeManualOrderValueResolver.NodeIdOrderValue> orderedNodeIds = NodeManualOrderValueResolver.resolve(childNodeIds);
for (final NodeManualOrderValueResolver.NodeIdOrderValue nodeIdOrderValue : orderedNodeIds) {
final Node node = doGetById(nodeIdOrderValue.getNodeId());
final Node editedNode = Node.create(node).manualOrderValue(nodeIdOrderValue.getManualOrderValue()).timestamp(Instant.now(CLOCK)).build();
StoreNodeCommand.create(this).node(editedNode).build().execute();
}
}
use of com.enonic.xp.repo.impl.search.result.SearchResult in project xp by enonic.
the class NodeOrderTest method score_sorting.
@Test
public void score_sorting() throws Exception {
final Node node1 = createNode("node1", ValueFactory.newString("denne har en fisk"));
final Node node2 = createNode("node2", ValueFactory.newString("denne har fisk og ost"));
final Node node3 = createNode("node3", ValueFactory.newString("mens denne har både fisk, ost og pølse"));
final Node node4 = createNode("node4", ValueFactory.newString("denne vinner, siden den har alle sammen: fisk, ost, pølse og pai"));
final FunctionExpr fulltextExpression = FunctionExpr.from("fulltext", ValueExpr.string("my-value"), ValueExpr.string("pai fisk pølse ost"), ValueExpr.string("OR"));
final NodeQuery fulltextQuery = NodeQuery.create().query(QueryExpr.from(new DynamicConstraintExpr(fulltextExpression), FieldOrderExpr.create(IndexPath.from("_score"), OrderExpr.Direction.DESC))).build();
printContentRepoIndex();
final SearchResult result = searchService.query(fulltextQuery, SingleRepoSearchSource.from(ContextAccessor.current()));
assertEquals(4, result.getNumberOfHits());
final Iterator<String> iterator = result.getIds().iterator();
assertEquals(node4.id(), NodeId.from(iterator.next()));
assertEquals(node3.id(), NodeId.from(iterator.next()));
assertEquals(node2.id(), NodeId.from(iterator.next()));
assertEquals(node1.id(), NodeId.from(iterator.next()));
}
use of com.enonic.xp.repo.impl.search.result.SearchResult in project xp by enonic.
the class BranchServiceImpl method getIgnoreOrder.
private NodeBranchEntries getIgnoreOrder(final NodeIds nodeIds, final InternalContext context) {
if (nodeIds.isEmpty()) {
return NodeBranchEntries.empty();
}
final SearchResult results = this.searchDao.search(SearchRequest.create().query(NodeBranchQuery.create().addQueryFilter(ValueFilter.create().fieldName(BranchIndexPath.BRANCH_NAME.getPath()).addValue(ValueFactory.newString(context.getBranch().getValue())).build()).addQueryFilter(IdFilter.create().fieldName(BranchIndexPath.NODE_ID.getPath()).values(nodeIds).build()).size(nodeIds.getSize()).build()).returnFields(BRANCH_RETURN_FIELDS).searchSource(new SingleRepoStorageSource(context.getRepositoryId(), SingleRepoStorageSource.Type.BRANCH)).searchPreference(context.getSearchPreference()).build());
final NodeBranchQueryResult nodeBranchEntries = NodeBranchQueryResultFactory.create(results);
return NodeBranchEntries.from(nodeBranchEntries.getList());
}
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());
}
Aggregations