Search in sources :

Example 6 with DynamicConstraintExpr

use of com.enonic.xp.query.expr.DynamicConstraintExpr 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 7 with DynamicConstraintExpr

use of com.enonic.xp.query.expr.DynamicConstraintExpr in project xp by enonic.

the class FindNodesByQueryCommandTest_func_fulltext method negate.

@Test
public void negate() throws Exception {
    final PropertyTree data = new PropertyTree();
    data.addString("title", "fisk kake");
    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 båt");
    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());
    final NodeQuery query = NodeQuery.create().query(QueryExpr.from(new DynamicConstraintExpr(FunctionExpr.from("fulltext", ValueExpr.string("title"), ValueExpr.string("fisk -båt"), 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 8 with DynamicConstraintExpr

use of com.enonic.xp.query.expr.DynamicConstraintExpr in project xp by enonic.

the class FindNodesByQueryCommandTest_func_fulltext method fulltext_norwegian_characters_check_asciifolding.

@Test
public void fulltext_norwegian_characters_check_asciifolding() 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("ae"), 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("o a"), 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 9 with DynamicConstraintExpr

use of com.enonic.xp.query.expr.DynamicConstraintExpr 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()));
}
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 10 with DynamicConstraintExpr

use of com.enonic.xp.query.expr.DynamicConstraintExpr 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()));
}
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