Search in sources :

Example 6 with FunctionExpr

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

the class SortBuilderFactoryTest method createGeoDistanceWithoutDirection.

@Test
public void createGeoDistanceWithoutDirection() {
    final Set<OrderExpr> orderExprs = new HashSet<>();
    orderExprs.add(new DynamicOrderExpr(new FunctionExpr("geoDistance", List.of(ValueExpr.string("myField"), ValueExpr.geoPoint("-50,40"), ValueExpr.string("km"))), null));
    final List<SortBuilder> sortBuilders = new SortQueryBuilderFactory(new SearchQueryFieldNameResolver()).create(orderExprs);
    assertEquals(1, sortBuilders.size());
    assertTrue(sortBuilders.iterator().next() instanceof GeoDistanceSortBuilder);
}
Also used : FieldSortBuilder(org.elasticsearch.search.sort.FieldSortBuilder) GeoDistanceSortBuilder(org.elasticsearch.search.sort.GeoDistanceSortBuilder) SortBuilder(org.elasticsearch.search.sort.SortBuilder) FunctionExpr(com.enonic.xp.query.expr.FunctionExpr) DynamicOrderExpr(com.enonic.xp.query.expr.DynamicOrderExpr) OrderExpr(com.enonic.xp.query.expr.OrderExpr) DslOrderExpr(com.enonic.xp.query.expr.DslOrderExpr) FieldOrderExpr(com.enonic.xp.query.expr.FieldOrderExpr) DynamicOrderExpr(com.enonic.xp.query.expr.DynamicOrderExpr) SearchQueryFieldNameResolver(com.enonic.xp.repo.impl.elasticsearch.query.translator.resolver.SearchQueryFieldNameResolver) HashSet(java.util.HashSet) GeoDistanceSortBuilder(org.elasticsearch.search.sort.GeoDistanceSortBuilder) Test(org.junit.jupiter.api.Test)

Example 7 with FunctionExpr

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

the class PrincipalQueryNodeQueryTranslator method getQueryExpression.

private static QueryExpr getQueryExpression(final String query) {
    final String fields = String.join(",", DISPLAY_NAME_KEY, ALL_TEXT_FIELD_NAME);
    final FunctionExpr fullText = FunctionExpr.from("fulltext", ValueExpr.string(fields), ValueExpr.string(query), ValueExpr.string("AND"));
    final FunctionExpr nGram = FunctionExpr.from("ngram", ValueExpr.string(fields), ValueExpr.string(query), ValueExpr.string("AND"));
    final LogicalExpr fullTextOrNgram = LogicalExpr.or(new DynamicConstraintExpr(fullText), new DynamicConstraintExpr(nGram));
    return new QueryExpr(fullTextOrNgram, Collections.emptySet());
}
Also used : FunctionExpr(com.enonic.xp.query.expr.FunctionExpr) DynamicConstraintExpr(com.enonic.xp.query.expr.DynamicConstraintExpr) QueryExpr(com.enonic.xp.query.expr.QueryExpr) LogicalExpr(com.enonic.xp.query.expr.LogicalExpr)

Example 8 with FunctionExpr

use of com.enonic.xp.query.expr.FunctionExpr 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)

Example 9 with FunctionExpr

use of com.enonic.xp.query.expr.FunctionExpr 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)

Aggregations

FunctionExpr (com.enonic.xp.query.expr.FunctionExpr)9 Test (org.junit.jupiter.api.Test)6 DynamicConstraintExpr (com.enonic.xp.query.expr.DynamicConstraintExpr)4 FieldOrderExpr (com.enonic.xp.query.expr.FieldOrderExpr)4 OrderExpr (com.enonic.xp.query.expr.OrderExpr)4 SearchQueryFieldNameResolver (com.enonic.xp.repo.impl.elasticsearch.query.translator.resolver.SearchQueryFieldNameResolver)3 GeoDistanceSortBuilder (org.elasticsearch.search.sort.GeoDistanceSortBuilder)3 Content (com.enonic.xp.content.Content)2 ContentQuery (com.enonic.xp.content.ContentQuery)2 FindContentByQueryResult (com.enonic.xp.content.FindContentByQueryResult)2 DslOrderExpr (com.enonic.xp.query.expr.DslOrderExpr)2 DynamicOrderExpr (com.enonic.xp.query.expr.DynamicOrderExpr)2 HashSet (java.util.HashSet)2 FieldSortBuilder (org.elasticsearch.search.sort.FieldSortBuilder)2 SortBuilder (org.elasticsearch.search.sort.SortBuilder)2 Node (com.enonic.xp.node.Node)1 NodeQuery (com.enonic.xp.node.NodeQuery)1 LogicalExpr (com.enonic.xp.query.expr.LogicalExpr)1 QueryExpr (com.enonic.xp.query.expr.QueryExpr)1 ValueExpr (com.enonic.xp.query.expr.ValueExpr)1