Search in sources :

Example 1 with FieldOrderExpr

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

the class ReorderChildNodeCommand method createFirstNodeBeforeInsertQuery.

private NodeQuery createFirstNodeBeforeInsertQuery(final Long nodeAfterOrderValue) {
    final CompareExpr orderGreaterThanNodeToMoveBefore = CompareExpr.gt(FieldExpr.from(NodeIndexPath.MANUAL_ORDER_VALUE), ValueExpr.number(nodeAfterOrderValue));
    final CompareExpr parentPathEqualToParent = CompareExpr.eq(FieldExpr.from(NodeIndexPath.PARENT_PATH), ValueExpr.string(parentNode.path().toString()));
    final LogicalExpr constraint = LogicalExpr.and(orderGreaterThanNodeToMoveBefore, parentPathEqualToParent);
    final FieldOrderExpr orderManuallyDesc = FieldOrderExpr.create(NodeIndexPath.MANUAL_ORDER_VALUE, OrderExpr.Direction.ASC);
    return NodeQuery.create().query(QueryExpr.from(constraint, orderManuallyDesc)).size(1).build();
}
Also used : FieldOrderExpr(com.enonic.xp.query.expr.FieldOrderExpr) CompareExpr(com.enonic.xp.query.expr.CompareExpr) LogicalExpr(com.enonic.xp.query.expr.LogicalExpr)

Example 2 with FieldOrderExpr

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

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

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

FieldOrderExpr (com.enonic.xp.query.expr.FieldOrderExpr)4 DslOrderExpr (com.enonic.xp.query.expr.DslOrderExpr)3 DynamicOrderExpr (com.enonic.xp.query.expr.DynamicOrderExpr)3 OrderExpr (com.enonic.xp.query.expr.OrderExpr)3 SearchQueryFieldNameResolver (com.enonic.xp.repo.impl.elasticsearch.query.translator.resolver.SearchQueryFieldNameResolver)3 HashSet (java.util.HashSet)3 FieldSortBuilder (org.elasticsearch.search.sort.FieldSortBuilder)3 GeoDistanceSortBuilder (org.elasticsearch.search.sort.GeoDistanceSortBuilder)3 SortBuilder (org.elasticsearch.search.sort.SortBuilder)3 Test (org.junit.jupiter.api.Test)3 CompareExpr (com.enonic.xp.query.expr.CompareExpr)1 LogicalExpr (com.enonic.xp.query.expr.LogicalExpr)1