Search in sources :

Example 1 with ContentQuery

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

the class ContentServiceImplTest_find method dsl_query_geo_point.

@Test
public void dsl_query_geo_point() throws Exception {
    PropertyTree data = createPropertyTreeForAllInputTypes();
    final Content content = this.contentService.create(CreateContentParams.create().type(ContentTypeName.folder()).contentData(data).name("myContent").parent(ContentPath.ROOT).displayName("my display-name").build());
    final Content child2 = createContent(ContentPath.ROOT, "c");
    final PropertyTree request = new PropertyTree();
    final PropertySet fulltext = request.addSet("term");
    fulltext.addString("field", "data.geoPoint");
    fulltext.addString("value", "59.91273,10.74609");
    final ContentQuery queryDsl = ContentQuery.create().queryExpr(QueryExpr.from(DslExpr.from(request))).build();
    assertEquals(1, contentService.find(FindContentByQueryParams.create().contentQuery(queryDsl).build()).getHits());
}
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 2 with ContentQuery

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

the class ContentServiceImplTest_find method dsl_query_range.

@Test
public void dsl_query_range() 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)

Example 3 with ContentQuery

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

the class ContentServiceImplTest_find method dsl_query_two_root_properties.

@Test
public void dsl_query_two_root_properties() throws Exception {
    final PropertyTree request = new PropertyTree();
    request.addSet("fulltext", new PropertySet());
    request.addSet("ngram", new PropertySet());
    final ContentQuery queryDsl = ContentQuery.create().queryExpr(QueryExpr.from(DslExpr.from(request))).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) PropertySet(com.enonic.xp.data.PropertySet) Test(org.junit.jupiter.api.Test)

Example 4 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)

Example 5 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)

Aggregations

ContentQuery (com.enonic.xp.content.ContentQuery)21 Test (org.junit.jupiter.api.Test)17 Content (com.enonic.xp.content.Content)14 PropertyTree (com.enonic.xp.data.PropertyTree)7 PropertySet (com.enonic.xp.data.PropertySet)6 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