use of com.enonic.xp.node.FindNodesByQueryResult in project xp by enonic.
the class FindNodesByQueryCommandTest_func_fulltext method fulltext_fuzzy_2.
@Test
public void fulltext_fuzzy_2() 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());
final PropertyTree data2 = new PropertyTree();
data2.addString("title", "fisk");
final Node node2 = createNode(CreateNodeParams.create().name("my-node-2").parent(NodePath.ROOT).data(data2).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 fsik~2"), ValueExpr.string("OR"))))).build();
final FindNodesByQueryResult result = doFindByQuery(query);
assertEquals(2, result.getNodeIds().getSize());
assertTrue(result.getNodeIds().contains(node.id()));
assertTrue(result.getNodeIds().contains(node2.id()));
}
use of com.enonic.xp.node.FindNodesByQueryResult in project xp by enonic.
the class FindNodesByQueryCommandTest_func_fulltext method fulltext.
@Test
public void fulltext() throws Exception {
final Node node = createNode(CreateNodeParams.create().name("my-node-1").parent(NodePath.ROOT).indexConfigDocument(PatternIndexConfigDocument.create().analyzer(NodeConstants.DOCUMENT_INDEX_DEFAULT_ANALYZER).defaultConfig(IndexConfig.BY_TYPE).build()).build());
final NodeQuery query = NodeQuery.create().query(QueryExpr.from(new DynamicConstraintExpr(FunctionExpr.from("fulltext", ValueExpr.string(NodeIndexPath.NAME.getPath()), ValueExpr.string("My node name is my-node-1"), ValueExpr.string("OR"))))).build();
final FindNodesByQueryResult result = doFindByQuery(query);
assertEquals(1, result.getNodeIds().getSize());
assertTrue(result.getNodeIds().contains(node.id()));
}
use of com.enonic.xp.node.FindNodesByQueryResult in project xp by enonic.
the class FindNodesByQueryCommandTest_func_fulltext 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()));
}
use of com.enonic.xp.node.FindNodesByQueryResult in project xp by enonic.
the class FindNodesByQueryCommandTest method get_by_parent.
@Test
public void get_by_parent() throws Exception {
final Node node1 = createNode(CreateNodeParams.create().name("my-node-1").parent(NodePath.ROOT).build());
final Node node2 = createNode(CreateNodeParams.create().name("my-node-2").parent(NodePath.ROOT).build());
final Node childNode1 = createNode(CreateNodeParams.create().name("child-node").parent(node1.path()).build());
refresh();
final NodeQuery query = NodeQuery.create().parent(NodePath.ROOT).build();
FindNodesByQueryResult result = doFindByQuery(query);
assertEquals(2, result.getNodeIds().getSize());
final NodeQuery childQuery = NodeQuery.create().parent(node1.path()).build();
result = doFindByQuery(childQuery);
assertEquals(1, result.getNodeIds().getSize());
}
use of com.enonic.xp.node.FindNodesByQueryResult in project xp by enonic.
the class FindNodesByQueryCommandTest_acl method fulltext_with_acl.
@Test
public void fulltext_with_acl() throws Exception {
final Node node = createNode(CreateNodeParams.create().name("node_with_access").parent(NodePath.ROOT).indexConfigDocument(PatternIndexConfigDocument.create().analyzer(NodeConstants.DOCUMENT_INDEX_DEFAULT_ANALYZER).defaultConfig(IndexConfig.BY_TYPE).build()).build());
final Node nodeNodeAccess = createNode(CreateNodeParams.create().name("my-node-2").parent(NodePath.ROOT).permissions(denyReadForPrincipal(TEST_DEFAULT_USER.getKey())).indexConfigDocument(PatternIndexConfigDocument.create().analyzer(NodeConstants.DOCUMENT_INDEX_DEFAULT_ANALYZER).defaultConfig(IndexConfig.BY_TYPE).build()).build());
final NodeQuery query = NodeQuery.create().query(QueryExpr.from(new DynamicConstraintExpr(FunctionExpr.from("fulltext", ValueExpr.string(NodeIndexPath.NAME.getPath()), ValueExpr.string("My node name is my-node-1"), ValueExpr.string("OR"))))).build();
final FindNodesByQueryResult resultWithTestUser = doFindByQuery(query);
assertEquals(1L, resultWithTestUser.getTotalHits());
assertTrue(resultWithTestUser.getNodeIds().contains(node.id()));
final FindNodesByQueryResult resultAsAdmin = NodeHelper.runAsAdmin(() -> doFindByQuery(query));
assertEquals(2L, resultAsAdmin.getTotalHits());
assertTrue(resultAsAdmin.getNodeIds().contains(node.id()));
assertTrue(resultAsAdmin.getNodeIds().contains(nodeNodeAccess.id()));
}
Aggregations