Search in sources :

Example 11 with FindContentIdsByQueryResult

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

the class ContentServiceImplTest_create_path_integrity_test method create.

@Test
public void create() {
    final int concurrentAttempts = 5;
    final int expectedSuccessfulAttempts = 1;
    final AtomicInteger exceptionCounter = new AtomicInteger();
    CompletableFuture.allOf(IntStream.range(0, concurrentAttempts).mapToObj(i -> CompletableFuture.runAsync(new CreateContentTask(this.contentService, ContextAccessor.current())).exceptionally(throwable -> {
        exceptionCounter.incrementAndGet();
        return null;
    })).toArray(CompletableFuture[]::new)).join();
    final FindContentIdsByQueryResult result = this.contentService.find(ContentQuery.create().queryExpr(QueryParser.parse("_path = '/content/mycontent'")).build());
    assertEquals(expectedSuccessfulAttempts, result.getTotalHits());
}
Also used : IntStream(java.util.stream.IntStream) CreateContentParams(com.enonic.xp.content.CreateContentParams) ContentService(com.enonic.xp.content.ContentService) QueryParser(com.enonic.xp.query.parser.QueryParser) ContentPath(com.enonic.xp.content.ContentPath) FindContentIdsByQueryResult(com.enonic.xp.content.FindContentIdsByQueryResult) CompletableFuture(java.util.concurrent.CompletableFuture) ContentTypeName(com.enonic.xp.schema.content.ContentTypeName) Test(org.junit.jupiter.api.Test) ContentQuery(com.enonic.xp.content.ContentQuery) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ContextAccessor(com.enonic.xp.context.ContextAccessor) Context(com.enonic.xp.context.Context) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) PropertyTree(com.enonic.xp.data.PropertyTree) FindContentIdsByQueryResult(com.enonic.xp.content.FindContentIdsByQueryResult) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.jupiter.api.Test)

Example 12 with FindContentIdsByQueryResult

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

the class ContentServiceImpl method find.

@Override
public FindContentIdsByQueryResult find(final ContentQuery query) {
    final Trace trace = Tracer.newTrace("content.find");
    if (trace == null) {
        return doFind(query);
    }
    return Tracer.trace(trace, () -> {
        trace.put("query", query.getQueryExpr() != null ? query.getQueryExpr().toString() : "");
        trace.put("from", query.getFrom());
        trace.put("size", query.getSize());
        final FindContentIdsByQueryResult result = doFind(query);
        trace.put("hits", result.getTotalHits());
        return result;
    });
}
Also used : Trace(com.enonic.xp.trace.Trace) FindContentIdsByQueryResult(com.enonic.xp.content.FindContentIdsByQueryResult)

Example 13 with FindContentIdsByQueryResult

use of com.enonic.xp.content.FindContentIdsByQueryResult 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)

Example 14 with FindContentIdsByQueryResult

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

the class QueryContentHandlerTest method queryEmpty.

@Test
public void queryEmpty() throws Exception {
    final FindContentIdsByQueryResult findResult = FindContentIdsByQueryResult.create().hits(0).totalHits(0).contents(ContentIds.empty()).aggregations(Aggregations.empty()).highlight(Map.of()).build();
    Mockito.when(this.contentService.find(Mockito.isA(ContentQuery.class))).thenReturn(findResult);
    Mockito.when(this.contentService.getByIds(Mockito.isA(GetContentByIdsParams.class))).thenReturn(Contents.empty());
    runFunction("/test/QueryContentHandlerTest.js", "queryEmpty");
}
Also used : FindContentIdsByQueryResult(com.enonic.xp.content.FindContentIdsByQueryResult) GetContentByIdsParams(com.enonic.xp.content.GetContentByIdsParams) ContentQuery(com.enonic.xp.content.ContentQuery) Test(org.junit.jupiter.api.Test)

Example 15 with FindContentIdsByQueryResult

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

the class QueryContentHandlerTest method setupQuery.

private void setupQuery(final int count, final boolean aggs, final boolean addHighlight) {
    final Contents contents = TestDataFixtures.newContents(count);
    final Instant t1 = Instant.parse("2014-09-01T00:00:00.00Z");
    final Instant t2 = Instant.parse("2014-10-01T00:00:00.00Z");
    final Instant t3 = Instant.parse("2014-11-01T00:00:00.00Z");
    final Buckets buckets1 = Buckets.create().add(Bucket.create().key("male").docCount(10).build()).add(Bucket.create().key("female").docCount(12).build()).build();
    final Buckets buckets2 = Buckets.create().add(Bucket.create().key("2014-01").docCount(8).build()).add(Bucket.create().key("2014-02").docCount(10).build()).add(Bucket.create().key("2014-03").docCount(12).build()).build();
    final Buckets buckets3 = Buckets.create().add(NumericRangeBucket.create().key("a").docCount(2).to(50).build()).add(NumericRangeBucket.create().key("b").docCount(4).from(50).to(100).build()).add(NumericRangeBucket.create().key("c").docCount(4).from(100).build()).build();
    final Buckets buckets4 = Buckets.create().add(DateRangeBucket.create().from(t1).docCount(2).key("date range bucket key").build()).add(DateRangeBucket.create().to(t1).from(t2).docCount(5).build()).add(DateRangeBucket.create().to(t3).docCount(7).build()).build();
    final BucketAggregation aggr1 = BucketAggregation.bucketAggregation("genders").buckets(buckets1).build();
    final BucketAggregation aggr2 = BucketAggregation.bucketAggregation("by_month").buckets(buckets2).build();
    final BucketAggregation aggr3 = BucketAggregation.bucketAggregation("price_ranges").buckets(buckets3).build();
    final BucketAggregation aggr4 = BucketAggregation.bucketAggregation("my_date_range").buckets(buckets4).build();
    final StatsAggregation aggr5 = StatsAggregation.create("item_count").avg(3).max(5).min(1).sum(15).count(5).build();
    final Aggregations aggregations = Aggregations.from(aggr1, aggr2, aggr3, aggr4, aggr5);
    final Map<ContentId, HighlightedProperties> highlight = Map.of(ContentId.from("123"), HighlightedProperties.create().add(HighlightedProperty.create().name("property1").addFragment("fragment1_1").addFragment("fragment1_2").build()).build(), ContentId.from("456"), HighlightedProperties.create().add(HighlightedProperty.create().name("property2").addFragment("fragment2_1").addFragment("fragment2_2").build()).build());
    final FindContentIdsByQueryResult findResult = FindContentIdsByQueryResult.create().hits(contents.getSize()).totalHits(20).contents(contents.getIds()).aggregations(aggs ? aggregations : null).highlight(addHighlight ? highlight : null).build();
    Mockito.when(this.contentService.find(Mockito.isA(ContentQuery.class))).thenReturn(findResult);
    Mockito.when(this.contentService.getByIds(Mockito.isA(GetContentByIdsParams.class))).thenReturn(contents);
}
Also used : FindContentIdsByQueryResult(com.enonic.xp.content.FindContentIdsByQueryResult) Contents(com.enonic.xp.content.Contents) GetContentByIdsParams(com.enonic.xp.content.GetContentByIdsParams) ContentQuery(com.enonic.xp.content.ContentQuery) Aggregations(com.enonic.xp.aggregation.Aggregations) HighlightedProperties(com.enonic.xp.highlight.HighlightedProperties) Instant(java.time.Instant) ContentId(com.enonic.xp.content.ContentId) StatsAggregation(com.enonic.xp.aggregation.StatsAggregation) BucketAggregation(com.enonic.xp.aggregation.BucketAggregation) Buckets(com.enonic.xp.aggregation.Buckets)

Aggregations

FindContentIdsByQueryResult (com.enonic.xp.content.FindContentIdsByQueryResult)17 ContentQuery (com.enonic.xp.content.ContentQuery)13 Test (org.junit.jupiter.api.Test)12 Content (com.enonic.xp.content.Content)8 PropertyTree (com.enonic.xp.data.PropertyTree)5 GetContentByIdsParams (com.enonic.xp.content.GetContentByIdsParams)4 ReprocessContentRequestJson (com.enonic.xp.impl.server.rest.model.ReprocessContentRequestJson)4 AbstractRunnableTaskTest (com.enonic.xp.task.AbstractRunnableTaskTest)4 RunnableTask (com.enonic.xp.task.RunnableTask)4 ContentDependencies (com.enonic.xp.content.ContentDependencies)3 ContentDependenciesAggregation (com.enonic.xp.content.ContentDependenciesAggregation)3 Contents (com.enonic.xp.content.Contents)3 GetContentTypeParams (com.enonic.xp.schema.content.GetContentTypeParams)3 BucketAggregation (com.enonic.xp.aggregation.BucketAggregation)2 Buckets (com.enonic.xp.aggregation.Buckets)2 Aggregations (com.enonic.xp.aggregation.Aggregations)1 StatsAggregation (com.enonic.xp.aggregation.StatsAggregation)1 ContentId (com.enonic.xp.content.ContentId)1 ContentPath (com.enonic.xp.content.ContentPath)1 ContentService (com.enonic.xp.content.ContentService)1