use of com.enonic.xp.content.ContentQuery in project xp by enonic.
the class ContentServiceImplTest_findContentPaths method empty.
@Test
public void empty() throws Exception {
final ContentQuery query = ContentQuery.create().queryExpr(QueryParser.parse("")).build();
assertEquals(ContentPaths.empty(), contentService.findContentPaths(query));
}
use of com.enonic.xp.content.ContentQuery in project xp by enonic.
the class ContentServiceImplTest_find method order_by_path.
@Test
public void order_by_path() 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 ContentQuery queryOrderAsc = ContentQuery.create().queryExpr(QueryParser.parse("order by _path asc")).build();
assertOrder(contentService.find(FindContentByQueryParams.create().contentQuery(queryOrderAsc).build()), site, child1, child2, child3);
assertOrder(contentService.find(queryOrderAsc).getContentIds(), site, child1, child2, child3);
final ContentQuery queryOrderDesc = ContentQuery.create().queryExpr(QueryParser.parse("order by _path desc")).build();
assertOrder(contentService.find(FindContentByQueryParams.create().contentQuery(queryOrderDesc).build()), child3, child2, child1, site);
assertOrder(contentService.find(queryOrderDesc).getContentIds(), child3, child2, child1, site);
}
use of com.enonic.xp.content.ContentQuery in project xp by enonic.
the class CheckContentValidityCommand method execute.
public ContentValidityResult execute() {
if (this.contentIds.getSize() == 0) {
return ContentValidityResult.empty();
}
// valid == false
final Filter notValid = ValueFilter.create().fieldName(ContentPropertyNames.VALID).addValue(ValueFactory.newBoolean(false)).build();
// workflow != null && workflow != READY
final Filter notReady = BooleanFilter.create().must(ExistsFilter.create().fieldName(WORKFLOW_STATE_FIELD).build()).mustNot(ValueFilter.create().fieldName(WORKFLOW_STATE_FIELD).addValues(WorkflowState.READY.toString()).build()).build();
// valid == false OR (workflow != null && workflow != READY)
final Filter filter = BooleanFilter.create().should(notValid).should(notReady).build();
final ContentQuery query = ContentQuery.create().queryFilter(filter).queryFilter(IdFilter.create().fieldName(ContentIndexPath.ID.getPath()).values(contentIds.asStrings()).build()).size(-1).build();
final FindContentByQueryResult result = FindContentByQueryCommand.create().params(FindContentByQueryParams.create().contentQuery(query).populateChildren(false).build()).contentTypeService(this.contentTypeService).eventPublisher(this.eventPublisher).nodeService(this.nodeService).translator(this.translator).build().execute();
ContentIds.Builder invalidContentIds = ContentIds.create();
ContentIds.Builder notReadyContentIds = ContentIds.create();
result.getContents().forEach(content -> {
if (!content.isValid()) {
invalidContentIds.add(content.getId());
}
if (!content.getWorkflowInfo().getState().equals(WorkflowState.READY)) {
notReadyContentIds.add(content.getId());
}
});
return ContentValidityResult.create().notValidContentIds(invalidContentIds.build()).notReadyContentIds(notReadyContentIds.build()).build();
}
use of com.enonic.xp.content.ContentQuery in project xp by enonic.
the class ContentServiceImplTest_selectorSearch method fulltext_order.
@Test
public void fulltext_order() throws Exception {
final Content site1 = createContent(ContentPath.ROOT, "site1");
final Content third = createContent(site1.getPath(), "Fisk ost");
final Content second = createContent(site1.getPath(), "Fisk ost ost");
final Content first = createContent(site1.getPath(), "Fisk ost ost ost");
final FunctionExpr fulltext = FunctionExpr.from("fulltext", ValueExpr.string("displayName"), ValueExpr.string("ost"));
final OrderExpr order = FieldOrderExpr.create(IndexPath.from("_score"), OrderExpr.Direction.DESC);
final ContentQuery query = ContentQuery.create().queryExpr(QueryExpr.from(new DynamicConstraintExpr(fulltext), order)).build();
final FindContentByQueryResult result = contentService.find(FindContentByQueryParams.create().contentQuery(query).build());
assertOrder(result, first, second, third);
}
use of com.enonic.xp.content.ContentQuery in project xp by enonic.
the class ContentServiceImplTest_selectorSearch method same_site_first.
// Implement path search match first
@Disabled
@Test
public void same_site_first() throws Exception {
final Content site1 = createContent(ContentPath.ROOT, "site1");
final Content site2 = createContent(ContentPath.ROOT, "site2");
final Content third = createContent(site1.getPath(), "Fisk ost");
final Content second = createContent(site2.getPath(), "Fisk ost");
final FunctionExpr fulltext = FunctionExpr.from("fulltext", ValueExpr.string("displayName"), ValueExpr.string("ost"));
final OrderExpr order = FieldOrderExpr.create(IndexPath.from("_score"), OrderExpr.Direction.DESC);
final ContentQuery query = ContentQuery.create().queryExpr(QueryExpr.from(new DynamicConstraintExpr(fulltext), order)).build();
final FindContentByQueryResult result = contentService.find(FindContentByQueryParams.create().contentQuery(query).build());
assertOrder(result, second, third);
}
Aggregations