use of com.enonic.xp.query.expr.DslOrderExpr 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.query.expr.DslOrderExpr 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);
}
Aggregations