Search in sources :

Example 41 with FunctionValues

use of org.apache.lucene.queries.function.FunctionValues in project lucene-solr by apache.

the class VectorValueSource method getValues.

@Override
public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
    int size = sources.size();
    // special-case x,y and lat,lon since it's so common
    if (size == 2) {
        final FunctionValues x = sources.get(0).getValues(context, readerContext);
        final FunctionValues y = sources.get(1).getValues(context, readerContext);
        return new FunctionValues() {

            @Override
            public void byteVal(int doc, byte[] vals) throws IOException {
                vals[0] = x.byteVal(doc);
                vals[1] = y.byteVal(doc);
            }

            @Override
            public void shortVal(int doc, short[] vals) throws IOException {
                vals[0] = x.shortVal(doc);
                vals[1] = y.shortVal(doc);
            }

            @Override
            public void intVal(int doc, int[] vals) throws IOException {
                vals[0] = x.intVal(doc);
                vals[1] = y.intVal(doc);
            }

            @Override
            public void longVal(int doc, long[] vals) throws IOException {
                vals[0] = x.longVal(doc);
                vals[1] = y.longVal(doc);
            }

            @Override
            public void floatVal(int doc, float[] vals) throws IOException {
                vals[0] = x.floatVal(doc);
                vals[1] = y.floatVal(doc);
            }

            @Override
            public void doubleVal(int doc, double[] vals) throws IOException {
                vals[0] = x.doubleVal(doc);
                vals[1] = y.doubleVal(doc);
            }

            @Override
            public void strVal(int doc, String[] vals) throws IOException {
                vals[0] = x.strVal(doc);
                vals[1] = y.strVal(doc);
            }

            @Override
            public String toString(int doc) throws IOException {
                return name() + "(" + x.toString(doc) + "," + y.toString(doc) + ")";
            }
        };
    }
    final FunctionValues[] valsArr = new FunctionValues[size];
    for (int i = 0; i < size; i++) {
        valsArr[i] = sources.get(i).getValues(context, readerContext);
    }
    return new FunctionValues() {

        @Override
        public void byteVal(int doc, byte[] vals) throws IOException {
            for (int i = 0; i < valsArr.length; i++) {
                vals[i] = valsArr[i].byteVal(doc);
            }
        }

        @Override
        public void shortVal(int doc, short[] vals) throws IOException {
            for (int i = 0; i < valsArr.length; i++) {
                vals[i] = valsArr[i].shortVal(doc);
            }
        }

        @Override
        public void floatVal(int doc, float[] vals) throws IOException {
            for (int i = 0; i < valsArr.length; i++) {
                vals[i] = valsArr[i].floatVal(doc);
            }
        }

        @Override
        public void intVal(int doc, int[] vals) throws IOException {
            for (int i = 0; i < valsArr.length; i++) {
                vals[i] = valsArr[i].intVal(doc);
            }
        }

        @Override
        public void longVal(int doc, long[] vals) throws IOException {
            for (int i = 0; i < valsArr.length; i++) {
                vals[i] = valsArr[i].longVal(doc);
            }
        }

        @Override
        public void doubleVal(int doc, double[] vals) throws IOException {
            for (int i = 0; i < valsArr.length; i++) {
                vals[i] = valsArr[i].doubleVal(doc);
            }
        }

        @Override
        public void strVal(int doc, String[] vals) throws IOException {
            for (int i = 0; i < valsArr.length; i++) {
                vals[i] = valsArr[i].strVal(doc);
            }
        }

        @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 : FunctionValues(org.apache.lucene.queries.function.FunctionValues)

Example 42 with FunctionValues

use of org.apache.lucene.queries.function.FunctionValues in project lucene-solr by apache.

the class FilterFieldSource method getValues.

@Override
public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
    final FunctionValues vals = source.getValues(context, readerContext);
    return new FunctionValues() {

        @Override
        public byte byteVal(int doc) throws IOException {
            return vals.byteVal(doc);
        }

        @Override
        public short shortVal(int doc) throws IOException {
            return vals.shortVal(doc);
        }

        @Override
        public float floatVal(int doc) throws IOException {
            return vals.floatVal(doc);
        }

        @Override
        public int intVal(int doc) throws IOException {
            return vals.intVal(doc);
        }

        @Override
        public long longVal(int doc) throws IOException {
            return vals.longVal(doc);
        }

        @Override
        public double doubleVal(int doc) throws IOException {
            return vals.doubleVal(doc);
        }

        @Override
        public String strVal(int doc) throws IOException {
            return vals.strVal(doc);
        }

        @Override
        public Object objectVal(int doc) throws IOException {
            return exists(doc) ? vals.objectVal(doc) : null;
        }

        @Override
        public boolean exists(int doc) throws IOException {
            Object other = vals.objectVal(doc);
            return other != null && !missValue.equals(other);
        }

        @Override
        public String toString(int doc) throws IOException {
            return NAME + '(' + vals.toString(doc) + ')';
        }

        @Override
        public ValueFiller getValueFiller() {
            return new ValueFiller() {

                private final ValueFiller delegateFiller = vals.getValueFiller();

                private final MutableValue mval = delegateFiller.getValue();

                @Override
                public MutableValue getValue() {
                    return mval;
                }

                @Override
                public void fillValue(int doc) throws IOException {
                    delegateFiller.fillValue(doc);
                    mval.exists = exists(doc);
                }
            };
        }
    };
}
Also used : FunctionValues(org.apache.lucene.queries.function.FunctionValues) MutableValue(org.apache.lucene.util.mutable.MutableValue)

Example 43 with FunctionValues

use of org.apache.lucene.queries.function.FunctionValues in project lucene-solr by apache.

the class GeohashFunction method getValues.

@Override
public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
    final FunctionValues latDV = lat.getValues(context, readerContext);
    final FunctionValues lonDV = lon.getValues(context, readerContext);
    return new FunctionValues() {

        @Override
        public String strVal(int doc) throws IOException {
            return GeohashUtils.encodeLatLon(latDV.doubleVal(doc), lonDV.doubleVal(doc));
        }

        @Override
        public String toString(int doc) throws IOException {
            StringBuilder sb = new StringBuilder();
            sb.append(name()).append('(');
            sb.append(latDV.toString(doc)).append(',').append(lonDV.toString(doc));
            sb.append(')');
            return sb.toString();
        }
    };
}
Also used : FunctionValues(org.apache.lucene.queries.function.FunctionValues)

Example 44 with FunctionValues

use of org.apache.lucene.queries.function.FunctionValues in project lucene-solr by apache.

the class GeohashHaversineFunction method getValues.

@Override
public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
    final FunctionValues gh1DV = geoHash1.getValues(context, readerContext);
    final FunctionValues gh2DV = geoHash2.getValues(context, readerContext);
    return new DoubleDocValues(this) {

        @Override
        public double doubleVal(int doc) throws IOException {
            return distance(doc, gh1DV, gh2DV);
        }

        @Override
        public String toString(int doc) throws IOException {
            StringBuilder sb = new StringBuilder();
            sb.append(name()).append('(');
            sb.append(gh1DV.toString(doc)).append(',').append(gh2DV.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 45 with FunctionValues

use of org.apache.lucene.queries.function.FunctionValues in project lucene-solr by apache.

the class HaversineFunction method getValues.

@Override
public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
    final FunctionValues vals1 = p1.getValues(context, readerContext);
    final FunctionValues vals2 = p2.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('(');
            sb.append(vals1.toString(doc)).append(',').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)

Aggregations

FunctionValues (org.apache.lucene.queries.function.FunctionValues)45 ValueSource (org.apache.lucene.queries.function.ValueSource)10 DoubleDocValues (org.apache.lucene.queries.function.docvalues.DoubleDocValues)9 LeafReaderContext (org.apache.lucene.index.LeafReaderContext)7 Map (java.util.Map)6 LeafReader (org.apache.lucene.index.LeafReader)6 NumericDocValues (org.apache.lucene.index.NumericDocValues)6 IOException (java.io.IOException)5 FloatDocValues (org.apache.lucene.queries.function.docvalues.FloatDocValues)5 Explanation (org.apache.lucene.search.Explanation)4 ArrayList (java.util.ArrayList)3 Terms (org.apache.lucene.index.Terms)3 BoolDocValues (org.apache.lucene.queries.function.docvalues.BoolDocValues)3 BytesRef (org.apache.lucene.util.BytesRef)3 BytesRefBuilder (org.apache.lucene.util.BytesRefBuilder)3 Point (org.locationtech.spatial4j.shape.Point)3 Rectangle (org.locationtech.spatial4j.shape.Rectangle)3 Date (java.util.Date)2 TermsEnum (org.apache.lucene.index.TermsEnum)2 SimpleFloatFunction (org.apache.lucene.queries.function.valuesource.SimpleFloatFunction)2