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