Search in sources :

Example 6 with SearchQueryFieldNameResolver

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

Example 7 with SearchQueryFieldNameResolver

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)));
}
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 8 with SearchQueryFieldNameResolver

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

Example 9 with SearchQueryFieldNameResolver

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

Example 10 with SearchQueryFieldNameResolver

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

Aggregations

SearchQueryFieldNameResolver (com.enonic.xp.repo.impl.elasticsearch.query.translator.resolver.SearchQueryFieldNameResolver)28 Test (org.junit.jupiter.api.Test)24 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)18 GeoDistanceSortBuilder (org.elasticsearch.search.sort.GeoDistanceSortBuilder)8 DslOrderExpr (com.enonic.xp.query.expr.DslOrderExpr)7 FieldSortBuilder (org.elasticsearch.search.sort.FieldSortBuilder)6 SortBuilder (org.elasticsearch.search.sort.SortBuilder)6 DynamicOrderExpr (com.enonic.xp.query.expr.DynamicOrderExpr)5 FieldOrderExpr (com.enonic.xp.query.expr.FieldOrderExpr)5 OrderExpr (com.enonic.xp.query.expr.OrderExpr)5 HashSet (java.util.HashSet)5 FunctionExpr (com.enonic.xp.query.expr.FunctionExpr)3 ValueFilter (com.enonic.xp.query.filter.ValueFilter)3 PropertyTree (com.enonic.xp.data.PropertyTree)2 PropertySet (com.enonic.xp.data.PropertySet)1 CompareExpr (com.enonic.xp.query.expr.CompareExpr)1 QueryExpr (com.enonic.xp.query.expr.QueryExpr)1 BooleanFilter (com.enonic.xp.query.filter.BooleanFilter)1 ExistsFilter (com.enonic.xp.query.filter.ExistsFilter)1 IdFilter (com.enonic.xp.query.filter.IdFilter)1