Search in sources :

Example 11 with NodeQuery

use of com.enonic.xp.node.NodeQuery in project xp by enonic.

the class FindNodePathsByQueryTest method queryAndExpect.

private void queryAndExpect(final String queryString, final NodePaths expected) {
    final NodeQuery query = NodeQuery.create().query(QueryParser.parse(queryString)).withPath(true).build();
    final FindNodesByQueryResult result = this.nodeService.findByQuery(query);
    assertEquals(expected, NodePaths.from(result.getNodeHits().stream().map(NodeHit::getNodePath).collect(Collectors.toSet())));
}
Also used : FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) NodeQuery(com.enonic.xp.node.NodeQuery)

Example 12 with NodeQuery

use of com.enonic.xp.node.NodeQuery in project xp by enonic.

the class FindNodesByMultiRepoQueryCommandTest method multi_repo_search_different_branches.

@Test
public void multi_repo_search_different_branches() throws Exception {
    final Repository repo1 = createRepo(REPO_USER_1, "repo1");
    final Repository repo2 = createRepo(REPO_USER_2, "repo2");
    // Create new branch in repo1
    final Branch otherBranch = callInContext(REPO_USER_1, repo1.getId(), MASTER_BRANCH, () -> createBranch("otherBranch"));
    final Node repo1MasterNode1 = callInContext(REPO_USER_1, repo1.getId(), MASTER_BRANCH, () -> createNode(NodePath.ROOT, "repo1Node"));
    final Node repo1OtherNode1 = callInContext(REPO_USER_1, repo1.getId(), otherBranch, () -> createNode(NodePath.ROOT, "repo1Node"));
    final Node repo2MasterNode1 = callInContext(REPO_USER_2, repo2.getId(), MASTER_BRANCH, () -> createNode(NodePath.ROOT, "repo2Node"));
    final SearchTargets targets = SearchTargets.create().add(createTarget(otherBranch, REPO_USER_1, repo1.getId())).add(createTarget(MASTER_BRANCH, REPO_USER_2, repo2.getId())).build();
    final NodeQuery query = NodeQuery.create().parent(NodePath.ROOT).build();
    final FindNodesByMultiRepoQueryResult result = doQuery(query, targets);
    assertEquals(2L, result.getTotalHits());
    assertRepos(result, repo1.getId(), repo2.getId());
    assertBranches(result, MASTER_BRANCH, otherBranch);
    assertNodes(result, repo1OtherNode1.id(), repo2MasterNode1.id());
}
Also used : FindNodesByMultiRepoQueryResult(com.enonic.xp.node.FindNodesByMultiRepoQueryResult) Repository(com.enonic.xp.repository.Repository) Branch(com.enonic.xp.branch.Branch) Node(com.enonic.xp.node.Node) MultiRepoNodeQuery(com.enonic.xp.node.MultiRepoNodeQuery) NodeQuery(com.enonic.xp.node.NodeQuery) SearchTargets(com.enonic.xp.node.SearchTargets) Test(org.junit.jupiter.api.Test)

Example 13 with NodeQuery

use of com.enonic.xp.node.NodeQuery in project xp by enonic.

the class FindNodesByMultiRepoQueryCommandTest method multi_repo_search.

@Test
public void multi_repo_search() throws Exception {
    final Repository repo1 = createRepo(REPO_USER_1, "repo1");
    final Repository repo2 = createRepo(REPO_USER_2, "repo2");
    runInContext(REPO_USER_1, repo1.getId(), () -> createNode(NodePath.ROOT, "repo1Node"));
    runInContext(REPO_USER_2, repo2.getId(), () -> createNode(NodePath.ROOT, "repo2Node"));
    final SearchTargets targets = SearchTargets.create().add(createTarget(MASTER_BRANCH, REPO_USER_1, repo1.getId())).add(createTarget(MASTER_BRANCH, REPO_USER_2, repo2.getId())).build();
    final NodeQuery query = NodeQuery.create().parent(NodePath.ROOT).build();
    final FindNodesByMultiRepoQueryResult result = doQuery(query, targets);
    assertEquals(2L, result.getTotalHits());
    assertRepos(result, repo1.getId(), repo2.getId());
    assertBranches(result, MASTER_BRANCH);
}
Also used : FindNodesByMultiRepoQueryResult(com.enonic.xp.node.FindNodesByMultiRepoQueryResult) Repository(com.enonic.xp.repository.Repository) MultiRepoNodeQuery(com.enonic.xp.node.MultiRepoNodeQuery) NodeQuery(com.enonic.xp.node.NodeQuery) SearchTargets(com.enonic.xp.node.SearchTargets) Test(org.junit.jupiter.api.Test)

Example 14 with NodeQuery

use of com.enonic.xp.node.NodeQuery in project xp by enonic.

the class FindNodesByMultiRepoQueryCommandTest method multi_repo_search_different_branches_same_repo.

@Test
public void multi_repo_search_different_branches_same_repo() throws Exception {
    final Repository repo1 = createRepo(REPO_USER_1, "repo1");
    final Repository repo2 = createRepo(REPO_USER_2, "repo2");
    // Create new branch in repo1
    final Branch otherBranch = callInContext(REPO_USER_1, repo1.getId(), MASTER_BRANCH, () -> createBranch("otherBranch"));
    final Node repo1MasterNode1 = callInContext(REPO_USER_1, repo1.getId(), MASTER_BRANCH, () -> createNode(NodePath.ROOT, "repo1Node"));
    final Node repo1OtherNode1 = callInContext(REPO_USER_1, repo1.getId(), otherBranch, () -> createNode(NodePath.ROOT, "repo1Node"));
    final Node repo2MasterNode1 = callInContext(REPO_USER_2, repo2.getId(), MASTER_BRANCH, () -> createNode(NodePath.ROOT, "repo2Node"));
    final SearchTargets targets = SearchTargets.create().add(createTarget(otherBranch, REPO_USER_1, repo1.getId())).add(createTarget(MASTER_BRANCH, REPO_USER_1, repo1.getId())).add(createTarget(MASTER_BRANCH, REPO_USER_2, repo2.getId())).build();
    final NodeQuery query = NodeQuery.create().parent(NodePath.ROOT).build();
    final FindNodesByMultiRepoQueryResult result = doQuery(query, targets);
    assertEquals(3L, result.getTotalHits());
    assertRepos(result, repo1.getId(), repo2.getId());
    assertBranches(result, MASTER_BRANCH, otherBranch);
    assertNodes(result, repo1OtherNode1.id(), repo1MasterNode1.id(), repo2MasterNode1.id());
}
Also used : FindNodesByMultiRepoQueryResult(com.enonic.xp.node.FindNodesByMultiRepoQueryResult) Repository(com.enonic.xp.repository.Repository) Branch(com.enonic.xp.branch.Branch) Node(com.enonic.xp.node.Node) MultiRepoNodeQuery(com.enonic.xp.node.MultiRepoNodeQuery) NodeQuery(com.enonic.xp.node.NodeQuery) SearchTargets(com.enonic.xp.node.SearchTargets) Test(org.junit.jupiter.api.Test)

Example 15 with NodeQuery

use of com.enonic.xp.node.NodeQuery in project xp by enonic.

the class FindNodesByQueryCommandTest_func_range method queryAndAssert.

private void queryAndAssert(final int exptected, final String queryString) {
    final NodeQuery query = NodeQuery.create().query(QueryParser.parse(queryString)).build();
    final FindNodesByQueryResult result = doFindByQuery(query);
    assertEquals(exptected, result.getNodeIds().getSize());
}
Also used : FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) NodeQuery(com.enonic.xp.node.NodeQuery)

Aggregations

NodeQuery (com.enonic.xp.node.NodeQuery)73 FindNodesByQueryResult (com.enonic.xp.node.FindNodesByQueryResult)58 Test (org.junit.jupiter.api.Test)44 Node (com.enonic.xp.node.Node)24 BucketAggregation (com.enonic.xp.aggregation.BucketAggregation)18 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)18 Bucket (com.enonic.xp.aggregation.Bucket)14 PropertyTree (com.enonic.xp.data.PropertyTree)11 DynamicConstraintExpr (com.enonic.xp.query.expr.DynamicConstraintExpr)10 Aggregation (com.enonic.xp.aggregation.Aggregation)7 Buckets (com.enonic.xp.aggregation.Buckets)6 FindNodesByMultiRepoQueryResult (com.enonic.xp.node.FindNodesByMultiRepoQueryResult)6 MultiRepoNodeQuery (com.enonic.xp.node.MultiRepoNodeQuery)6 Nodes (com.enonic.xp.node.Nodes)5 SearchTargets (com.enonic.xp.node.SearchTargets)5 Repository (com.enonic.xp.repository.Repository)5 DateRangeBucket (com.enonic.xp.aggregation.DateRangeBucket)3 ContentId (com.enonic.xp.content.ContentId)3 PrincipalKey (com.enonic.xp.security.PrincipalKey)3 NumericRangeBucket (com.enonic.xp.aggregation.NumericRangeBucket)2