use of com.enonic.xp.query.expr.DynamicOrderExpr in project xp by enonic.
the class FindContentIdsByQueryCommandTest method test.
@Test
public void test() {
FindNodesByQueryResult nodesByQueryResult = FindNodesByQueryResult.create().addNodeHit(NodeHit.create().nodeId(NodeId.from("nodeId")).score(1.0f).sort(SortValuesProperty.create().values(84).build()).highlight(HighlightedProperties.create().add(HighlightedProperty.create().name("name").addFragment("fragment").build()).build()).build()).hits(1).build();
Mockito.when(nodeService.findByQuery(Mockito.any(NodeQuery.class))).thenReturn(nodesByQueryResult);
FindContentIdsByQueryCommand command = FindContentIdsByQueryCommand.create().translator(translator).nodeService(nodeService).contentTypeService(contentTypeService).eventPublisher(eventPublisher).query(ContentQuery.create().queryExpr(QueryExpr.from(null, new DynamicOrderExpr(FunctionExpr.from("geoDistance", ValueExpr.string("my-value"), ValueExpr.geoPoint("83,80"), ValueExpr.string("km")), OrderExpr.Direction.ASC))).build()).build();
FindContentIdsByQueryResult result = command.execute();
Assertions.assertFalse(result.getSort().isEmpty());
Assertions.assertEquals(1, result.getSort().size());
Assertions.assertEquals(1, result.getScore().size());
}
use of com.enonic.xp.query.expr.DynamicOrderExpr 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);
}
use of com.enonic.xp.query.expr.DynamicOrderExpr 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);
}
use of com.enonic.xp.query.expr.DynamicOrderExpr 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()));
}
Aggregations