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();
}
}
};
}
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];
}
};
}
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];
}
};
}
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;
}
}
};
}
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));
}
}
}
Aggregations