Search in sources :

Example 6 with ContentQuery

use of com.enonic.xp.content.ContentQuery in project xp by enonic.

the class ContentServiceImplTest_find method dsl_match_all_query.

@Test
public void dsl_match_all_query() throws Exception {
    final Content site = createContent(ContentPath.ROOT, "a");
    createContent(site.getPath(), "d");
    createContent(site.getPath(), "c");
    createContent(site.getPath(), "b");
    final PropertyTree request = new PropertyTree();
    final PropertySet fulltext = new PropertySet();
    request.addSet("matchAll", fulltext);
    final ContentQuery queryDsl = ContentQuery.create().queryExpr(QueryExpr.from(DslExpr.from(request))).build();
    assertEquals(4, contentService.find(FindContentByQueryParams.create().contentQuery(queryDsl).build()).getTotalHits());
}
Also used : ContentQuery(com.enonic.xp.content.ContentQuery) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) PropertySet(com.enonic.xp.data.PropertySet) Test(org.junit.jupiter.api.Test)

Example 7 with ContentQuery

use of com.enonic.xp.content.ContentQuery in project xp by enonic.

the class ContentServiceImplTest_find method dsl_query_empty.

@Test
public void dsl_query_empty() throws Exception {
    final ContentQuery queryDsl = ContentQuery.create().queryExpr(QueryExpr.from(DslExpr.from(new PropertyTree()))).build();
    assertThrows(IllegalArgumentException.class, () -> contentService.find(FindContentByQueryParams.create().contentQuery(queryDsl).build()));
}
Also used : ContentQuery(com.enonic.xp.content.ContentQuery) PropertyTree(com.enonic.xp.data.PropertyTree) Test(org.junit.jupiter.api.Test)

Example 8 with ContentQuery

use of com.enonic.xp.content.ContentQuery in project xp by enonic.

the class ContentServiceImplTest_find method dsl_like_query.

@Test
public void dsl_like_query() throws Exception {
    final Content site = createContent(ContentPath.ROOT, "a");
    final Content child3 = createContent(site.getPath(), "d");
    final Content child2 = createContent(site.getPath(), "c");
    final Content child1 = createContent(site.getPath(), "b");
    final PropertyTree request = new PropertyTree();
    final PropertySet fulltext = new PropertySet();
    fulltext.addString("field", "displayName");
    fulltext.addString("value", "*d");
    request.addSet("like", fulltext);
    final ContentQuery queryDsl = ContentQuery.create().queryExpr(QueryExpr.from(DslExpr.from(request))).build();
    final FindContentByQueryResult result = contentService.find(FindContentByQueryParams.create().contentQuery(queryDsl).build());
    assertOrder(result, child3);
}
Also used : ContentQuery(com.enonic.xp.content.ContentQuery) Content(com.enonic.xp.content.Content) FindContentByQueryResult(com.enonic.xp.content.FindContentByQueryResult) PropertyTree(com.enonic.xp.data.PropertyTree) PropertySet(com.enonic.xp.data.PropertySet) Test(org.junit.jupiter.api.Test)

Example 9 with ContentQuery

use of com.enonic.xp.content.ContentQuery in project xp by enonic.

the class ContentServiceImplTest_find method dsl_query.

@Test
public void dsl_query() throws Exception {
    final Content site = createContent(ContentPath.ROOT, "a");
    final Content child3 = createContent(site.getPath(), "d");
    final Content child2 = createContent(site.getPath(), "c");
    final Content child1 = createContent(site.getPath(), "b");
    final PropertyTree request = new PropertyTree();
    final PropertySet fulltext = new PropertySet();
    fulltext.addStrings("fields", "displayName");
    fulltext.addString("query", "c");
    request.addSet("fulltext", fulltext);
    final ContentQuery queryDsl = ContentQuery.create().queryExpr(QueryExpr.from(DslExpr.from(request))).build();
    assertOrder(contentService.find(FindContentByQueryParams.create().contentQuery(queryDsl).build()), child2);
}
Also used : ContentQuery(com.enonic.xp.content.ContentQuery) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) PropertySet(com.enonic.xp.data.PropertySet) Test(org.junit.jupiter.api.Test)

Example 10 with ContentQuery

use of com.enonic.xp.content.ContentQuery in project xp by enonic.

the class ContentServiceImplTest_find method dsl_query_sort.

@Test
public void dsl_query_sort() throws Exception {
    final Content site = createContent(ContentPath.ROOT, "a");
    final Content child3 = createContent(site.getPath(), "d");
    final Content child2 = createContent(site.getPath(), "c");
    final Content child1 = createContent(site.getPath(), "b");
    final PropertyTree request = new PropertyTree();
    final PropertySet like = new PropertySet();
    request.addSet("like", like);
    like.addString("field", "_path");
    like.addString("value", "*a/*");
    PropertyTree order = new PropertyTree();
    order.addString("field", "displayName");
    order.addString("direction", "DESC");
    ContentQuery queryDsl = ContentQuery.create().queryExpr(QueryExpr.from(DslExpr.from(request), DslOrderExpr.from(order))).build();
    assertOrder(contentService.find(FindContentByQueryParams.create().contentQuery(queryDsl).build()), child3, child2, child1);
    order = new PropertyTree();
    order.addString("field", "displayName");
    queryDsl = ContentQuery.create().queryExpr(QueryExpr.from(DslExpr.from(request), DslOrderExpr.from(order))).build();
    assertOrder(contentService.find(FindContentByQueryParams.create().contentQuery(queryDsl).build()), child1, child2, child3);
}
Also used : ContentQuery(com.enonic.xp.content.ContentQuery) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) PropertySet(com.enonic.xp.data.PropertySet) Test(org.junit.jupiter.api.Test)

Aggregations

ContentQuery (com.enonic.xp.content.ContentQuery)22 Test (org.junit.jupiter.api.Test)18 Content (com.enonic.xp.content.Content)15 PropertyTree (com.enonic.xp.data.PropertyTree)8 PropertySet (com.enonic.xp.data.PropertySet)7 FindContentByQueryResult (com.enonic.xp.content.FindContentByQueryResult)4 DynamicConstraintExpr (com.enonic.xp.query.expr.DynamicConstraintExpr)2 FieldOrderExpr (com.enonic.xp.query.expr.FieldOrderExpr)2 FunctionExpr (com.enonic.xp.query.expr.FunctionExpr)2 OrderExpr (com.enonic.xp.query.expr.OrderExpr)2 ContentIds (com.enonic.xp.content.ContentIds)1 ContentPath (com.enonic.xp.content.ContentPath)1 ReprocessContentResultJson (com.enonic.xp.impl.server.rest.model.ReprocessContentResultJson)1 GeoDistanceAggregationQuery (com.enonic.xp.query.aggregation.GeoDistanceAggregationQuery)1 ConstraintExpr (com.enonic.xp.query.expr.ConstraintExpr)1 BooleanFilter (com.enonic.xp.query.filter.BooleanFilter)1 ExistsFilter (com.enonic.xp.query.filter.ExistsFilter)1 Filter (com.enonic.xp.query.filter.Filter)1 IdFilter (com.enonic.xp.query.filter.IdFilter)1 ValueFilter (com.enonic.xp.query.filter.ValueFilter)1