Search in sources :

Example 1 with DslOrderExpr

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)));
}
Also used : PropertyTree(com.enonic.xp.data.PropertyTree) DslOrderExpr(com.enonic.xp.query.expr.DslOrderExpr) SearchQueryFieldNameResolver(com.enonic.xp.repo.impl.elasticsearch.query.translator.resolver.SearchQueryFieldNameResolver) Test(org.junit.jupiter.api.Test)

Example 2 with DslOrderExpr

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);
}
Also used : FieldSortBuilder(org.elasticsearch.search.sort.FieldSortBuilder) GeoDistanceSortBuilder(org.elasticsearch.search.sort.GeoDistanceSortBuilder) SortBuilder(org.elasticsearch.search.sort.SortBuilder) PropertyTree(com.enonic.xp.data.PropertyTree) PropertySet(com.enonic.xp.data.PropertySet) DslOrderExpr(com.enonic.xp.query.expr.DslOrderExpr) FieldSortBuilder(org.elasticsearch.search.sort.FieldSortBuilder) SearchQueryFieldNameResolver(com.enonic.xp.repo.impl.elasticsearch.query.translator.resolver.SearchQueryFieldNameResolver) GeoDistanceSortBuilder(org.elasticsearch.search.sort.GeoDistanceSortBuilder) Test(org.junit.jupiter.api.Test)

Aggregations

PropertyTree (com.enonic.xp.data.PropertyTree)2 DslOrderExpr (com.enonic.xp.query.expr.DslOrderExpr)2 SearchQueryFieldNameResolver (com.enonic.xp.repo.impl.elasticsearch.query.translator.resolver.SearchQueryFieldNameResolver)2 Test (org.junit.jupiter.api.Test)2 PropertySet (com.enonic.xp.data.PropertySet)1 FieldSortBuilder (org.elasticsearch.search.sort.FieldSortBuilder)1 GeoDistanceSortBuilder (org.elasticsearch.search.sort.GeoDistanceSortBuilder)1 SortBuilder (org.elasticsearch.search.sort.SortBuilder)1