Search in sources :

Example 21 with SearchQueryFieldNameResolver

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

the class SortBuilderFactoryTest method createGeoDistanceWithoutDirection.

@Test
public void createGeoDistanceWithoutDirection() {
    final Set<OrderExpr> orderExprs = new HashSet<>();
    orderExprs.add(new DynamicOrderExpr(new FunctionExpr("geoDistance", List.of(ValueExpr.string("myField"), ValueExpr.geoPoint("-50,40"), ValueExpr.string("km"))), null));
    final List<SortBuilder> sortBuilders = new SortQueryBuilderFactory(new SearchQueryFieldNameResolver()).create(orderExprs);
    assertEquals(1, sortBuilders.size());
    assertTrue(sortBuilders.iterator().next() instanceof GeoDistanceSortBuilder);
}
Also used : FieldSortBuilder(org.elasticsearch.search.sort.FieldSortBuilder) GeoDistanceSortBuilder(org.elasticsearch.search.sort.GeoDistanceSortBuilder) SortBuilder(org.elasticsearch.search.sort.SortBuilder) FunctionExpr(com.enonic.xp.query.expr.FunctionExpr) DynamicOrderExpr(com.enonic.xp.query.expr.DynamicOrderExpr) 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) SearchQueryFieldNameResolver(com.enonic.xp.repo.impl.elasticsearch.query.translator.resolver.SearchQueryFieldNameResolver) HashSet(java.util.HashSet) GeoDistanceSortBuilder(org.elasticsearch.search.sort.GeoDistanceSortBuilder) Test(org.junit.jupiter.api.Test)

Example 22 with SearchQueryFieldNameResolver

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

the class SortBuilderFactoryTest method createMultipleFieldSort.

@Test
public void createMultipleFieldSort() {
    final Set<OrderExpr> orderExprs = new HashSet<>();
    orderExprs.add(new FieldOrderExpr(FieldExpr.from("myField"), OrderExpr.Direction.ASC));
    orderExprs.add(new FieldOrderExpr(FieldExpr.from("mySecondField"), OrderExpr.Direction.DESC));
    final List<SortBuilder> sortBuilders = new SortQueryBuilderFactory(new SearchQueryFieldNameResolver()).create(orderExprs);
    assertEquals(2, sortBuilders.size());
    assertTrue(sortBuilders.iterator().next() instanceof FieldSortBuilder);
    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 23 with SearchQueryFieldNameResolver

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

the class QueryBuilderFactoryTest method createQueryWithFilter.

@Test
public void createQueryWithFilter() throws Exception {
    final String expected = load("query_with_queryfilter.json");
    final ValueFilter queryFilter = ValueFilter.create().fieldName("myField").addValue(ValueFactory.newString("myValue1")).addValue(ValueFactory.newString("myValue2")).build();
    final QueryExpr query = QueryParser.parse("not( myField > 1) ");
    final QueryBuilder builtQuery = QueryBuilderFactory.newBuilder().queryExpr(query).addQueryFilter(queryFilter).fieldNameResolver(new SearchQueryFieldNameResolver()).build().create();
    final String expectedJson = cleanString(expected);
    final String actualJson = cleanString(builtQuery.toString());
    assertEquals(expectedJson, actualJson);
}
Also used : QueryExpr(com.enonic.xp.query.expr.QueryExpr) 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 24 with SearchQueryFieldNameResolver

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

the class RangeExpressionBuilderTest method compare_gte_number.

@Test
public void compare_gte_number() throws Exception {
    final String expected = load("compare_gte_number.json");
    final QueryBuilder query = RangeExpressionBuilder.build(CompareExpr.gte(FieldExpr.from("myField"), ValueExpr.number(3L)), 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)

Example 25 with SearchQueryFieldNameResolver

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

the class RangeExpressionBuilderTest method compare_gt_string.

@Test
public void compare_gt_string() throws Exception {
    final String expected = load("compare_gt_string.json");
    final QueryBuilder query = RangeExpressionBuilder.build(CompareExpr.gt(FieldExpr.from("myField"), ValueExpr.string("myString")), 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