Search in sources :

Example 1 with MultiGeoPointValues

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

the class GeoEmptyValueSource method getValues.

@Override
public DoubleValues getValues(LeafReaderContext leaf, DoubleValues scores) {
    LeafGeoPointFieldData leafData = (LeafGeoPointFieldData) fieldData.load(leaf);
    final MultiGeoPointValues values = leafData.getGeoPointValues();
    return new DoubleValues() {

        @Override
        public double doubleValue() {
            return 1;
        }

        @Override
        public boolean advanceExact(int doc) throws IOException {
            return values.advanceExact(doc);
        }
    };
}
Also used : DoubleValues(org.apache.lucene.search.DoubleValues) MultiGeoPointValues(org.opensearch.index.fielddata.MultiGeoPointValues) LeafGeoPointFieldData(org.opensearch.index.fielddata.LeafGeoPointFieldData)

Example 2 with MultiGeoPointValues

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

the class GeoUtils method distanceValues.

/**
 * Return a {@link SortedNumericDoubleValues} instance that returns the distances to a list of geo-points
 * for each document.
 */
public static SortedNumericDoubleValues distanceValues(final GeoDistance distance, final DistanceUnit unit, final MultiGeoPointValues geoPointValues, final GeoPoint... fromPoints) {
    final GeoPointValues singleValues = FieldData.unwrapSingleton(geoPointValues);
    if (singleValues != null && fromPoints.length == 1) {
        return FieldData.singleton(new NumericDoubleValues() {

            @Override
            public boolean advanceExact(int doc) throws IOException {
                return singleValues.advanceExact(doc);
            }

            @Override
            public double doubleValue() throws IOException {
                final GeoPoint from = fromPoints[0];
                final GeoPoint to = singleValues.geoPointValue();
                return distance.calculate(from.lat(), from.lon(), to.lat(), to.lon(), unit);
            }
        });
    } else {
        return new SortingNumericDoubleValues() {

            @Override
            public boolean advanceExact(int target) throws IOException {
                if (geoPointValues.advanceExact(target)) {
                    resize(geoPointValues.docValueCount() * fromPoints.length);
                    int v = 0;
                    for (int i = 0; i < geoPointValues.docValueCount(); ++i) {
                        final GeoPoint point = geoPointValues.nextValue();
                        for (GeoPoint from : fromPoints) {
                            values[v] = distance.calculate(from.lat(), from.lon(), point.lat(), point.lon(), unit);
                            v++;
                        }
                    }
                    sort();
                    return true;
                } else {
                    return false;
                }
            }
        };
    }
}
Also used : SortingNumericDoubleValues(org.opensearch.index.fielddata.SortingNumericDoubleValues) MultiGeoPointValues(org.opensearch.index.fielddata.MultiGeoPointValues) GeoPointValues(org.opensearch.index.fielddata.GeoPointValues) SortedNumericDoubleValues(org.opensearch.index.fielddata.SortedNumericDoubleValues) SortingNumericDoubleValues(org.opensearch.index.fielddata.SortingNumericDoubleValues) NumericDoubleValues(org.opensearch.index.fielddata.NumericDoubleValues) IOException(java.io.IOException)

Example 3 with MultiGeoPointValues

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

the class GeoLongitudeValueSource method getValues.

@Override
public DoubleValues getValues(LeafReaderContext leaf, DoubleValues scores) {
    LeafGeoPointFieldData leafData = (LeafGeoPointFieldData) fieldData.load(leaf);
    final MultiGeoPointValues values = leafData.getGeoPointValues();
    return new DoubleValues() {

        @Override
        public double doubleValue() throws IOException {
            return values.nextValue().getLon();
        }

        @Override
        public boolean advanceExact(int doc) throws IOException {
            return values.advanceExact(doc);
        }
    };
}
Also used : DoubleValues(org.apache.lucene.search.DoubleValues) MultiGeoPointValues(org.opensearch.index.fielddata.MultiGeoPointValues) LeafGeoPointFieldData(org.opensearch.index.fielddata.LeafGeoPointFieldData)

Example 4 with MultiGeoPointValues

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

the class LatLonPointDVLeafFieldData method getGeoPointValues.

@Override
public MultiGeoPointValues getGeoPointValues() {
    try {
        final SortedNumericDocValues numericValues = DocValues.getSortedNumeric(reader, fieldName);
        return new MultiGeoPointValues() {

            final GeoPoint point = new GeoPoint();

            @Override
            public boolean advanceExact(int doc) throws IOException {
                return numericValues.advanceExact(doc);
            }

            @Override
            public int docValueCount() {
                return numericValues.docValueCount();
            }

            @Override
            public GeoPoint nextValue() throws IOException {
                final long encoded = numericValues.nextValue();
                point.reset(GeoEncodingUtils.decodeLatitude((int) (encoded >>> 32)), GeoEncodingUtils.decodeLongitude((int) encoded));
                return point;
            }
        };
    } catch (IOException e) {
        throw new IllegalStateException("Cannot load doc values", e);
    }
}
Also used : GeoPoint(org.opensearch.common.geo.GeoPoint) SortedNumericDocValues(org.apache.lucene.index.SortedNumericDocValues) IOException(java.io.IOException) MultiGeoPointValues(org.opensearch.index.fielddata.MultiGeoPointValues)

Example 5 with MultiGeoPointValues

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

the class GeoBoundsAggregator method getLeafCollector.

@Override
public LeafBucketCollector getLeafCollector(LeafReaderContext ctx, LeafBucketCollector sub) {
    if (valuesSource == null) {
        return LeafBucketCollector.NO_OP_COLLECTOR;
    }
    final BigArrays bigArrays = context.bigArrays();
    final MultiGeoPointValues values = valuesSource.geoPointValues(ctx);
    return new LeafBucketCollectorBase(sub, values) {

        @Override
        public void collect(int doc, long bucket) throws IOException {
            if (bucket >= tops.size()) {
                long from = tops.size();
                tops = bigArrays.grow(tops, bucket + 1);
                tops.fill(from, tops.size(), Double.NEGATIVE_INFINITY);
                bottoms = bigArrays.resize(bottoms, tops.size());
                bottoms.fill(from, bottoms.size(), Double.POSITIVE_INFINITY);
                posLefts = bigArrays.resize(posLefts, tops.size());
                posLefts.fill(from, posLefts.size(), Double.POSITIVE_INFINITY);
                posRights = bigArrays.resize(posRights, tops.size());
                posRights.fill(from, posRights.size(), Double.NEGATIVE_INFINITY);
                negLefts = bigArrays.resize(negLefts, tops.size());
                negLefts.fill(from, negLefts.size(), Double.POSITIVE_INFINITY);
                negRights = bigArrays.resize(negRights, tops.size());
                negRights.fill(from, negRights.size(), Double.NEGATIVE_INFINITY);
            }
            if (values.advanceExact(doc)) {
                final int valuesCount = values.docValueCount();
                for (int i = 0; i < valuesCount; ++i) {
                    GeoPoint value = values.nextValue();
                    double top = tops.get(bucket);
                    if (value.lat() > top) {
                        top = value.lat();
                    }
                    double bottom = bottoms.get(bucket);
                    if (value.lat() < bottom) {
                        bottom = value.lat();
                    }
                    double posLeft = posLefts.get(bucket);
                    if (value.lon() >= 0 && value.lon() < posLeft) {
                        posLeft = value.lon();
                    }
                    double posRight = posRights.get(bucket);
                    if (value.lon() >= 0 && value.lon() > posRight) {
                        posRight = value.lon();
                    }
                    double negLeft = negLefts.get(bucket);
                    if (value.lon() < 0 && value.lon() < negLeft) {
                        negLeft = value.lon();
                    }
                    double negRight = negRights.get(bucket);
                    if (value.lon() < 0 && value.lon() > negRight) {
                        negRight = value.lon();
                    }
                    tops.set(bucket, top);
                    bottoms.set(bucket, bottom);
                    posLefts.set(bucket, posLeft);
                    posRights.set(bucket, posRight);
                    negLefts.set(bucket, negLeft);
                    negRights.set(bucket, negRight);
                }
            }
        }
    };
}
Also used : GeoPoint(org.opensearch.common.geo.GeoPoint) BigArrays(org.opensearch.common.util.BigArrays) LeafBucketCollectorBase(org.opensearch.search.aggregations.LeafBucketCollectorBase) MultiGeoPointValues(org.opensearch.index.fielddata.MultiGeoPointValues) GeoPoint(org.opensearch.common.geo.GeoPoint)

Aggregations

MultiGeoPointValues (org.opensearch.index.fielddata.MultiGeoPointValues)10 GeoPoint (org.opensearch.common.geo.GeoPoint)5 BigArrays (org.opensearch.common.util.BigArrays)4 DoubleValues (org.apache.lucene.search.DoubleValues)3 LeafGeoPointFieldData (org.opensearch.index.fielddata.LeafGeoPointFieldData)3 LeafBucketCollectorBase (org.opensearch.search.aggregations.LeafBucketCollectorBase)3 IOException (java.io.IOException)2 SortedNumericDocValues (org.apache.lucene.index.SortedNumericDocValues)2 NumericDoubleValues (org.opensearch.index.fielddata.NumericDoubleValues)2 SortedNumericDoubleValues (org.opensearch.index.fielddata.SortedNumericDoubleValues)2 LeafReaderContext (org.apache.lucene.index.LeafReaderContext)1 DocIdSetIterator (org.apache.lucene.search.DocIdSetIterator)1 SortField (org.apache.lucene.search.SortField)1 DoubleComparator (org.apache.lucene.search.comparators.DoubleComparator)1 BitSet (org.apache.lucene.util.BitSet)1 GeoPointValues (org.opensearch.index.fielddata.GeoPointValues)1 SortedBinaryDocValues (org.opensearch.index.fielddata.SortedBinaryDocValues)1 SortingNumericDoubleValues (org.opensearch.index.fielddata.SortingNumericDoubleValues)1 DocValueFormat (org.opensearch.search.DocValueFormat)1 ValuesSource (org.opensearch.search.aggregations.support.ValuesSource)1