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