Search in sources :

Example 1 with LindenSort

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);
}
Also used : LindenSort(com.xiaomi.linden.thrift.common.LindenSort)

Example 2 with 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);
}
Also used : LindenSort(com.xiaomi.linden.thrift.common.LindenSort) ValueSource(org.apache.lucene.queries.function.ValueSource) Sort(org.apache.lucene.search.Sort) LindenSort(com.xiaomi.linden.thrift.common.LindenSort) SortField(org.apache.lucene.search.SortField) LindenSortField(com.xiaomi.linden.thrift.common.LindenSortField) Point(com.spatial4j.core.shape.Point) LindenSortField(com.xiaomi.linden.thrift.common.LindenSortField) Point(com.spatial4j.core.shape.Point)

Aggregations

LindenSort (com.xiaomi.linden.thrift.common.LindenSort)2 Point (com.spatial4j.core.shape.Point)1 LindenSortField (com.xiaomi.linden.thrift.common.LindenSortField)1 ValueSource (org.apache.lucene.queries.function.ValueSource)1 Sort (org.apache.lucene.search.Sort)1 SortField (org.apache.lucene.search.SortField)1