Search in sources :

Example 6 with DoubleDocValues

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

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();
        }
    };
}
Also used : DoubleDocValues(org.apache.lucene.queries.function.docvalues.DoubleDocValues) FunctionValues(org.apache.lucene.queries.function.FunctionValues)

Example 8 with DoubleDocValues

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) + ')';
        }
    };
}
Also used : DoubleDocValues(org.apache.lucene.queries.function.docvalues.DoubleDocValues) FunctionValues(org.apache.lucene.queries.function.FunctionValues)

Example 9 with DoubleDocValues

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();
        }
    };
}
Also used : DoubleDocValues(org.apache.lucene.queries.function.docvalues.DoubleDocValues) FunctionValues(org.apache.lucene.queries.function.FunctionValues)

Example 10 with DoubleDocValues

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 + ')';
        }
    };
}
Also used : DoubleDocValues(org.apache.lucene.queries.function.docvalues.DoubleDocValues) FunctionValues(org.apache.lucene.queries.function.FunctionValues)

Aggregations

DoubleDocValues (org.apache.lucene.queries.function.docvalues.DoubleDocValues)19 FunctionValues (org.apache.lucene.queries.function.FunctionValues)9 AtomicNumericFieldData (org.elasticsearch.index.fielddata.AtomicNumericFieldData)5 Explanation (org.apache.lucene.search.Explanation)3 AtomicGeoPointFieldData (org.elasticsearch.index.fielddata.AtomicGeoPointFieldData)3 MultiGeoPointValues (org.elasticsearch.index.fielddata.MultiGeoPointValues)3 NumericDoubleValues (org.elasticsearch.index.fielddata.NumericDoubleValues)3 ArrayList (java.util.ArrayList)2 MutableValueDouble (org.apache.lucene.util.mutable.MutableValueDouble)2 SortedNumericDoubleValues (org.elasticsearch.index.fielddata.SortedNumericDoubleValues)2 Shape (org.locationtech.spatial4j.shape.Shape)2 Calendar (java.util.Calendar)1 Map (java.util.Map)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 LeafReaderContext (org.apache.lucene.index.LeafReaderContext)1 NumericDocValues (org.apache.lucene.index.NumericDocValues)1 SortedDocValues (org.apache.lucene.index.SortedDocValues)1 SortedSetDocValues (org.apache.lucene.index.SortedSetDocValues)1 SortedSetFieldSource (org.apache.lucene.queries.function.valuesource.SortedSetFieldSource)1 BytesRef (org.apache.lucene.util.BytesRef)1