Search in sources :

Example 1 with IndexGeoPointFieldData

use of org.opensearch.index.fielddata.IndexGeoPointFieldData in project OpenSearch by opensearch-project.

the class GeoDistanceSortBuilder method buildBucketedSort.

@Override
public BucketedSort buildBucketedSort(QueryShardContext context, int bucketSize, BucketedSort.ExtraData extra) throws IOException {
    GeoPoint[] localPoints = localPoints();
    MultiValueMode localSortMode = localSortMode();
    IndexGeoPointFieldData geoIndexFieldData = fieldData(context);
    Nested nested = nested(context);
    return comparatorSource(localPoints, localSortMode, geoIndexFieldData, nested).newBucketedSort(context.bigArrays(), order, DocValueFormat.RAW, bucketSize, extra);
}
Also used : GeoPoint(org.opensearch.common.geo.GeoPoint) IndexGeoPointFieldData(org.opensearch.index.fielddata.IndexGeoPointFieldData) Nested(org.opensearch.index.fielddata.IndexFieldData.XFieldComparatorSource.Nested) MultiValueMode(org.opensearch.search.MultiValueMode)

Example 2 with IndexGeoPointFieldData

use of org.opensearch.index.fielddata.IndexGeoPointFieldData in project OpenSearch by opensearch-project.

the class GeoDistanceSortBuilder method build.

@Override
public SortFieldAndFormat build(QueryShardContext context) throws IOException {
    GeoPoint[] localPoints = localPoints();
    boolean reverse = order == SortOrder.DESC;
    MultiValueMode localSortMode = localSortMode();
    IndexGeoPointFieldData geoIndexFieldData = fieldData(context);
    Nested nested = nested(context);
    if (// only works with 5.x geo_point
    geoIndexFieldData.getClass() == LatLonPointIndexFieldData.class && nested == null && // LatLonDocValuesField internally picks the closest point
    localSortMode == MultiValueMode.MIN && unit == DistanceUnit.METERS && reverse == false && localPoints.length == 1) {
        return new SortFieldAndFormat(LatLonDocValuesField.newDistanceSort(fieldName, localPoints[0].lat(), localPoints[0].lon()), DocValueFormat.RAW);
    }
    return new SortFieldAndFormat(new SortField(fieldName, comparatorSource(localPoints, localSortMode, geoIndexFieldData, nested), reverse), DocValueFormat.RAW);
}
Also used : GeoPoint(org.opensearch.common.geo.GeoPoint) IndexGeoPointFieldData(org.opensearch.index.fielddata.IndexGeoPointFieldData) Nested(org.opensearch.index.fielddata.IndexFieldData.XFieldComparatorSource.Nested) SortField(org.apache.lucene.search.SortField) MultiValueMode(org.opensearch.search.MultiValueMode) LatLonPointIndexFieldData(org.opensearch.index.fielddata.plain.AbstractLatLonPointIndexFieldData.LatLonPointIndexFieldData)

Example 3 with IndexGeoPointFieldData

use of org.opensearch.index.fielddata.IndexGeoPointFieldData in project OpenSearch by opensearch-project.

the class DecayFunctionBuilder method parseGeoVariable.

private AbstractDistanceScoreFunction parseGeoVariable(XContentParser parser, QueryShardContext context, MappedFieldType fieldType, MultiValueMode mode) throws IOException {
    XContentParser.Token token;
    String parameterName = null;
    GeoPoint origin = new GeoPoint();
    String scaleString = null;
    String offsetString = "0km";
    double decay = 0.5;
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            parameterName = parser.currentName();
        } else if (DecayFunctionBuilder.SCALE.equals(parameterName)) {
            scaleString = parser.text();
        } else if (DecayFunctionBuilder.ORIGIN.equals(parameterName)) {
            origin = GeoUtils.parseGeoPoint(parser);
        } else if (DecayFunctionBuilder.DECAY.equals(parameterName)) {
            decay = parser.doubleValue();
        } else if (DecayFunctionBuilder.OFFSET.equals(parameterName)) {
            offsetString = parser.text();
        } else {
            throw new OpenSearchParseException("parameter [{}] not supported!", parameterName);
        }
    }
    if (origin == null || scaleString == null) {
        throw new OpenSearchParseException("[{}] and [{}] must be set for geo fields.", DecayFunctionBuilder.ORIGIN, DecayFunctionBuilder.SCALE);
    }
    double scale = DistanceUnit.DEFAULT.parse(scaleString, DistanceUnit.DEFAULT);
    double offset = DistanceUnit.DEFAULT.parse(offsetString, DistanceUnit.DEFAULT);
    IndexGeoPointFieldData indexFieldData = context.getForField(fieldType);
    return new GeoFieldDataScoreFunction(origin, scale, decay, offset, getDecayFunction(), indexFieldData, mode, getFunctionName());
}
Also used : GeoPoint(org.opensearch.common.geo.GeoPoint) OpenSearchParseException(org.opensearch.OpenSearchParseException) IndexGeoPointFieldData(org.opensearch.index.fielddata.IndexGeoPointFieldData) XContentParser(org.opensearch.common.xcontent.XContentParser)

Aggregations

GeoPoint (org.opensearch.common.geo.GeoPoint)3 IndexGeoPointFieldData (org.opensearch.index.fielddata.IndexGeoPointFieldData)3 Nested (org.opensearch.index.fielddata.IndexFieldData.XFieldComparatorSource.Nested)2 MultiValueMode (org.opensearch.search.MultiValueMode)2 SortField (org.apache.lucene.search.SortField)1 OpenSearchParseException (org.opensearch.OpenSearchParseException)1 XContentParser (org.opensearch.common.xcontent.XContentParser)1 LatLonPointIndexFieldData (org.opensearch.index.fielddata.plain.AbstractLatLonPointIndexFieldData.LatLonPointIndexFieldData)1