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());
}
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());
}
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();
}
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());
}
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()));
}
Aggregations