Search in sources :

Example 6 with SearchResult

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;
}
Also used : ExcludeEntry(com.enonic.xp.repo.impl.version.search.ExcludeEntry) Node(com.enonic.xp.node.Node) SearchResult(com.enonic.xp.repo.impl.search.result.SearchResult)

Example 7 with SearchResult

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();
    }
}
Also used : QueryExpr(com.enonic.xp.query.expr.QueryExpr) NodeIds(com.enonic.xp.node.NodeIds) Node(com.enonic.xp.node.Node) SearchResult(com.enonic.xp.repo.impl.search.result.SearchResult)

Example 8 with SearchResult

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()));
}
Also used : FunctionExpr(com.enonic.xp.query.expr.FunctionExpr) DynamicConstraintExpr(com.enonic.xp.query.expr.DynamicConstraintExpr) Node(com.enonic.xp.node.Node) NodeQuery(com.enonic.xp.node.NodeQuery) SearchResult(com.enonic.xp.repo.impl.search.result.SearchResult) Test(org.junit.jupiter.api.Test)

Example 9 with SearchResult

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());
}
Also used : SingleRepoStorageSource(com.enonic.xp.repo.impl.SingleRepoStorageSource) NodeBranchQueryResult(com.enonic.xp.repo.impl.branch.search.NodeBranchQueryResult) SearchResult(com.enonic.xp.repo.impl.search.result.SearchResult)

Example 10 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)

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