Search in sources :

Example 1 with SearchQueryFieldNameResolver

use of com.enonic.xp.repo.impl.elasticsearch.query.translator.resolver.SearchQueryFieldNameResolver in project xp by enonic.

the class GeoDistanceSortFunction method create.

public static SortBuilder create(final DynamicOrderExpr orderExpr) {
    final FunctionExpr function = orderExpr.getFunction();
    GeoDistanceSortFunctionArguments arguments = new GeoDistanceSortFunctionArguments(function.getArguments());
    final String baseFieldName = arguments.getFieldName();
    final String queryFieldName = new SearchQueryFieldNameResolver().resolve(baseFieldName, IndexValueType.GEO_POINT);
    GeoDistanceSortBuilder builder = new GeoDistanceSortBuilder(queryFieldName).point(arguments.getLatitude(), arguments.getLongitude());
    if (orderExpr.getDirection() != null) {
        builder.order(SortOrder.valueOf(orderExpr.getDirection().name()));
    }
    if (arguments.getUnit() != null) {
        builder.unit(DistanceUnit.fromString(arguments.getUnit()));
    }
    return builder;
}
Also used : FunctionExpr(com.enonic.xp.query.expr.FunctionExpr) SearchQueryFieldNameResolver(com.enonic.xp.repo.impl.elasticsearch.query.translator.resolver.SearchQueryFieldNameResolver) GeoDistanceSortBuilder(org.elasticsearch.search.sort.GeoDistanceSortBuilder)

Example 2 with SearchQueryFieldNameResolver

use of com.enonic.xp.repo.impl.elasticsearch.query.translator.resolver.SearchQueryFieldNameResolver in project xp by enonic.

the class GeoDistanceSortFunction method create.

public static SortBuilder create(final DslOrderExpr orderExpr) {
    final String queryFieldName = new SearchQueryFieldNameResolver().resolve(orderExpr.getField(), IndexValueType.GEO_POINT);
    final GeoDistanceSortBuilder builder = new GeoDistanceSortBuilder(queryFieldName).point(orderExpr.getLat(), orderExpr.getLon());
    if (orderExpr.getDirection() != null) {
        builder.order(SortOrder.valueOf(orderExpr.getDirection().toString()));
    }
    if (orderExpr.getUnit() != null) {
        builder.unit(DistanceUnit.fromString(orderExpr.getUnit()));
    }
    return builder;
}
Also used : SearchQueryFieldNameResolver(com.enonic.xp.repo.impl.elasticsearch.query.translator.resolver.SearchQueryFieldNameResolver) GeoDistanceSortBuilder(org.elasticsearch.search.sort.GeoDistanceSortBuilder)

Example 3 with SearchQueryFieldNameResolver

use of com.enonic.xp.repo.impl.elasticsearch.query.translator.resolver.SearchQueryFieldNameResolver in project xp by enonic.

the class FilterBuilderFactoryTest method createBooleanFilter.

@Test
public void createBooleanFilter() throws Exception {
    final BooleanFilter.Builder builder = BooleanFilter.create();
    builder.must(ExistsFilter.create().fieldName("MyMust").build());
    builder.must(ExistsFilter.create().fieldName("MyMust").build());
    builder.mustNot(ExistsFilter.create().fieldName("MyMustNot").build());
    builder.should(ExistsFilter.create().fieldName("MyOptional").build());
    builder.should(ExistsFilter.create().fieldName("MyOptional").build());
    builder.should(ExistsFilter.create().fieldName("MyOptional").build());
    final String expected = load("filter_boolean.json");
    final QueryBuilder filterBuilder = new FilterBuilderFactory(new SearchQueryFieldNameResolver()).create(Filters.from(builder.build()));
    assertEquals(cleanString(expected), cleanString(filterBuilder.toString()));
}
Also used : BooleanFilter(com.enonic.xp.query.filter.BooleanFilter) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) SearchQueryFieldNameResolver(com.enonic.xp.repo.impl.elasticsearch.query.translator.resolver.SearchQueryFieldNameResolver) Test(org.junit.jupiter.api.Test)

Example 4 with SearchQueryFieldNameResolver

use of com.enonic.xp.repo.impl.elasticsearch.query.translator.resolver.SearchQueryFieldNameResolver in project xp by enonic.

the class FilterBuilderFactoryTest method createNumberValueFilter.

@Test
public void createNumberValueFilter() throws Exception {
    final ValueFilter queryFilter = ValueFilter.create().fieldName("myField").addValue(ValueFactory.newDouble(1.0)).addValue(ValueFactory.newDouble(2.0)).build();
    final String expected = load("filter_values_number.json");
    final QueryBuilder filterBuilder = new FilterBuilderFactory(new SearchQueryFieldNameResolver()).create(Filters.from(queryFilter));
    assertEquals(cleanString(expected), cleanString(filterBuilder.toString()));
}
Also used : ValueFilter(com.enonic.xp.query.filter.ValueFilter) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) SearchQueryFieldNameResolver(com.enonic.xp.repo.impl.elasticsearch.query.translator.resolver.SearchQueryFieldNameResolver) Test(org.junit.jupiter.api.Test)

Example 5 with SearchQueryFieldNameResolver

use of com.enonic.xp.repo.impl.elasticsearch.query.translator.resolver.SearchQueryFieldNameResolver in project xp by enonic.

the class FilterBuilderFactoryTest method createStringValueFilter.

@Test
public void createStringValueFilter() throws Exception {
    final ValueFilter queryFilter = ValueFilter.create().fieldName("myField").addValue(ValueFactory.newString("myValue1")).addValue(ValueFactory.newString("myValue2")).build();
    final String expected = load("filter_values_string.json");
    final QueryBuilder filterBuilder = new FilterBuilderFactory(new SearchQueryFieldNameResolver()).create(Filters.from(queryFilter));
    assertEquals(cleanString(expected), cleanString(filterBuilder.toString()));
}
Also used : ValueFilter(com.enonic.xp.query.filter.ValueFilter) 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