Search in sources :

Example 11 with DynamicConstraintExpr

use of com.enonic.xp.query.expr.DynamicConstraintExpr in project xp by enonic.

the class FindNodesByQueryCommandTest_acl method fulltext_with_acl.

@Test
public void fulltext_with_acl() throws Exception {
    final Node node = createNode(CreateNodeParams.create().name("node_with_access").parent(NodePath.ROOT).indexConfigDocument(PatternIndexConfigDocument.create().analyzer(NodeConstants.DOCUMENT_INDEX_DEFAULT_ANALYZER).defaultConfig(IndexConfig.BY_TYPE).build()).build());
    final Node nodeNodeAccess = createNode(CreateNodeParams.create().name("my-node-2").parent(NodePath.ROOT).permissions(denyReadForPrincipal(TEST_DEFAULT_USER.getKey())).indexConfigDocument(PatternIndexConfigDocument.create().analyzer(NodeConstants.DOCUMENT_INDEX_DEFAULT_ANALYZER).defaultConfig(IndexConfig.BY_TYPE).build()).build());
    final NodeQuery query = NodeQuery.create().query(QueryExpr.from(new DynamicConstraintExpr(FunctionExpr.from("fulltext", ValueExpr.string(NodeIndexPath.NAME.getPath()), ValueExpr.string("My node name is my-node-1"), ValueExpr.string("OR"))))).build();
    final FindNodesByQueryResult resultWithTestUser = doFindByQuery(query);
    assertEquals(1L, resultWithTestUser.getTotalHits());
    assertTrue(resultWithTestUser.getNodeIds().contains(node.id()));
    final FindNodesByQueryResult resultAsAdmin = NodeHelper.runAsAdmin(() -> doFindByQuery(query));
    assertEquals(2L, resultAsAdmin.getTotalHits());
    assertTrue(resultAsAdmin.getNodeIds().contains(node.id()));
    assertTrue(resultAsAdmin.getNodeIds().contains(nodeNodeAccess.id()));
}
Also used : DynamicConstraintExpr(com.enonic.xp.query.expr.DynamicConstraintExpr) FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) Node(com.enonic.xp.node.Node) NodeQuery(com.enonic.xp.node.NodeQuery) Test(org.junit.jupiter.api.Test)

Example 12 with DynamicConstraintExpr

use of com.enonic.xp.query.expr.DynamicConstraintExpr in project xp by enonic.

the class ContentServiceImplTest_selectorSearch method fulltext_order.

@Test
public void fulltext_order() throws Exception {
    final Content site1 = createContent(ContentPath.ROOT, "site1");
    final Content third = createContent(site1.getPath(), "Fisk ost");
    final Content second = createContent(site1.getPath(), "Fisk ost ost");
    final Content first = createContent(site1.getPath(), "Fisk ost ost ost");
    final FunctionExpr fulltext = FunctionExpr.from("fulltext", ValueExpr.string("displayName"), ValueExpr.string("ost"));
    final OrderExpr order = FieldOrderExpr.create(IndexPath.from("_score"), OrderExpr.Direction.DESC);
    final ContentQuery query = ContentQuery.create().queryExpr(QueryExpr.from(new DynamicConstraintExpr(fulltext), order)).build();
    final FindContentByQueryResult result = contentService.find(FindContentByQueryParams.create().contentQuery(query).build());
    assertOrder(result, first, second, third);
}
Also used : FunctionExpr(com.enonic.xp.query.expr.FunctionExpr) ContentQuery(com.enonic.xp.content.ContentQuery) DynamicConstraintExpr(com.enonic.xp.query.expr.DynamicConstraintExpr) Content(com.enonic.xp.content.Content) FindContentByQueryResult(com.enonic.xp.content.FindContentByQueryResult) OrderExpr(com.enonic.xp.query.expr.OrderExpr) FieldOrderExpr(com.enonic.xp.query.expr.FieldOrderExpr) Test(org.junit.jupiter.api.Test)

Example 13 with DynamicConstraintExpr

use of com.enonic.xp.query.expr.DynamicConstraintExpr in project xp by enonic.

the class ContentServiceImplTest_selectorSearch method same_site_first.

// Implement path search match first
@Disabled
@Test
public void same_site_first() throws Exception {
    final Content site1 = createContent(ContentPath.ROOT, "site1");
    final Content site2 = createContent(ContentPath.ROOT, "site2");
    final Content third = createContent(site1.getPath(), "Fisk ost");
    final Content second = createContent(site2.getPath(), "Fisk ost");
    final FunctionExpr fulltext = FunctionExpr.from("fulltext", ValueExpr.string("displayName"), ValueExpr.string("ost"));
    final OrderExpr order = FieldOrderExpr.create(IndexPath.from("_score"), OrderExpr.Direction.DESC);
    final ContentQuery query = ContentQuery.create().queryExpr(QueryExpr.from(new DynamicConstraintExpr(fulltext), order)).build();
    final FindContentByQueryResult result = contentService.find(FindContentByQueryParams.create().contentQuery(query).build());
    assertOrder(result, second, third);
}
Also used : FunctionExpr(com.enonic.xp.query.expr.FunctionExpr) ContentQuery(com.enonic.xp.content.ContentQuery) DynamicConstraintExpr(com.enonic.xp.query.expr.DynamicConstraintExpr) Content(com.enonic.xp.content.Content) FindContentByQueryResult(com.enonic.xp.content.FindContentByQueryResult) OrderExpr(com.enonic.xp.query.expr.OrderExpr) FieldOrderExpr(com.enonic.xp.query.expr.FieldOrderExpr) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Aggregations

DynamicConstraintExpr (com.enonic.xp.query.expr.DynamicConstraintExpr)13 Test (org.junit.jupiter.api.Test)12 Node (com.enonic.xp.node.Node)10 NodeQuery (com.enonic.xp.node.NodeQuery)10 FindNodesByQueryResult (com.enonic.xp.node.FindNodesByQueryResult)9 PropertyTree (com.enonic.xp.data.PropertyTree)7 FunctionExpr (com.enonic.xp.query.expr.FunctionExpr)4 Content (com.enonic.xp.content.Content)2 ContentQuery (com.enonic.xp.content.ContentQuery)2 FindContentByQueryResult (com.enonic.xp.content.FindContentByQueryResult)2 PropertySet (com.enonic.xp.data.PropertySet)2 FieldOrderExpr (com.enonic.xp.query.expr.FieldOrderExpr)2 OrderExpr (com.enonic.xp.query.expr.OrderExpr)2 LogicalExpr (com.enonic.xp.query.expr.LogicalExpr)1 QueryExpr (com.enonic.xp.query.expr.QueryExpr)1 SearchResult (com.enonic.xp.repo.impl.search.result.SearchResult)1 Disabled (org.junit.jupiter.api.Disabled)1