Search in sources :

Example 16 with ContentQuery

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));
}
Also used : ContentQuery(com.enonic.xp.content.ContentQuery) Test(org.junit.jupiter.api.Test)

Example 17 with ContentQuery

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);
}
Also used : ContentQuery(com.enonic.xp.content.ContentQuery) Content(com.enonic.xp.content.Content) Test(org.junit.jupiter.api.Test)

Example 18 with ContentQuery

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();
}
Also used : ContentQuery(com.enonic.xp.content.ContentQuery) IdFilter(com.enonic.xp.query.filter.IdFilter) ExistsFilter(com.enonic.xp.query.filter.ExistsFilter) ValueFilter(com.enonic.xp.query.filter.ValueFilter) BooleanFilter(com.enonic.xp.query.filter.BooleanFilter) Filter(com.enonic.xp.query.filter.Filter) FindContentByQueryResult(com.enonic.xp.content.FindContentByQueryResult) ContentIds(com.enonic.xp.content.ContentIds)

Example 19 with ContentQuery

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);
}
Also used : FunctionExpr(com.enonic.xp.query.expr.FunctionExpr) ContentQuery(com.enonic.xp.content.ContentQuery) DynamicConstraintExpr(com.enonic.xp.query.expr.DynamicConstraintExpr) Content(com.enonic.xp.content.Content) FindContentByQueryResult(com.enonic.xp.content.FindContentByQueryResult) OrderExpr(com.enonic.xp.query.expr.OrderExpr) FieldOrderExpr(com.enonic.xp.query.expr.FieldOrderExpr) Test(org.junit.jupiter.api.Test)

Example 20 with ContentQuery

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);
}
Also used : FunctionExpr(com.enonic.xp.query.expr.FunctionExpr) ContentQuery(com.enonic.xp.content.ContentQuery) DynamicConstraintExpr(com.enonic.xp.query.expr.DynamicConstraintExpr) Content(com.enonic.xp.content.Content) FindContentByQueryResult(com.enonic.xp.content.FindContentByQueryResult) OrderExpr(com.enonic.xp.query.expr.OrderExpr) FieldOrderExpr(com.enonic.xp.query.expr.FieldOrderExpr) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

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