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);
}
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()));
}
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()));
}
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()));
}
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()));
}
Aggregations