Search in sources :

Example 11 with ContentQuery

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

the class ContentServiceImplTest_find method dsl_query_geo_point.

@Test
public void dsl_query_geo_point() throws Exception {
    PropertyTree data = createPropertyTreeForAllInputTypes();
    final Content content = this.contentService.create(CreateContentParams.create().type(ContentTypeName.folder()).contentData(data).name("myContent").parent(ContentPath.ROOT).displayName("my display-name").build());
    final Content child2 = createContent(ContentPath.ROOT, "c");
    final PropertyTree request = new PropertyTree();
    final PropertySet fulltext = request.addSet("term");
    fulltext.addString("field", "data.geoPoint");
    fulltext.addString("value", "59.91273,10.74609");
    final ContentQuery queryDsl = ContentQuery.create().queryExpr(QueryExpr.from(DslExpr.from(request))).build();
    assertEquals(1, contentService.find(FindContentByQueryParams.create().contentQuery(queryDsl).build()).getHits());
}
Also used : ContentQuery(com.enonic.xp.content.ContentQuery) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) PropertySet(com.enonic.xp.data.PropertySet) Test(org.junit.jupiter.api.Test)

Example 12 with ContentQuery

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

the class ContentQueryTest method testBuilder.

@Test
public void testBuilder() {
    final ContentQuery query = createTestQuery();
    assertNotNull(query);
    assertEquals(10, query.getFrom());
    assertEquals(10, query.getSize());
    assertEquals(3, query.getAggregationQueries().getSize());
    assertEquals(3, query.getContentTypes().getSize());
    assertNotNull(query.getQueryExpr());
    assertEquals(1, query.getQueryFilters().getSize());
    assertNotNull(query.getHighlight());
    assertEquals(Encoder.HTML, query.getHighlight().getSettings().getEncoder());
    assertEquals(Fragmenter.SIMPLE, query.getHighlight().getSettings().getFragmenter());
    assertEquals(1, (int) query.getHighlight().getSettings().getFragmentSize());
    assertEquals(2, (int) query.getHighlight().getSettings().getNoMatchSize());
    assertEquals(3, (int) query.getHighlight().getSettings().getNumOfFragments());
    assertEquals(Order.SCORE, query.getHighlight().getSettings().getOrder());
    assertEquals(List.of("<a>", "<b>"), query.getHighlight().getSettings().getPreTags());
    assertEquals(List.of("<c>", "<d>"), query.getHighlight().getSettings().getPostTags());
    assertEquals(true, query.getHighlight().getSettings().getRequireFieldMatch());
    assertEquals(TagsSchema.STYLED, query.getHighlight().getSettings().getTagsSchema());
}
Also used : ContentQuery(com.enonic.xp.content.ContentQuery) Test(org.junit.jupiter.api.Test)

Example 13 with ContentQuery

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

the class ContentQueryTest method createTestQuery.

private ContentQuery createTestQuery() {
    final GeoDistanceAggregationQuery query1 = GeoDistanceAggregationQuery.create("geo").unit("inch").origin(GeoPoint.from("20,30")).build();
    final GeoDistanceAggregationQuery query2 = GeoDistanceAggregationQuery.create("geo").unit("inch").origin(GeoPoint.from("20,30")).build();
    final GeoDistanceAggregationQuery query3 = GeoDistanceAggregationQuery.create("geo").unit("inch").origin(GeoPoint.from("20,30")).build();
    final HighlightQuery highlightQuery = HighlightQuery.create().property(HighlightQueryProperty.create("propertyToHighlight").build()).settings(HighlightQuerySettings.create().encoder(Encoder.HTML).fragmenter(Fragmenter.SIMPLE).fragmentSize(1).noMatchSize(2).numOfFragments(3).order(Order.SCORE).addPreTags(List.of("<a>", "<b>")).addPostTags(List.of("<c>", "<d>")).requireFieldMatch(true).tagsSchema(TagsSchema.STYLED).build()).build();
    final ContentQuery.Builder builder = ContentQuery.create();
    builder.addContentTypeName(ContentTypeName.imageMedia());
    builder.addContentTypeNames(ContentTypeNames.from(ContentTypeName.archiveMedia(), ContentTypeName.dataMedia()));
    builder.aggregationQuery(query1);
    builder.aggregationQueries(Arrays.asList(query2, query3));
    builder.highlight(highlightQuery);
    builder.from(10);
    builder.size(10);
    builder.queryExpr(QueryExpr.from(CompareExpr.eq(FieldExpr.from("name"), ValueExpr.string("testerson"))));
    builder.queryFilter(RangeFilter.create().from(ValueFactory.newDouble(2.0)).to(ValueFactory.newDouble(10.0)).build());
    return builder.build();
}
Also used : GeoDistanceAggregationQuery(com.enonic.xp.query.aggregation.GeoDistanceAggregationQuery) ContentQuery(com.enonic.xp.content.ContentQuery) HighlightQuery(com.enonic.xp.query.highlight.HighlightQuery)

Example 14 with ContentQuery

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

the class ContentServiceImplTest_find method createAndFindContent.

private FindContentByQueryResult createAndFindContent(final ContentPublishInfo publishInfo) throws Exception {
    final Content content = createContent(ContentPath.ROOT, publishInfo);
    final ContentQuery query = ContentQuery.create().queryExpr(QueryParser.parse("_id='" + content.getId().toString() + "'")).build();
    return contentService.find(FindContentByQueryParams.create().contentQuery(query).build());
}
Also used : ContentQuery(com.enonic.xp.content.ContentQuery) Content(com.enonic.xp.content.Content)

Example 15 with ContentQuery

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

the class ContentServiceImplTest_findContentPaths method multiple_items.

@Test
public void multiple_items() 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");
    ContentQuery query = ContentQuery.create().queryExpr(QueryParser.parse("")).build();
    assertEquals(contentService.findContentPaths(query), ContentPaths.from(site.getPath(), child1.getPath(), child2.getPath(), child3.getPath()));
    query = ContentQuery.create().queryExpr(QueryParser.parse("_path in ('/content" + child1.getPath().asAbsolute() + "', '/content" + child2.getPath().asAbsolute() + "')")).build();
    assertEquals(contentService.findContentPaths(query), ContentPaths.from(child1.getPath(), child2.getPath()));
}
Also used : ContentQuery(com.enonic.xp.content.ContentQuery) Content(com.enonic.xp.content.Content) Test(org.junit.jupiter.api.Test)

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