use of org.apache.lucene.queries.function.docvalues.DoubleDocValues 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.apache.lucene.queries.function.docvalues.DoubleDocValues in project lucene-solr by apache.
the class MultiDoubleFunction method getValues.
@Override
public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
final FunctionValues[] valsArr = new FunctionValues[sources.length];
for (int i = 0; i < sources.length; i++) {
valsArr[i] = sources[i].getValues(context, readerContext);
}
return new DoubleDocValues(this) {
@Override
public double doubleVal(int doc) throws IOException {
return func(doc, valsArr);
}
@Override
public boolean exists(int doc) throws IOException {
boolean exists = true;
for (FunctionValues val : valsArr) {
exists = exists & val.exists(doc);
}
return exists;
}
@Override
public String toString(int doc) throws IOException {
StringBuilder sb = new StringBuilder();
sb.append(name()).append('(');
boolean firstTime = true;
for (FunctionValues vals : valsArr) {
if (firstTime) {
firstTime = false;
} else {
sb.append(',');
}
sb.append(vals.toString(doc));
}
sb.append(')');
return sb.toString();
}
};
}
use of org.apache.lucene.queries.function.docvalues.DoubleDocValues in project lucene-solr by apache.
the class DualDoubleFunction method getValues.
@Override
public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
final FunctionValues aVals = a.getValues(context, readerContext);
final FunctionValues bVals = b.getValues(context, readerContext);
return new DoubleDocValues(this) {
@Override
public double doubleVal(int doc) throws IOException {
return func(doc, aVals, bVals);
}
@Override
public boolean exists(int doc) throws IOException {
return aVals.exists(doc) & bVals.exists(doc);
}
@Override
public String toString(int doc) throws IOException {
return name() + '(' + aVals.toString(doc) + ',' + bVals.toString(doc) + ')';
}
};
}
use of org.apache.lucene.queries.function.docvalues.DoubleDocValues in project lucene-solr by apache.
the class VectorDistanceFunction method getValues.
@Override
public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
final FunctionValues vals1 = source1.getValues(context, readerContext);
final FunctionValues vals2 = source2.getValues(context, readerContext);
return new DoubleDocValues(this) {
@Override
public double doubleVal(int doc) throws IOException {
return distance(doc, vals1, vals2);
}
@Override
public String toString(int doc) throws IOException {
StringBuilder sb = new StringBuilder();
sb.append(name()).append('(').append(power).append(',');
boolean firstTime = true;
sb.append(vals1.toString(doc)).append(',');
sb.append(vals2.toString(doc));
sb.append(')');
return sb.toString();
}
};
}
use of org.apache.lucene.queries.function.docvalues.DoubleDocValues in project lucene-solr by apache.
the class HaversineConstFunction method getValues.
@Override
public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
final FunctionValues latVals = latSource.getValues(context, readerContext);
final FunctionValues lonVals = lonSource.getValues(context, readerContext);
final double latCenterRad = this.latCenter * DEGREES_TO_RADIANS;
final double lonCenterRad = this.lonCenter * DEGREES_TO_RADIANS;
final double latCenterRad_cos = this.latCenterRad_cos;
return new DoubleDocValues(this) {
@Override
public double doubleVal(int doc) throws IOException {
double latRad = latVals.doubleVal(doc) * DEGREES_TO_RADIANS;
double lonRad = lonVals.doubleVal(doc) * DEGREES_TO_RADIANS;
double diffX = latCenterRad - latRad;
double diffY = lonCenterRad - lonRad;
double hsinX = Math.sin(diffX * 0.5);
double hsinY = Math.sin(diffY * 0.5);
double h = hsinX * hsinX + (latCenterRad_cos * Math.cos(latRad) * hsinY * hsinY);
return (EARTH_MEAN_DIAMETER * Math.atan2(Math.sqrt(h), Math.sqrt(1 - h)));
}
@Override
public String toString(int doc) throws IOException {
return name() + '(' + latVals.toString(doc) + ',' + lonVals.toString(doc) + ',' + latCenter + ',' + lonCenter + ')';
}
};
}
Aggregations