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());
}
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()));
}
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);
}
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);
}
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);
}
Aggregations