Search in sources :

Example 66 with FindNodesByQueryResult

use of com.enonic.xp.node.FindNodesByQueryResult 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()));
}
Also used : 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 67 with FindNodesByQueryResult

use of com.enonic.xp.node.FindNodesByQueryResult 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 68 with FindNodesByQueryResult

use of com.enonic.xp.node.FindNodesByQueryResult 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()));
}
Also used : FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) NodeQuery(com.enonic.xp.node.NodeQuery)

Example 69 with FindNodesByQueryResult

use of com.enonic.xp.node.FindNodesByQueryResult 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 70 with FindNodesByQueryResult

use of com.enonic.xp.node.FindNodesByQueryResult 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)

Aggregations

FindNodesByQueryResult (com.enonic.xp.node.FindNodesByQueryResult)84 NodeQuery (com.enonic.xp.node.NodeQuery)61 Test (org.junit.jupiter.api.Test)55 Node (com.enonic.xp.node.Node)32 BucketAggregation (com.enonic.xp.aggregation.BucketAggregation)19 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)19 Bucket (com.enonic.xp.aggregation.Bucket)14 PropertyTree (com.enonic.xp.data.PropertyTree)13 Nodes (com.enonic.xp.node.Nodes)9 DynamicConstraintExpr (com.enonic.xp.query.expr.DynamicConstraintExpr)9 Aggregation (com.enonic.xp.aggregation.Aggregation)8 Buckets (com.enonic.xp.aggregation.Buckets)6 QueryExpr (com.enonic.xp.query.expr.QueryExpr)4 DateRangeBucket (com.enonic.xp.aggregation.DateRangeBucket)3 NodeHit (com.enonic.xp.node.NodeHit)3 CompareExpr (com.enonic.xp.query.expr.CompareExpr)3 NumericRangeBucket (com.enonic.xp.aggregation.NumericRangeBucket)2 SingleValueMetricAggregation (com.enonic.xp.aggregation.SingleValueMetricAggregation)2 ContentId (com.enonic.xp.content.ContentId)2 Context (com.enonic.xp.context.Context)2