Search in sources :

Example 16 with DoubleDocValues

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

the class TrieDoubleField method getSingleValueSource.

@Override
protected ValueSource getSingleValueSource(SortedSetSelector.Type choice, SchemaField f) {
    return new SortedSetFieldSource(f.getName(), choice) {

        @Override
        public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
            // needed for nested anon class ref
            SortedSetFieldSource thisAsSortedSetFieldSource = this;
            SortedSetDocValues sortedSet = DocValues.getSortedSet(readerContext.reader(), field);
            SortedDocValues view = SortedSetSelector.wrap(sortedSet, selector);
            return new DoubleDocValues(thisAsSortedSetFieldSource) {

                private int lastDocID;

                private boolean setDoc(int docID) throws IOException {
                    if (docID < lastDocID) {
                        throw new IllegalArgumentException("docs out of order: lastDocID=" + lastDocID + " docID=" + docID);
                    }
                    if (docID > view.docID()) {
                        lastDocID = docID;
                        return docID == view.advance(docID);
                    } else {
                        return docID == view.docID();
                    }
                }

                @Override
                public double doubleVal(int doc) throws IOException {
                    if (setDoc(doc)) {
                        BytesRef bytes = view.binaryValue();
                        assert bytes.length > 0;
                        return NumericUtils.sortableLongToDouble(LegacyNumericUtils.prefixCodedToLong(bytes));
                    } else {
                        return 0D;
                    }
                }

                @Override
                public boolean exists(int doc) throws IOException {
                    return setDoc(doc);
                }

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

                        private final MutableValueDouble mval = new MutableValueDouble();

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

                        @Override
                        public void fillValue(int doc) throws IOException {
                            if (setDoc(doc)) {
                                mval.exists = true;
                                mval.value = NumericUtils.sortableLongToDouble(LegacyNumericUtils.prefixCodedToLong(view.binaryValue()));
                            } else {
                                mval.exists = false;
                                mval.value = 0D;
                            }
                        }
                    };
                }
            };
        }
    };
}
Also used : SortedSetDocValues(org.apache.lucene.index.SortedSetDocValues) DoubleDocValues(org.apache.lucene.queries.function.docvalues.DoubleDocValues) LeafReaderContext(org.apache.lucene.index.LeafReaderContext) MutableValueDouble(org.apache.lucene.util.mutable.MutableValueDouble) Map(java.util.Map) SortedSetFieldSource(org.apache.lucene.queries.function.valuesource.SortedSetFieldSource) SortedDocValues(org.apache.lucene.index.SortedDocValues) BytesRef(org.apache.lucene.util.BytesRef)

Example 17 with DoubleDocValues

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

the class DoubleFieldSource method getValues.

@Override
public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
    final NumericDocValues values = getNumericDocValues(context, readerContext);
    return new DoubleDocValues(this) {

        int lastDocID;

        private double getValueForDoc(int doc) throws IOException {
            if (doc < lastDocID) {
                throw new IllegalArgumentException("docs were sent out-of-order: lastDocID=" + lastDocID + " vs docID=" + doc);
            }
            lastDocID = doc;
            int curDocID = values.docID();
            if (doc > curDocID) {
                curDocID = values.advance(doc);
            }
            if (doc == curDocID) {
                return Double.longBitsToDouble(values.longValue());
            } else {
                return 0.0;
            }
        }

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

        @Override
        public boolean exists(int doc) throws IOException {
            getValueForDoc(doc);
            return doc == values.docID();
        }

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

                private final MutableValueDouble mval = new MutableValueDouble();

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

                @Override
                public void fillValue(int doc) throws IOException {
                    mval.value = getValueForDoc(doc);
                    mval.exists = exists(doc);
                }
            };
        }
    };
}
Also used : NumericDocValues(org.apache.lucene.index.NumericDocValues) DoubleDocValues(org.apache.lucene.queries.function.docvalues.DoubleDocValues) MutableValueDouble(org.apache.lucene.util.mutable.MutableValueDouble)

Example 18 with DoubleDocValues

use of org.apache.lucene.queries.function.docvalues.DoubleDocValues 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 19 with DoubleDocValues

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

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