Search in sources :

Example 1 with ContentTypeNames

use of com.enonic.xp.schema.content.ContentTypeNames in project xp by enonic.

the class ContentQueryNodeQueryTranslator method processContentTypesNames.

private static void processContentTypesNames(final ContentQuery contentQuery, final NodeQuery.Builder builder) {
    final ContentTypeNames contentTypeNames = contentQuery.getContentTypes();
    if (contentTypeNames != null && contentTypeNames.isNotEmpty()) {
        final ValueFilter.Builder contentTypeFilterBuilder = ValueFilter.create().fieldName(ContentPropertyNames.TYPE).setCache(true);
        for (final ContentTypeName contentTypeName : contentTypeNames) {
            contentTypeFilterBuilder.addValue(ValueFactory.newString(contentTypeName.toString()));
        }
        builder.addQueryFilter(contentTypeFilterBuilder.build());
    }
}
Also used : ContentTypeName(com.enonic.xp.schema.content.ContentTypeName) ContentTypeNames(com.enonic.xp.schema.content.ContentTypeNames) ValueFilter(com.enonic.xp.query.filter.ValueFilter)

Example 2 with ContentTypeNames

use of com.enonic.xp.schema.content.ContentTypeNames in project xp by enonic.

the class QueryContentHandler method doExecute.

@Override
protected Object doExecute() {
    final int start = valueOrDefault(this.start, 0);
    final int count = valueOrDefault(this.count, GetChildContentHandler.DEFAULT_COUNT);
    final ContentTypeNames contentTypeNames = getContentTypeNames();
    final QueryExpr queryExpr = QueryExpr.from(buildConstraintExpr(), buildOrderExpr());
    final Filters filters = JsonToFilterMapper.create(this.filters);
    final Set<AggregationQuery> aggregations = new QueryAggregationParams().getAggregations(this.aggregations);
    final HighlightQuery highlight = new QueryHighlightParams().getHighlightQuery(this.highlight);
    final ContentQuery.Builder queryBuilder = ContentQuery.create().from(start).size(count).aggregationQueries(aggregations).highlight(highlight).addContentTypeNames(contentTypeNames).queryExpr(queryExpr);
    for (final Filter filter : filters) {
        queryBuilder.queryFilter(filter);
    }
    final FindContentIdsByQueryResult queryResult = contentService.find(queryBuilder.build());
    return convert(queryResult);
}
Also used : AggregationQuery(com.enonic.xp.query.aggregation.AggregationQuery) FindContentIdsByQueryResult(com.enonic.xp.content.FindContentIdsByQueryResult) QueryExpr(com.enonic.xp.query.expr.QueryExpr) Filters(com.enonic.xp.query.filter.Filters) ContentQuery(com.enonic.xp.content.ContentQuery) Filter(com.enonic.xp.query.filter.Filter) ContentTypeNames(com.enonic.xp.schema.content.ContentTypeNames) HighlightQuery(com.enonic.xp.query.highlight.HighlightQuery)

Aggregations

ContentTypeNames (com.enonic.xp.schema.content.ContentTypeNames)2 ContentQuery (com.enonic.xp.content.ContentQuery)1 FindContentIdsByQueryResult (com.enonic.xp.content.FindContentIdsByQueryResult)1 AggregationQuery (com.enonic.xp.query.aggregation.AggregationQuery)1 QueryExpr (com.enonic.xp.query.expr.QueryExpr)1 Filter (com.enonic.xp.query.filter.Filter)1 Filters (com.enonic.xp.query.filter.Filters)1 ValueFilter (com.enonic.xp.query.filter.ValueFilter)1 HighlightQuery (com.enonic.xp.query.highlight.HighlightQuery)1 ContentTypeName (com.enonic.xp.schema.content.ContentTypeName)1