Search in sources :

Example 1 with DynamicConstraintExpr

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()));
}
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 2 with DynamicConstraintExpr

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()));
}
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 3 with DynamicConstraintExpr

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()));
}
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) PropertySet(com.enonic.xp.data.PropertySet) Test(org.junit.jupiter.api.Test)

Example 4 with DynamicConstraintExpr

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()));
}
Also used : FunctionExpr(com.enonic.xp.query.expr.FunctionExpr) DynamicConstraintExpr(com.enonic.xp.query.expr.DynamicConstraintExpr) Node(com.enonic.xp.node.Node) NodeQuery(com.enonic.xp.node.NodeQuery) SearchResult(com.enonic.xp.repo.impl.search.result.SearchResult) Test(org.junit.jupiter.api.Test)

Example 5 with DynamicConstraintExpr

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()));
}
Also used : DynamicConstraintExpr(com.enonic.xp.query.expr.DynamicConstraintExpr) FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) Node(com.enonic.xp.node.Node) NodeQuery(com.enonic.xp.node.NodeQuery) Test(org.junit.jupiter.api.Test)

Aggregations

DynamicConstraintExpr (com.enonic.xp.query.expr.DynamicConstraintExpr)13 Test (org.junit.jupiter.api.Test)12 Node (com.enonic.xp.node.Node)10 NodeQuery (com.enonic.xp.node.NodeQuery)10 FindNodesByQueryResult (com.enonic.xp.node.FindNodesByQueryResult)9 PropertyTree (com.enonic.xp.data.PropertyTree)7 FunctionExpr (com.enonic.xp.query.expr.FunctionExpr)4 Content (com.enonic.xp.content.Content)2 ContentQuery (com.enonic.xp.content.ContentQuery)2 FindContentByQueryResult (com.enonic.xp.content.FindContentByQueryResult)2 PropertySet (com.enonic.xp.data.PropertySet)2 FieldOrderExpr (com.enonic.xp.query.expr.FieldOrderExpr)2 OrderExpr (com.enonic.xp.query.expr.OrderExpr)2 LogicalExpr (com.enonic.xp.query.expr.LogicalExpr)1 QueryExpr (com.enonic.xp.query.expr.QueryExpr)1 SearchResult (com.enonic.xp.repo.impl.search.result.SearchResult)1 Disabled (org.junit.jupiter.api.Disabled)1