Search in sources :

Example 6 with MultiGeoPointValues

use of org.elasticsearch.index.fielddata.MultiGeoPointValues in project elasticsearch by elastic.

the class GeoLongitudeValueSource method getValues.

@Override
// ValueSource uses a rawtype
@SuppressWarnings("rawtypes")
public FunctionValues getValues(Map context, LeafReaderContext leaf) throws IOException {
    AtomicGeoPointFieldData leafData = (AtomicGeoPointFieldData) fieldData.load(leaf);
    final MultiGeoPointValues values = leafData.getGeoPointValues();
    return new DoubleDocValues(this) {

        @Override
        public double doubleVal(int doc) {
            values.setDocument(doc);
            if (values.count() == 0) {
                return 0.0;
            } else {
                return values.valueAt(0).getLon();
            }
        }
    };
}
Also used : AtomicGeoPointFieldData(org.elasticsearch.index.fielddata.AtomicGeoPointFieldData) DoubleDocValues(org.apache.lucene.queries.function.docvalues.DoubleDocValues) MultiGeoPointValues(org.elasticsearch.index.fielddata.MultiGeoPointValues)

Example 7 with MultiGeoPointValues

use of org.elasticsearch.index.fielddata.MultiGeoPointValues in project elasticsearch by elastic.

the class GeoPointDVAtomicFieldData method getGeoPointValues.

@Override
public MultiGeoPointValues getGeoPointValues() {
    return new MultiGeoPointValues() {

        GeoPoint[] points = new GeoPoint[0];

        private int count = 0;

        @Override
        public void setDocument(int docId) {
            values.setDocument(docId);
            count = values.count();
            if (count > points.length) {
                final int previousLength = points.length;
                points = Arrays.copyOf(points, ArrayUtil.oversize(count, RamUsageEstimator.NUM_BYTES_OBJECT_REF));
                for (int i = previousLength; i < points.length; ++i) {
                    points[i] = new GeoPoint(Double.NaN, Double.NaN);
                }
            }
            for (int i = 0; i < count; ++i) {
                points[i].resetFromIndexHash(values.valueAt(i));
            }
        }

        @Override
        public int count() {
            return count;
        }

        @Override
        public GeoPoint valueAt(int index) {
            return points[index];
        }
    };
}
Also used : GeoPoint(org.elasticsearch.common.geo.GeoPoint) MultiGeoPointValues(org.elasticsearch.index.fielddata.MultiGeoPointValues) GeoPoint(org.elasticsearch.common.geo.GeoPoint)

Example 8 with MultiGeoPointValues

use of org.elasticsearch.index.fielddata.MultiGeoPointValues in project elasticsearch by elastic.

the class LatLonPointDVAtomicFieldData method getGeoPointValues.

@Override
public MultiGeoPointValues getGeoPointValues() {
    return new MultiGeoPointValues() {

        GeoPoint[] points = new GeoPoint[0];

        private int count = 0;

        @Override
        public void setDocument(int docId) {
            values.setDocument(docId);
            count = values.count();
            if (count > points.length) {
                final int previousLength = points.length;
                points = Arrays.copyOf(points, ArrayUtil.oversize(count, RamUsageEstimator.NUM_BYTES_OBJECT_REF));
                for (int i = previousLength; i < points.length; ++i) {
                    points[i] = new GeoPoint(Double.NaN, Double.NaN);
                }
            }
            long encoded;
            for (int i = 0; i < count; ++i) {
                encoded = values.valueAt(i);
                points[i].reset(GeoEncodingUtils.decodeLatitude((int) (encoded >>> 32)), GeoEncodingUtils.decodeLongitude((int) encoded));
            }
        }

        @Override
        public int count() {
            return count;
        }

        @Override
        public GeoPoint valueAt(int index) {
            return points[index];
        }
    };
}
Also used : GeoPoint(org.elasticsearch.common.geo.GeoPoint) MultiGeoPointValues(org.elasticsearch.index.fielddata.MultiGeoPointValues) GeoPoint(org.elasticsearch.common.geo.GeoPoint)

Example 9 with MultiGeoPointValues

use of org.elasticsearch.index.fielddata.MultiGeoPointValues in project elasticsearch by elastic.

the class GeoEmptyValueSource method getValues.

@Override
// ValueSource uses a rawtype
@SuppressWarnings("rawtypes")
public FunctionValues getValues(Map context, LeafReaderContext leaf) throws IOException {
    AtomicGeoPointFieldData leafData = (AtomicGeoPointFieldData) fieldData.load(leaf);
    final MultiGeoPointValues values = leafData.getGeoPointValues();
    return new DoubleDocValues(this) {

        @Override
        public double doubleVal(int doc) {
            values.setDocument(doc);
            if (values.count() == 0) {
                return 1;
            } else {
                return 0;
            }
        }
    };
}
Also used : AtomicGeoPointFieldData(org.elasticsearch.index.fielddata.AtomicGeoPointFieldData) DoubleDocValues(org.apache.lucene.queries.function.docvalues.DoubleDocValues) MultiGeoPointValues(org.elasticsearch.index.fielddata.MultiGeoPointValues)

Example 10 with MultiGeoPointValues

use of org.elasticsearch.index.fielddata.MultiGeoPointValues in project elasticsearch by elastic.

the class MissingValuesTests method testMissingGeoPoints.

public void testMissingGeoPoints() {
    final int numDocs = TestUtil.nextInt(random(), 1, 100);
    final GeoPoint[][] values = new GeoPoint[numDocs][];
    for (int i = 0; i < numDocs; ++i) {
        values[i] = new GeoPoint[random().nextInt(4)];
        for (int j = 0; j < values[i].length; ++j) {
            values[i][j] = new GeoPoint(randomDouble() * 90, randomDouble() * 180);
        }
    }
    MultiGeoPointValues asGeoValues = new MultiGeoPointValues() {

        int i = -1;

        @Override
        public GeoPoint valueAt(int index) {
            return values[i][index];
        }

        @Override
        public void setDocument(int docId) {
            i = docId;
        }

        @Override
        public int count() {
            return values[i].length;
        }
    };
    final GeoPoint missing = new GeoPoint(randomDouble() * 90, randomDouble() * 180);
    MultiGeoPointValues withMissingReplaced = MissingValues.replaceMissing(asGeoValues, missing);
    for (int i = 0; i < numDocs; ++i) {
        withMissingReplaced.setDocument(i);
        if (values[i].length > 0) {
            assertEquals(values[i].length, withMissingReplaced.count());
            for (int j = 0; j < values[i].length; ++j) {
                assertEquals(values[i][j], withMissingReplaced.valueAt(j));
            }
        } else {
            assertEquals(1, withMissingReplaced.count());
            assertEquals(missing, withMissingReplaced.valueAt(0));
        }
    }
}
Also used : GeoPoint(org.elasticsearch.common.geo.GeoPoint) MultiGeoPointValues(org.elasticsearch.index.fielddata.MultiGeoPointValues) GeoPoint(org.elasticsearch.common.geo.GeoPoint)

Aggregations

MultiGeoPointValues (org.elasticsearch.index.fielddata.MultiGeoPointValues)10 GeoPoint (org.elasticsearch.common.geo.GeoPoint)6 DoubleDocValues (org.apache.lucene.queries.function.docvalues.DoubleDocValues)3 AtomicGeoPointFieldData (org.elasticsearch.index.fielddata.AtomicGeoPointFieldData)3 BigArrays (org.elasticsearch.common.util.BigArrays)2 NumericDoubleValues (org.elasticsearch.index.fielddata.NumericDoubleValues)2 SortedNumericDoubleValues (org.elasticsearch.index.fielddata.SortedNumericDoubleValues)2 LeafBucketCollectorBase (org.elasticsearch.search.aggregations.LeafBucketCollectorBase)2 LeafReaderContext (org.apache.lucene.index.LeafReaderContext)1 DocIdSetIterator (org.apache.lucene.search.DocIdSetIterator)1 SortField (org.apache.lucene.search.SortField)1 BitSet (org.apache.lucene.util.BitSet)1 Bits (org.apache.lucene.util.Bits)1 ElasticsearchParseException (org.elasticsearch.ElasticsearchParseException)1 GeoPointValues (org.elasticsearch.index.fielddata.GeoPointValues)1 IndexFieldData (org.elasticsearch.index.fielddata.IndexFieldData)1 Nested (org.elasticsearch.index.fielddata.IndexFieldData.XFieldComparatorSource.Nested)1 IndexGeoPointFieldData (org.elasticsearch.index.fielddata.IndexGeoPointFieldData)1 SortingNumericDoubleValues (org.elasticsearch.index.fielddata.SortingNumericDoubleValues)1 LatLonPointDVIndexFieldData (org.elasticsearch.index.fielddata.plain.AbstractLatLonPointDVIndexFieldData.LatLonPointDVIndexFieldData)1