use of com.enonic.xp.content.FindContentByQueryResult in project xp by enonic.
the class FindContentByQueryCommand method execute.
FindContentByQueryResult execute() {
final NodeQuery nodeQuery = ContentQueryNodeQueryTranslator.translate(this.params.getContentQuery()).addQueryFilters(createFilters()).build();
final FindNodesByQueryResult result = nodeService.findByQuery(nodeQuery);
final NodeIds nodeIds = result.getNodeIds();
final Map<ContentId, HighlightedProperties> highlight = result.getNodeHits().stream().filter(nodeHit -> nodeHit.getHighlight() != null && nodeHit.getHighlight().size() > 0).collect(Collectors.toMap(hit -> ContentId.from(hit.getNodeId().toString()), NodeHit::getHighlight));
final Nodes foundNodes = this.nodeService.getByIds(nodeIds);
Contents contents = this.translator.fromNodes(foundNodes, true);
return FindContentByQueryResult.create().contents(contents).aggregations(result.getAggregations()).hits(result.getHits()).totalHits(result.getTotalHits()).highlight(highlight).build();
}
use of com.enonic.xp.content.FindContentByQueryResult in project xp by enonic.
the class ContentServiceImplTest_find method test_published_draft.
@Test
public void test_published_draft() throws Exception {
final FindContentByQueryResult result = createAndFindContent(ContentPublishInfo.create().from(Instant.now().minus(Duration.ofDays(1))).to(Instant.now().plus(Duration.ofDays(1))).build());
assertEquals(1, result.getTotalHits());
}
use of com.enonic.xp.content.FindContentByQueryResult in project xp by enonic.
the class ContentServiceImplTest_find method test_pending_publish_draft.
@Test
public void test_pending_publish_draft() throws Exception {
final FindContentByQueryResult result = createAndFindContent(ContentPublishInfo.create().from(Instant.now().plus(Duration.ofDays(1))).build());
assertEquals(1, result.getTotalHits());
}
use of com.enonic.xp.content.FindContentByQueryResult in project xp by enonic.
the class ContentServiceImplTest_find method dsl_like_query.
@Test
public void dsl_like_query() 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 PropertyTree request = new PropertyTree();
final PropertySet fulltext = new PropertySet();
fulltext.addString("field", "displayName");
fulltext.addString("value", "*d");
request.addSet("like", fulltext);
final ContentQuery queryDsl = ContentQuery.create().queryExpr(QueryExpr.from(DslExpr.from(request))).build();
final FindContentByQueryResult result = contentService.find(FindContentByQueryParams.create().contentQuery(queryDsl).build());
assertOrder(result, child3);
}
use of com.enonic.xp.content.FindContentByQueryResult in project xp by enonic.
the class ContentServiceImplTest_find method test_pending_publish_master.
@Test
public void test_pending_publish_master() throws Exception {
authorizedMasterContext().callWith(() -> {
final FindContentByQueryResult result = createAndFindContent(ContentPublishInfo.create().from(Instant.now().plus(Duration.ofDays(1))).build());
assertEquals(0, result.getTotalHits());
return null;
});
}
Aggregations