Search in sources :

Example 41 with FindNodesByQueryResult

use of com.enonic.xp.node.FindNodesByQueryResult in project xp by enonic.

the class FindNodesByQueryCommandTest_order method testByBooleanSorting.

@Test
public void testByBooleanSorting() {
    String[] orders = { FIELD_BOOL + " " + ORDER_DESC };
    FindNodesByQueryResult result = sort(orders);
    Iterator<Node> iterator = getNodes(result.getNodeIds()).iterator();
    assertEquals("node2", iterator.next().name().toString());
    assertEquals("node1", iterator.next().name().toString());
    assertEquals("node3", iterator.next().name().toString());
}
Also used : FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) Node(com.enonic.xp.node.Node) Test(org.junit.jupiter.api.Test)

Example 42 with FindNodesByQueryResult

use of com.enonic.xp.node.FindNodesByQueryResult in project xp by enonic.

the class FindIssueCommentsCommand method execute.

public FindIssueCommentsResult execute() {
    validateBlockingChecks();
    final Node issue = nodeService.getById(NodeId.from(this.query.getIssue()));
    final NodeQuery nodeQuery = IssueCommentQueryNodeQueryTranslator.translate(this.query, issue.name());
    final FindNodesByQueryResult result = nodeService.findByQuery(nodeQuery);
    final Nodes foundNodes = this.nodeService.getByIds(result.getNodeIds());
    final List<IssueComment> issues = IssueCommentNodeTranslator.fromNodes(foundNodes);
    return FindIssueCommentsResult.create().comments(issues).hits(result.getHits()).totalHits(result.getTotalHits()).build();
}
Also used : FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) Node(com.enonic.xp.node.Node) NodeQuery(com.enonic.xp.node.NodeQuery) IssueComment(com.enonic.xp.issue.IssueComment) Nodes(com.enonic.xp.node.Nodes)

Example 43 with FindNodesByQueryResult

use of com.enonic.xp.node.FindNodesByQueryResult in project xp by enonic.

the class FindIssuesCommand method execute.

public FindIssuesResult execute() {
    final NodeQuery nodeQuery = IssueQueryNodeQueryTranslator.translate(this.query);
    final FindNodesByQueryResult result = nodeService.findByQuery(nodeQuery);
    final Nodes foundNodes = this.nodeService.getByIds(result.getNodeIds());
    final List<Issue> issues = IssueNodeTranslator.fromNodes(foundNodes);
    return FindIssuesResult.create().issues(issues).hits(result.getHits()).totalHits(result.getTotalHits()).build();
}
Also used : Issue(com.enonic.xp.issue.Issue) FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) NodeQuery(com.enonic.xp.node.NodeQuery) Nodes(com.enonic.xp.node.Nodes)

Example 44 with FindNodesByQueryResult

use of com.enonic.xp.node.FindNodesByQueryResult in project xp by enonic.

the class FindContentIdsByQueryCommandTest method test.

@Test
public void test() {
    FindNodesByQueryResult nodesByQueryResult = FindNodesByQueryResult.create().addNodeHit(NodeHit.create().nodeId(NodeId.from("nodeId")).score(1.0f).sort(SortValuesProperty.create().values(84).build()).highlight(HighlightedProperties.create().add(HighlightedProperty.create().name("name").addFragment("fragment").build()).build()).build()).hits(1).build();
    Mockito.when(nodeService.findByQuery(Mockito.any(NodeQuery.class))).thenReturn(nodesByQueryResult);
    FindContentIdsByQueryCommand command = FindContentIdsByQueryCommand.create().translator(translator).nodeService(nodeService).contentTypeService(contentTypeService).eventPublisher(eventPublisher).query(ContentQuery.create().queryExpr(QueryExpr.from(null, new DynamicOrderExpr(FunctionExpr.from("geoDistance", ValueExpr.string("my-value"), ValueExpr.geoPoint("83,80"), ValueExpr.string("km")), OrderExpr.Direction.ASC))).build()).build();
    FindContentIdsByQueryResult result = command.execute();
    Assertions.assertFalse(result.getSort().isEmpty());
    Assertions.assertEquals(1, result.getSort().size());
    Assertions.assertEquals(1, result.getScore().size());
}
Also used : FindContentIdsByQueryResult(com.enonic.xp.content.FindContentIdsByQueryResult) FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) DynamicOrderExpr(com.enonic.xp.query.expr.DynamicOrderExpr) NodeQuery(com.enonic.xp.node.NodeQuery) Test(org.junit.jupiter.api.Test)

Example 45 with FindNodesByQueryResult

use of com.enonic.xp.node.FindNodesByQueryResult in project xp by enonic.

the class IndexServiceImplTest method queryForNode.

private Node queryForNode(final NodeId nodeId) {
    final FindNodesByQueryResult result = FindNodesByQueryCommand.create().indexServiceInternal(this.indexServiceInternal).storageService(this.storageService).searchService(this.searchService).query(NodeQuery.create().query(QueryParser.parse("_id = '" + nodeId.toString() + "'")).build()).build().execute();
    final Nodes nodes = getNodes(result.getNodeIds());
    return nodes.getNodeById(nodeId);
}
Also used : FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) Nodes(com.enonic.xp.node.Nodes)

Aggregations

FindNodesByQueryResult (com.enonic.xp.node.FindNodesByQueryResult)84 NodeQuery (com.enonic.xp.node.NodeQuery)61 Test (org.junit.jupiter.api.Test)55 Node (com.enonic.xp.node.Node)32 BucketAggregation (com.enonic.xp.aggregation.BucketAggregation)19 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)19 Bucket (com.enonic.xp.aggregation.Bucket)14 PropertyTree (com.enonic.xp.data.PropertyTree)13 Nodes (com.enonic.xp.node.Nodes)9 DynamicConstraintExpr (com.enonic.xp.query.expr.DynamicConstraintExpr)9 Aggregation (com.enonic.xp.aggregation.Aggregation)8 Buckets (com.enonic.xp.aggregation.Buckets)6 QueryExpr (com.enonic.xp.query.expr.QueryExpr)4 DateRangeBucket (com.enonic.xp.aggregation.DateRangeBucket)3 NodeHit (com.enonic.xp.node.NodeHit)3 CompareExpr (com.enonic.xp.query.expr.CompareExpr)3 NumericRangeBucket (com.enonic.xp.aggregation.NumericRangeBucket)2 SingleValueMetricAggregation (com.enonic.xp.aggregation.SingleValueMetricAggregation)2 ContentId (com.enonic.xp.content.ContentId)2 Context (com.enonic.xp.context.Context)2