use of com.enonic.xp.query.expr.FunctionExpr in project xp by enonic.
the class DynamicSortBuilderFactory method create.
public SortBuilder create(final DynamicOrderExpr orderExpr) {
final FunctionExpr function = orderExpr.getFunction();
final String functionName = function.getName();
switch(functionName) {
case "geoDistance":
return GeoDistanceSortFunction.create(orderExpr);
default:
throw new FunctionQueryBuilderException("Not valid sort function: '" + functionName + "'");
}
}
use of com.enonic.xp.query.expr.FunctionExpr in project xp by enonic.
the class GeoDistanceSortFunction method create.
public static SortBuilder create(final DynamicOrderExpr orderExpr) {
final FunctionExpr function = orderExpr.getFunction();
GeoDistanceSortFunctionArguments arguments = new GeoDistanceSortFunctionArguments(function.getArguments());
final String baseFieldName = arguments.getFieldName();
final String queryFieldName = new SearchQueryFieldNameResolver().resolve(baseFieldName, IndexValueType.GEO_POINT);
GeoDistanceSortBuilder builder = new GeoDistanceSortBuilder(queryFieldName).point(arguments.getLatitude(), arguments.getLongitude());
if (orderExpr.getDirection() != null) {
builder.order(SortOrder.valueOf(orderExpr.getDirection().name()));
}
if (arguments.getUnit() != null) {
builder.unit(DistanceUnit.fromString(arguments.getUnit()));
}
return builder;
}
use of com.enonic.xp.query.expr.FunctionExpr in project xp by enonic.
the class FunctionExpressionBuilderTest method test_fulltext.
@Test
public void test_fulltext() {
List<ValueExpr> arguments = List.of(ValueExpr.string("myField"), ValueExpr.string("mySearchString"), ValueExpr.string("OR"));
final QueryBuilder fulltext = FunctionExpressionBuilder.build(new FunctionExpr("fulltext", arguments));
assertTrue(fulltext instanceof SimpleQueryStringBuilder);
}
use of com.enonic.xp.query.expr.FunctionExpr in project xp by enonic.
the class NodeOrderTest method score_sorting.
@Test
public void score_sorting() throws Exception {
final Node node1 = createNode("node1", ValueFactory.newString("denne har en fisk"));
final Node node2 = createNode("node2", ValueFactory.newString("denne har fisk og ost"));
final Node node3 = createNode("node3", ValueFactory.newString("mens denne har både fisk, ost og pølse"));
final Node node4 = createNode("node4", ValueFactory.newString("denne vinner, siden den har alle sammen: fisk, ost, pølse og pai"));
final FunctionExpr fulltextExpression = FunctionExpr.from("fulltext", ValueExpr.string("my-value"), ValueExpr.string("pai fisk pølse ost"), ValueExpr.string("OR"));
final NodeQuery fulltextQuery = NodeQuery.create().query(QueryExpr.from(new DynamicConstraintExpr(fulltextExpression), FieldOrderExpr.create(IndexPath.from("_score"), OrderExpr.Direction.DESC))).build();
printContentRepoIndex();
final SearchResult result = searchService.query(fulltextQuery, SingleRepoSearchSource.from(ContextAccessor.current()));
assertEquals(4, result.getNumberOfHits());
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()));
}
use of com.enonic.xp.query.expr.FunctionExpr 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);
}
Aggregations