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