Search in sources :

Example 1 with OrderExpr

use of com.enonic.xp.query.expr.OrderExpr 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 2 with OrderExpr

use of com.enonic.xp.query.expr.OrderExpr 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 3 with OrderExpr

use of com.enonic.xp.query.expr.OrderExpr in project xp by enonic.

the class SortBuilderFactoryTest method createGeoDistance.

@Test
public void createGeoDistance() {
    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"))), OrderExpr.Direction.ASC));
    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 4 with OrderExpr

use of com.enonic.xp.query.expr.OrderExpr 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 5 with OrderExpr

use of com.enonic.xp.query.expr.OrderExpr 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)

Aggregations

OrderExpr (com.enonic.xp.query.expr.OrderExpr)9 FieldOrderExpr (com.enonic.xp.query.expr.FieldOrderExpr)7 Test (org.junit.jupiter.api.Test)7 DslOrderExpr (com.enonic.xp.query.expr.DslOrderExpr)5 DynamicOrderExpr (com.enonic.xp.query.expr.DynamicOrderExpr)5 SearchQueryFieldNameResolver (com.enonic.xp.repo.impl.elasticsearch.query.translator.resolver.SearchQueryFieldNameResolver)5 HashSet (java.util.HashSet)5 FieldSortBuilder (org.elasticsearch.search.sort.FieldSortBuilder)5 GeoDistanceSortBuilder (org.elasticsearch.search.sort.GeoDistanceSortBuilder)5 SortBuilder (org.elasticsearch.search.sort.SortBuilder)5 FunctionExpr (com.enonic.xp.query.expr.FunctionExpr)4 Content (com.enonic.xp.content.Content)2 ContentQuery (com.enonic.xp.content.ContentQuery)2 FindContentByQueryResult (com.enonic.xp.content.FindContentByQueryResult)2 ConstraintExpr (com.enonic.xp.query.expr.ConstraintExpr)2 DynamicConstraintExpr (com.enonic.xp.query.expr.DynamicConstraintExpr)2 QueryExpr (com.enonic.xp.query.expr.QueryExpr)2 NodeQuery (com.enonic.xp.node.NodeQuery)1 UserQuery (com.enonic.xp.security.UserQuery)1 UserQueryResult (com.enonic.xp.security.UserQueryResult)1