Search in sources :

Example 6 with FunctionValues

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

the class RangeMapFloatFunction method getValues.

@Override
public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
    final FunctionValues vals = source.getValues(context, readerContext);
    final FunctionValues targets = target.getValues(context, readerContext);
    final FunctionValues defaults = (this.defaultVal == null) ? null : defaultVal.getValues(context, readerContext);
    return new FloatDocValues(this) {

        @Override
        public float floatVal(int doc) throws IOException {
            float val = vals.floatVal(doc);
            return (val >= min && val <= max) ? targets.floatVal(doc) : (defaultVal == null ? val : defaults.floatVal(doc));
        }

        @Override
        public String toString(int doc) throws IOException {
            return "map(" + vals.toString(doc) + ",min=" + min + ",max=" + max + ",target=" + targets.toString(doc) + ",defaultVal=" + (defaults == null ? "null" : (defaults.toString(doc))) + ")";
        }
    };
}
Also used : FunctionValues(org.apache.lucene.queries.function.FunctionValues) FloatDocValues(org.apache.lucene.queries.function.docvalues.FloatDocValues)

Example 7 with FunctionValues

use of org.apache.lucene.queries.function.FunctionValues 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 FunctionValues

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

the class MultiStringFunction 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 StrDocValues(this) {

        @Override
        public String strVal(int doc) throws IOException {
            CharSequence cs = func(doc, valsArr);
            return cs != null ? cs.toString() : null;
        }

        @Override
        public boolean exists(int doc) throws IOException {
            boolean exists = true;
            for (FunctionValues val : valsArr) {
                exists = exists & val.exists(doc);
            }
            return exists;
        }

        @Override
        public boolean bytesVal(int doc, BytesRefBuilder bytes) throws IOException {
            bytes.clear();
            CharSequence cs = func(doc, valsArr);
            if (cs != null) {
                bytes.copyChars(func(doc, valsArr));
                return true;
            } else {
                return false;
            }
        }

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

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

                private final MutableValueStr mval = new MutableValueStr();

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

                @Override
                public void fillValue(int doc) throws IOException {
                    mval.exists = bytesVal(doc, mval.value);
                }
            };
        }
    };
}
Also used : BytesRefBuilder(org.apache.lucene.util.BytesRefBuilder) StrDocValues(org.apache.lucene.queries.function.docvalues.StrDocValues) MutableValueStr(org.apache.lucene.util.mutable.MutableValueStr) FunctionValues(org.apache.lucene.queries.function.FunctionValues)

Example 9 with FunctionValues

use of org.apache.lucene.queries.function.FunctionValues 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 10 with FunctionValues

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

the class MultiDateFunction 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 LongDocValues(this) {

        @Override
        public long longVal(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();
        }

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

                private final MutableValueDate mval = new MutableValueDate();

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

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

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