Search in sources :

Example 1 with FindContentByQueryResult

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();
}
Also used : NodeHit(com.enonic.xp.node.NodeHit) Nodes(com.enonic.xp.node.Nodes) FindContentByQueryParams(com.enonic.xp.content.FindContentByQueryParams) Collectors(java.util.stream.Collectors) HighlightedProperties(com.enonic.xp.highlight.HighlightedProperties) ContentId(com.enonic.xp.content.ContentId) Contents(com.enonic.xp.content.Contents) Map(java.util.Map) FindContentByQueryResult(com.enonic.xp.content.FindContentByQueryResult) Preconditions(com.google.common.base.Preconditions) NodeQuery(com.enonic.xp.node.NodeQuery) NodeIds(com.enonic.xp.node.NodeIds) FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) Contents(com.enonic.xp.content.Contents) FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) NodeIds(com.enonic.xp.node.NodeIds) HighlightedProperties(com.enonic.xp.highlight.HighlightedProperties) NodeQuery(com.enonic.xp.node.NodeQuery) ContentId(com.enonic.xp.content.ContentId) Nodes(com.enonic.xp.node.Nodes)

Example 2 with FindContentByQueryResult

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());
}
Also used : FindContentByQueryResult(com.enonic.xp.content.FindContentByQueryResult) Test(org.junit.jupiter.api.Test)

Example 3 with FindContentByQueryResult

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());
}
Also used : FindContentByQueryResult(com.enonic.xp.content.FindContentByQueryResult) Test(org.junit.jupiter.api.Test)

Example 4 with FindContentByQueryResult

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);
}
Also used : ContentQuery(com.enonic.xp.content.ContentQuery) Content(com.enonic.xp.content.Content) FindContentByQueryResult(com.enonic.xp.content.FindContentByQueryResult) PropertyTree(com.enonic.xp.data.PropertyTree) PropertySet(com.enonic.xp.data.PropertySet) Test(org.junit.jupiter.api.Test)

Example 5 with FindContentByQueryResult

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;
    });
}
Also used : FindContentByQueryResult(com.enonic.xp.content.FindContentByQueryResult) Test(org.junit.jupiter.api.Test)

Aggregations

FindContentByQueryResult (com.enonic.xp.content.FindContentByQueryResult)11 Test (org.junit.jupiter.api.Test)9 ContentQuery (com.enonic.xp.content.ContentQuery)4 Content (com.enonic.xp.content.Content)3 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 ContentId (com.enonic.xp.content.ContentId)1 ContentIds (com.enonic.xp.content.ContentIds)1 Contents (com.enonic.xp.content.Contents)1 FindContentByQueryParams (com.enonic.xp.content.FindContentByQueryParams)1 PropertySet (com.enonic.xp.data.PropertySet)1 PropertyTree (com.enonic.xp.data.PropertyTree)1 HighlightedProperties (com.enonic.xp.highlight.HighlightedProperties)1 FindNodesByQueryResult (com.enonic.xp.node.FindNodesByQueryResult)1 NodeHit (com.enonic.xp.node.NodeHit)1 NodeIds (com.enonic.xp.node.NodeIds)1 NodeQuery (com.enonic.xp.node.NodeQuery)1 Nodes (com.enonic.xp.node.Nodes)1