use of com.yahoo.search.query.Sorting.LowerCaseSorter in project vespa by vespa-engine.
the class YqlParser method fetchSorting.
@NonNull
private OperatorNode<?> fetchSorting(OperatorNode<?> ast) {
if (ast.getOperator() != SequenceOperator.SORT)
return ast;
List<FieldOrder> sortingInit = new ArrayList<>();
List<OperatorNode<?>> sortArguments = ast.getArgument(1);
for (OperatorNode<?> op : sortArguments) {
OperatorNode<ExpressionOperator> fieldNode = op.<OperatorNode<ExpressionOperator>>getArgument(0);
String field = fetchFieldRead(fieldNode);
String locale = getAnnotation(fieldNode, SORTING_LOCALE, String.class, null, "locale used by sorting function");
String function = getAnnotation(fieldNode, SORTING_FUNCTION, String.class, null, "sorting function for the specified attribute");
String strength = getAnnotation(fieldNode, SORTING_STRENGTH, String.class, null, "strength for sorting function");
AttributeSorter sorter;
if (function == null) {
sorter = new AttributeSorter(field);
} else if (Sorting.LOWERCASE.equals(function)) {
sorter = new LowerCaseSorter(field);
} else if (Sorting.RAW.equals(function)) {
sorter = new RawSorter(field);
} else if (Sorting.UCA.equals(function)) {
if (locale != null) {
UcaSorter.Strength ucaStrength = UcaSorter.Strength.UNDEFINED;
if (strength != null) {
if (Sorting.STRENGTH_PRIMARY.equalsIgnoreCase(strength)) {
ucaStrength = UcaSorter.Strength.PRIMARY;
} else if (Sorting.STRENGTH_SECONDARY.equalsIgnoreCase(strength)) {
ucaStrength = UcaSorter.Strength.SECONDARY;
} else if (Sorting.STRENGTH_TERTIARY.equalsIgnoreCase(strength)) {
ucaStrength = UcaSorter.Strength.TERTIARY;
} else if (Sorting.STRENGTH_QUATERNARY.equalsIgnoreCase(strength)) {
ucaStrength = UcaSorter.Strength.QUATERNARY;
} else if (Sorting.STRENGTH_IDENTICAL.equalsIgnoreCase(strength)) {
ucaStrength = UcaSorter.Strength.IDENTICAL;
} else {
throw newUnexpectedArgumentException(function, Sorting.STRENGTH_PRIMARY, Sorting.STRENGTH_SECONDARY, Sorting.STRENGTH_TERTIARY, Sorting.STRENGTH_QUATERNARY, Sorting.STRENGTH_IDENTICAL);
}
sorter = new UcaSorter(field, locale, ucaStrength);
} else {
sorter = new UcaSorter(field, locale, ucaStrength);
}
} else {
sorter = new UcaSorter(field);
}
} else {
throw newUnexpectedArgumentException(function, "lowercase", "raw", "uca");
}
switch((SortOperator) op.getOperator()) {
case ASC:
sortingInit.add(new FieldOrder(sorter, Order.ASCENDING));
break;
case DESC:
sortingInit.add(new FieldOrder(sorter, Order.DESCENDING));
break;
default:
throw newUnexpectedArgumentException(op.getOperator(), SortOperator.ASC, SortOperator.DESC);
}
}
sorting = new Sorting(sortingInit);
return ast.getArgument(0);
}
Aggregations