Search in sources :

Example 61 with NodeQuery

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

the class FindNodesByMultiRepoQueryCommandTest method no_access_in_one_repo_of_three.

@Test
public void no_access_in_one_repo_of_three() throws Exception {
    final Repository repo1 = createRepo(REPO_USER_1, "repo1");
    final Repository repo2 = createRepo(REPO_USER_2, "repo2");
    final Repository repo3 = createRepo(REPO_USER_3, "repo3");
    runInContext(REPO_USER_1, repo1.getId(), () -> createNode(NodePath.ROOT, "repo1Node"));
    runInContext(REPO_USER_2, repo2.getId(), () -> createNode(NodePath.ROOT, "repo2Node"));
    runInContext(REPO_USER_3, repo3.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())).add(// repoUser1 has no access
    createTarget(MASTER_BRANCH, REPO_USER_1, repo3.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 62 with NodeQuery

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

the class FindNodesByQueryCommandTest method query_instant_different_field_name_case.

@Test
public void query_instant_different_field_name_case() throws Exception {
    final Instant BASE_INSTANT = Instant.parse("2000-01-01T00:00:00.00Z");
    final PropertyTree data13 = new PropertyTree();
    data13.addInstant("myProperty", BASE_INSTANT.plus(10, ChronoUnit.DAYS));
    final PropertyTree data2 = new PropertyTree();
    data2.addInstant("myProperty", BASE_INSTANT.plus(20, ChronoUnit.DAYS));
    final Node node1 = createNode(CreateNodeParams.create().name("my-node-1").parent(NodePath.ROOT).data(data13).build());
    final Node node2 = createNode(CreateNodeParams.create().name("my-node-2").parent(NodePath.ROOT).data(data2).build());
    final Node node3 = createNode(CreateNodeParams.create().name("child-node").parent(node1.path()).data(data13).build());
    final Value from = ValueFactory.newDateTime(BASE_INSTANT);
    final Value to = ValueFactory.newDateTime(BASE_INSTANT.plus(15, ChronoUnit.DAYS));
    final QueryExpr queryExpr = QueryExpr.from(CompareExpr.eq(FieldExpr.from("MYProperty"), ValueExpr.instant(BASE_INSTANT.plus(10, ChronoUnit.DAYS).toString())));
    final NodeQuery query = NodeQuery.create().query(queryExpr).addPostFilter(RangeFilter.create().fieldName("MYProperty").from(from).to(to).build()).build();
    final FindNodesByQueryResult result = doFindByQuery(query);
    assertEquals(2, result.getNodeIds().getSize());
    assertTrue(result.getNodeIds().contains(node1.id()));
    assertTrue(result.getNodeIds().contains(node3.id()));
    assertFalse(result.getNodeIds().contains(node2.id()));
}
Also used : QueryExpr(com.enonic.xp.query.expr.QueryExpr) FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) Instant(java.time.Instant) PropertyTree(com.enonic.xp.data.PropertyTree) Node(com.enonic.xp.node.Node) NodeQuery(com.enonic.xp.node.NodeQuery) Value(com.enonic.xp.data.Value) Test(org.junit.jupiter.api.Test)

Example 63 with NodeQuery

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

the class FindNodesByQueryCommandTest method query_number_different_field_name_case.

@Test
public void query_number_different_field_name_case() throws Exception {
    final PropertyTree data13 = new PropertyTree();
    data13.addLong("myProperty", 10L);
    final PropertyTree data2 = new PropertyTree();
    data2.addLong("myProperty", 20L);
    final Node node1 = createNode(CreateNodeParams.create().name("my-node-1").parent(NodePath.ROOT).data(data13).build());
    final Node node2 = createNode(CreateNodeParams.create().name("my-node-2").parent(NodePath.ROOT).data(data2).build());
    final Node node3 = createNode(CreateNodeParams.create().name("child-node").parent(node1.path()).data(data13).build());
    final NodeQuery query = NodeQuery.create().query(QueryExpr.from(CompareExpr.eq(FieldExpr.from("MYProperty"), ValueExpr.number(10L)))).addPostFilter(RangeFilter.create().fieldName("MYProperty").from(ValueFactory.newLong(0L)).to(ValueFactory.newLong(15L)).build()).addAggregationQuery(TermsAggregationQuery.create("categories").fieldName("myCategory").orderDirection(TermsAggregationQuery.Direction.ASC).orderType(TermsAggregationQuery.Type.DOC_COUNT).build()).build();
    final FindNodesByQueryResult result = doFindByQuery(query);
    assertEquals(2, result.getNodeIds().getSize());
    assertTrue(result.getNodeIds().contains(node1.id()));
    assertTrue(result.getNodeIds().contains(node3.id()));
    assertFalse(result.getNodeIds().contains(node2.id()));
}
Also used : FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) PropertyTree(com.enonic.xp.data.PropertyTree) Node(com.enonic.xp.node.Node) NodeQuery(com.enonic.xp.node.NodeQuery) Test(org.junit.jupiter.api.Test)

Example 64 with NodeQuery

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

the class FindNodesByQueryCommandTest_func_fulltext method fulltext_fuzzy.

@Test
public void fulltext_fuzzy() throws Exception {
    final PropertyTree data = new PropertyTree();
    data.addString("title", "Levenshtein");
    final Node node = createNode(CreateNodeParams.create().name("my-node-1").parent(NodePath.ROOT).data(data).indexConfigDocument(PatternIndexConfigDocument.create().analyzer(NodeConstants.DOCUMENT_INDEX_DEFAULT_ANALYZER).defaultConfig(IndexConfig.BY_TYPE).build()).build());
    refresh();
    final NodeQuery query = NodeQuery.create().query(QueryExpr.from(new DynamicConstraintExpr(FunctionExpr.from("fulltext", ValueExpr.string("title"), ValueExpr.string("levvenstein~2"), ValueExpr.string("AND"))))).build();
    final FindNodesByQueryResult result = doFindByQuery(query);
    assertEquals(1, result.getNodeIds().getSize());
    assertTrue(result.getNodeIds().contains(node.id()));
}
Also used : DynamicConstraintExpr(com.enonic.xp.query.expr.DynamicConstraintExpr) FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) PropertyTree(com.enonic.xp.data.PropertyTree) Node(com.enonic.xp.node.Node) NodeQuery(com.enonic.xp.node.NodeQuery) Test(org.junit.jupiter.api.Test)

Example 65 with NodeQuery

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

the class FindNodesByQueryCommandTest_func_ngram method queryAndAssert.

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

Aggregations

NodeQuery (com.enonic.xp.node.NodeQuery)74 FindNodesByQueryResult (com.enonic.xp.node.FindNodesByQueryResult)59 Test (org.junit.jupiter.api.Test)45 Node (com.enonic.xp.node.Node)24 BucketAggregation (com.enonic.xp.aggregation.BucketAggregation)19 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)19 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)8 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 NumericRangeBucket (com.enonic.xp.aggregation.NumericRangeBucket)2 SingleValueMetricAggregation (com.enonic.xp.aggregation.SingleValueMetricAggregation)2