use of com.xiaomi.linden.thrift.common.LindenSort in project linden by XiaoMi.
the class BQLCompilerAnalyzer method exitSort_specs.
@Override
public void exitSort_specs(BQLParser.Sort_specsContext ctx) {
LindenSort lindenSort = new LindenSort();
for (BQLParser.Sort_specContext sortCtx : ctx.sort_spec()) {
lindenSort.addToFields((LindenSortField) valProperty.get(sortCtx));
}
valProperty.put(ctx, lindenSort);
}
use of com.xiaomi.linden.thrift.common.LindenSort in project linden by XiaoMi.
the class SortConstructor method constructSort.
public static Sort constructSort(LindenSearchRequest request, IndexSearcher indexSearcher, LindenConfig config) throws IOException {
if (!request.isSetSort())
return null;
LindenSort lindenSort = request.getSort();
SortField[] sortFields = new SortField[lindenSort.getFieldsSize()];
for (int i = 0; i < lindenSort.getFieldsSize(); ++i) {
LindenSortField field = lindenSort.getFields().get(i);
SortField.Type type = SortField.Type.STRING;
boolean isReverse = field.isReverse();
switch(field.getType()) {
case STRING:
type = SortField.Type.STRING;
break;
case DOUBLE:
type = SortField.Type.DOUBLE;
break;
case FLOAT:
type = SortField.Type.FLOAT;
break;
case INTEGER:
type = SortField.Type.INT;
break;
case LONG:
type = SortField.Type.LONG;
break;
case SCORE:
type = SortField.Type.SCORE;
isReverse = !isReverse;
break;
case DISTANCE:
if (request.isSetSpatialParam()) {
Point point = SpatialContext.GEO.makePoint(request.getSpatialParam().getCoordinate().getLongitude(), request.getSpatialParam().getCoordinate().getLatitude());
ValueSource valueSource = config.getSpatialStrategy().makeDistanceValueSource(point, DistanceUtils.DEG_TO_KM);
sortFields[i] = valueSource.getSortField(false).rewrite(indexSearcher);
}
continue;
}
sortFields[i] = new SortField(field.getName(), type, isReverse);
}
return new Sort(sortFields);
}
Aggregations