use of com.enonic.xp.query.expr.DynamicConstraintExpr in project xp by enonic.
the class FindNodesByQueryCommandTest_func_fulltext method fulltext_with_path.
@Test
public void fulltext_with_path() throws Exception {
final PropertyTree data = new PropertyTree();
final String path1 = "Test.Of.String.With.Path";
final String value1 = "fisk ost pølse løk";
data.setString(path1, value1);
final String path2 = "MyString.With.Path2";
final String value2 = "vif rbk lsk sif";
data.setString(path2, value2);
final Node node = createNode(CreateNodeParams.create().name("fisk ost").parent(NodePath.ROOT).data(data).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(path1), ValueExpr.string("leter etter fisk"), 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.query.expr.DynamicConstraintExpr in project xp by enonic.
the class FindNodesByQueryCommandTest_func_fulltext method ascii_folding_with_wildcard.
@Test
public void ascii_folding_with_wildcard() throws Exception {
final PropertyTree data = new PropertyTree();
data.addString("myProperty", "grønnsaker");
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(), true);
final NodeQuery query = NodeQuery.create().query(QueryExpr.from(new DynamicConstraintExpr(FunctionExpr.from("fulltext", ValueExpr.string(NodeIndexPath.ALL_TEXT.getPath()), ValueExpr.string("grønns*"), 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.query.expr.DynamicConstraintExpr in project xp by enonic.
the class FindNodesByQueryCommandTest_func_fulltext method fulltext_norwegian_characters.
@Test
public void fulltext_norwegian_characters() throws Exception {
final PropertyTree data = new PropertyTree();
data.addString("myProperty", "æ");
final PropertySet userdata = data.addSet("data");
userdata.addString("displayName", "ø å");
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();
printContentRepoIndex();
final NodeQuery query = NodeQuery.create().query(QueryExpr.from(new DynamicConstraintExpr(FunctionExpr.from("fulltext", ValueExpr.string(NodeIndexPath.ALL_TEXT.getPath()), ValueExpr.string("æ"), ValueExpr.string("OR"))))).build();
final FindNodesByQueryResult result = doFindByQuery(query);
assertEquals(1, result.getNodeIds().getSize());
assertTrue(result.getNodeIds().contains(node.id()));
final NodeQuery query2 = NodeQuery.create().query(QueryExpr.from(new DynamicConstraintExpr(FunctionExpr.from("fulltext", ValueExpr.string("data.displayName"), ValueExpr.string("ø å"), ValueExpr.string("OR"))))).build();
final FindNodesByQueryResult result2 = doFindByQuery(query2);
assertEquals(1, result2.getNodeIds().getSize());
assertTrue(result.getNodeIds().contains(node.id()));
}
use of com.enonic.xp.query.expr.DynamicConstraintExpr 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()));
}
use of com.enonic.xp.query.expr.DynamicConstraintExpr 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