use of com.enonic.xp.repo.impl.elasticsearch.query.translator.resolver.SearchQueryFieldNameResolver 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.repo.impl.elasticsearch.query.translator.resolver.SearchQueryFieldNameResolver in project xp by enonic.
the class SortBuilderFactoryTest method createMultipleFieldSort.
@Test
public void createMultipleFieldSort() {
final Set<OrderExpr> orderExprs = new HashSet<>();
orderExprs.add(new FieldOrderExpr(FieldExpr.from("myField"), OrderExpr.Direction.ASC));
orderExprs.add(new FieldOrderExpr(FieldExpr.from("mySecondField"), OrderExpr.Direction.DESC));
final List<SortBuilder> sortBuilders = new SortQueryBuilderFactory(new SearchQueryFieldNameResolver()).create(orderExprs);
assertEquals(2, sortBuilders.size());
assertTrue(sortBuilders.iterator().next() instanceof FieldSortBuilder);
assertTrue(sortBuilders.iterator().next() instanceof FieldSortBuilder);
}
use of com.enonic.xp.repo.impl.elasticsearch.query.translator.resolver.SearchQueryFieldNameResolver in project xp by enonic.
the class QueryBuilderFactoryTest method createQueryWithFilter.
@Test
public void createQueryWithFilter() throws Exception {
final String expected = load("query_with_queryfilter.json");
final ValueFilter queryFilter = ValueFilter.create().fieldName("myField").addValue(ValueFactory.newString("myValue1")).addValue(ValueFactory.newString("myValue2")).build();
final QueryExpr query = QueryParser.parse("not( myField > 1) ");
final QueryBuilder builtQuery = QueryBuilderFactory.newBuilder().queryExpr(query).addQueryFilter(queryFilter).fieldNameResolver(new SearchQueryFieldNameResolver()).build().create();
final String expectedJson = cleanString(expected);
final String actualJson = cleanString(builtQuery.toString());
assertEquals(expectedJson, actualJson);
}
use of com.enonic.xp.repo.impl.elasticsearch.query.translator.resolver.SearchQueryFieldNameResolver in project xp by enonic.
the class RangeExpressionBuilderTest method compare_gte_number.
@Test
public void compare_gte_number() throws Exception {
final String expected = load("compare_gte_number.json");
final QueryBuilder query = RangeExpressionBuilder.build(CompareExpr.gte(FieldExpr.from("myField"), ValueExpr.number(3L)), new SearchQueryFieldNameResolver());
assertEquals(cleanString(expected), cleanString(query.toString()));
}
use of com.enonic.xp.repo.impl.elasticsearch.query.translator.resolver.SearchQueryFieldNameResolver in project xp by enonic.
the class RangeExpressionBuilderTest method compare_gt_string.
@Test
public void compare_gt_string() throws Exception {
final String expected = load("compare_gt_string.json");
final QueryBuilder query = RangeExpressionBuilder.build(CompareExpr.gt(FieldExpr.from("myField"), ValueExpr.string("myString")), new SearchQueryFieldNameResolver());
assertEquals(cleanString(expected), cleanString(query.toString()));
}
Aggregations