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