Search in sources :

Example 76 with FindNodesByQueryResult

use of com.enonic.xp.node.FindNodesByQueryResult in project xp by enonic.

the class FindNodesByQueryCommandTest_acl method queryAndAssert.

private void queryAndAssert(final String path1, final String value1, final Node node1) {
    final NodeQuery query = NodeQuery.create().query(QueryExpr.from(CompareExpr.eq(FieldExpr.from(path1), ValueExpr.string(value1)))).build();
    final FindNodesByQueryResult result = doFindByQuery(query);
    assertEquals(1, result.getNodeIds().getSize());
    assertTrue(result.getNodeIds().contains(node1.id()));
}
Also used : FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) NodeQuery(com.enonic.xp.node.NodeQuery)

Example 77 with FindNodesByQueryResult

use of com.enonic.xp.node.FindNodesByQueryResult in project xp by enonic.

the class FindNodesByQueryCommandTest_compare method compare_exists.

@Test
public void compare_exists() throws Exception {
    final PropertyTree data = new PropertyTree();
    data.addString("myCategory", "article");
    final Node node1 = createNode(CreateNodeParams.create().name("my-node-1").parent(NodePath.ROOT).data(data).build());
    final PropertyTree data2 = new PropertyTree();
    data2.addString("myCategory", "document");
    createNode(CreateNodeParams.create().name("my-node-2").parent(NodePath.ROOT).data(data2).build());
    createNode(CreateNodeParams.create().name("child-node").parent(node1.path()).build());
    printContentRepoIndex();
    final FindNodesByQueryResult result = doQuery("myCategory LIKE '*' AND NOT myCategory = 'article'");
    assertEquals(1, result.getHits());
}
Also used : FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) PropertyTree(com.enonic.xp.data.PropertyTree) Node(com.enonic.xp.node.Node) Test(org.junit.jupiter.api.Test)

Example 78 with FindNodesByQueryResult

use of com.enonic.xp.node.FindNodesByQueryResult in project xp by enonic.

the class FindNodesByQueryCommandTest_order_geoDistance method order_by_geoDistance.

@Test
public void order_by_geoDistance() throws Exception {
    createGeoLocations();
    final FindNodesByQueryResult result = doQuery("_parentPath = '/' ORDER BY geoDistance('myLocation', '" + OSLO.getLatitude() + "," + OSLO.getLongitude() + "')");
    assertOrder(result);
}
Also used : FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) Test(org.junit.jupiter.api.Test)

Example 79 with FindNodesByQueryResult

use of com.enonic.xp.node.FindNodesByQueryResult in project xp by enonic.

the class FindNodesByQueryCommandTest_order method testByLongAndBooleanSorting.

@Test
public void testByLongAndBooleanSorting() {
    String[] orders = { FIELD_LONG + " " + ORDER_DESC, FIELD_BOOL + " " + ORDER_DESC };
    FindNodesByQueryResult result = sort(orders);
    Iterator<Node> iterator = getNodes(result.getNodeIds()).iterator();
    assertEquals("node2", iterator.next().name().toString());
    assertEquals("node3", iterator.next().name().toString());
    assertEquals("node1", iterator.next().name().toString());
}
Also used : FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) Node(com.enonic.xp.node.Node) Test(org.junit.jupiter.api.Test)

Example 80 with FindNodesByQueryResult

use of com.enonic.xp.node.FindNodesByQueryResult in project xp by enonic.

the class FindNodesByQueryCommandTest_order method testByLongAndStringAndBooleanSorting.

@Test
public void testByLongAndStringAndBooleanSorting() {
    String[] orders = { FIELD_LONG + " " + ORDER_DESC, FIELD_STRING + " " + ORDER_DESC, FIELD_BOOL + " " + ORDER_ASC };
    FindNodesByQueryResult result = sort(orders);
    Iterator<Node> iterator = getNodes(result.getNodeIds()).iterator();
    assertEquals("node2", iterator.next().name().toString());
    assertEquals("node3", iterator.next().name().toString());
    assertEquals("node1", iterator.next().name().toString());
}
Also used : FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) Node(com.enonic.xp.node.Node) 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