Search in sources :

Example 16 with SearchResult

use of com.enonic.xp.repo.impl.search.result.SearchResult in project xp by enonic.

the class ReorderChildNodeCommand method doMoveLast.

private Node doMoveLast() {
    final SearchResult result = findLastNodeBeforeInsert(Long.MIN_VALUE);
    final Long newOrderValue;
    if (result.isEmpty()) {
        newOrderValue = resoleOnlyNodeOrderValue();
    } else {
        newOrderValue = resolveInsertLastOrderValue(result);
    }
    return doUpdateNodeOrderValue(newOrderValue);
}
Also used : SearchResult(com.enonic.xp.repo.impl.search.result.SearchResult)

Example 17 with SearchResult

use of com.enonic.xp.repo.impl.search.result.SearchResult in project xp by enonic.

the class NodeOrderTest method geo_distance_sorting.

@Test
public void geo_distance_sorting() throws Exception {
    final Node node1 = createNode("node1", ValueFactory.newGeoPoint(GeoPoint.from("80,80")));
    final Node node2 = createNode("node2", ValueFactory.newGeoPoint(GeoPoint.from("81,80")));
    final Node node3 = createNode("node3", ValueFactory.newGeoPoint(GeoPoint.from("82,80")));
    final Node node4 = createNode("node4", ValueFactory.newGeoPoint(GeoPoint.from("83,80")));
    final NodeQuery distanceQuery = NodeQuery.create().query(QueryExpr.from(null, new DynamicOrderExpr(FunctionExpr.from("geoDistance", ValueExpr.string("my-value"), ValueExpr.geoPoint("83,80")), OrderExpr.Direction.ASC))).build();
    final SearchResult result = searchService.query(distanceQuery, SingleRepoSearchSource.from(ContextAccessor.current()));
    final Iterator<String> iterator = result.getIds().iterator();
    assertEquals(node4.id(), NodeId.from(iterator.next()));
    assertEquals(node3.id(), NodeId.from(iterator.next()));
    assertEquals(node2.id(), NodeId.from(iterator.next()));
    assertEquals(node1.id(), NodeId.from(iterator.next()));
}
Also used : DynamicOrderExpr(com.enonic.xp.query.expr.DynamicOrderExpr) Node(com.enonic.xp.node.Node) NodeQuery(com.enonic.xp.node.NodeQuery) SearchResult(com.enonic.xp.repo.impl.search.result.SearchResult) Test(org.junit.jupiter.api.Test)

Aggregations

SearchResult (com.enonic.xp.repo.impl.search.result.SearchResult)17 Node (com.enonic.xp.node.Node)6 NodeQuery (com.enonic.xp.node.NodeQuery)5 NodeIds (com.enonic.xp.node.NodeIds)3 ContextAccessor (com.enonic.xp.context.ContextAccessor)2 ChildOrder (com.enonic.xp.index.ChildOrder)2 NodeBranchEntry (com.enonic.xp.node.NodeBranchEntry)2 NodeId (com.enonic.xp.node.NodeId)2 NodeIndexPath (com.enonic.xp.node.NodeIndexPath)2 NodePath (com.enonic.xp.node.NodePath)2 ExistsFilter (com.enonic.xp.query.filter.ExistsFilter)2 IdFilter (com.enonic.xp.query.filter.IdFilter)2 ReturnFields (com.enonic.xp.repo.impl.ReturnFields)2 ReturnValue (com.enonic.xp.repo.impl.ReturnValue)2 SingleRepoSearchSource (com.enonic.xp.repo.impl.SingleRepoSearchSource)2 NodeBranchQueryResult (com.enonic.xp.repo.impl.branch.search.NodeBranchQueryResult)2 SearchHit (com.enonic.xp.repo.impl.search.result.SearchHit)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 Function (java.util.function.Function)2