use of com.enonic.xp.repo.impl.elasticsearch.query.translator.resolver.SearchQueryFieldNameResolver in project xp by enonic.
the class SortBuilderFactoryTest method createFieldSort.
@Test
public void createFieldSort() {
final Set<OrderExpr> orderExprs = new HashSet<>();
orderExprs.add(new FieldOrderExpr(FieldExpr.from("myField"), OrderExpr.Direction.ASC));
final List<SortBuilder> sortBuilders = new SortQueryBuilderFactory(new SearchQueryFieldNameResolver()).create(orderExprs);
assertEquals(1, sortBuilders.size());
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 SortBuilderFactoryTest method createDslInvalidFunction.
@Test
public void createDslInvalidFunction() {
final PropertyTree geoExpression = new PropertyTree();
geoExpression.addString("type", "unknownFunction");
geoExpression.addString("field", "myGeoPoint");
final DslOrderExpr unknownOrderExpr = DslOrderExpr.from(geoExpression);
assertThrows(IllegalArgumentException.class, () -> new SortQueryBuilderFactory(new SearchQueryFieldNameResolver()).create(List.of(unknownOrderExpr)));
}
use of com.enonic.xp.repo.impl.elasticsearch.query.translator.resolver.SearchQueryFieldNameResolver in project xp by enonic.
the class SortBuilderFactoryTest method createFieldWithoutDirectionSort.
@Test
public void createFieldWithoutDirectionSort() {
final Set<OrderExpr> orderExprs = new HashSet<>();
orderExprs.add(new FieldOrderExpr(FieldExpr.from("myField"), null));
final List<SortBuilder> sortBuilders = new SortQueryBuilderFactory(new SearchQueryFieldNameResolver()).create(orderExprs);
assertEquals(1, sortBuilders.size());
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 SortBuilderFactoryTest method createDsl.
@Test
public void createDsl() {
final PropertyTree geoExpression = new PropertyTree();
geoExpression.addString("type", "geoDistance");
geoExpression.addString("field", "myGeoPoint");
geoExpression.addString("unit", "ft");
geoExpression.addString("direction", "ASC");
final PropertySet location1 = geoExpression.addSet("location");
location1.addDouble("lat", 2.2);
location1.addDouble("lon", 3.3);
final PropertyTree geoExpressionWithoutOptional = new PropertyTree();
geoExpressionWithoutOptional.addString("type", "geoDistance");
geoExpressionWithoutOptional.addString("field", "myGeoPoint");
final PropertySet location2 = geoExpressionWithoutOptional.addSet("location");
location2.addDouble("lat", 2D);
location2.addDouble("lon", 3D);
final PropertyTree fieldExpressionWithDirection = new PropertyTree();
fieldExpressionWithDirection.addString("field", "myField");
fieldExpressionWithDirection.addString("direction", "DESC");
final PropertyTree fieldExpressionWithoutDirection = new PropertyTree();
fieldExpressionWithoutDirection.addString("field", "_name");
final DslOrderExpr geoOrderExpr = DslOrderExpr.from(geoExpression);
final DslOrderExpr geoOrderWithoutOptionalExpr = DslOrderExpr.from(geoExpressionWithoutOptional);
final DslOrderExpr fieldWithDirectionOrderExpr = DslOrderExpr.from(fieldExpressionWithDirection);
final DslOrderExpr fieldWithoutDirectionOrderExpr = DslOrderExpr.from(fieldExpressionWithoutDirection);
final List<SortBuilder> sortBuilders = new SortQueryBuilderFactory(new SearchQueryFieldNameResolver()).create(List.of(geoOrderExpr, geoOrderWithoutOptionalExpr, fieldWithDirectionOrderExpr, fieldWithoutDirectionOrderExpr));
assertEquals(4, sortBuilders.size());
assertTrue(sortBuilders.get(0) instanceof GeoDistanceSortBuilder);
assertTrue(sortBuilders.get(1) instanceof GeoDistanceSortBuilder);
assertTrue(sortBuilders.get(2) instanceof FieldSortBuilder);
assertTrue(sortBuilders.get(3) instanceof FieldSortBuilder);
}
use of com.enonic.xp.repo.impl.elasticsearch.query.translator.resolver.SearchQueryFieldNameResolver in project xp by enonic.
the class LikeExpressionBuilderTest method compareLikeString.
@Test
public void compareLikeString() throws Exception {
final String expected = load("compare_like_string.json");
final QueryBuilder query = LikeExpressionBuilder.build(CompareExpr.like(FieldExpr.from("myField"), ValueExpr.string("myValue")), new SearchQueryFieldNameResolver());
assertEquals(cleanString(expected), cleanString(query.toString()));
}
Aggregations