Search in sources :

Example 1 with MutableValueFloat

use of org.apache.lucene.util.mutable.MutableValueFloat in project lucene-solr by apache.

the class GroupConverter method toMutable.

static Collection<SearchGroup<MutableValue>> toMutable(SchemaField field, Collection<SearchGroup<BytesRef>> values) {
    FieldType fieldType = field.getType();
    List<SearchGroup<MutableValue>> result = new ArrayList<>(values.size());
    for (SearchGroup<BytesRef> original : values) {
        SearchGroup<MutableValue> converted = new SearchGroup<MutableValue>();
        // ?
        converted.sortValues = original.sortValues;
        NumberType type = fieldType.getNumberType();
        final MutableValue v;
        switch(type) {
            case INTEGER:
                MutableValueInt mutableInt = new MutableValueInt();
                if (original.groupValue == null) {
                    mutableInt.value = 0;
                    mutableInt.exists = false;
                } else {
                    mutableInt.value = (Integer) fieldType.toObject(field, original.groupValue);
                }
                v = mutableInt;
                break;
            case FLOAT:
                MutableValueFloat mutableFloat = new MutableValueFloat();
                if (original.groupValue == null) {
                    mutableFloat.value = 0;
                    mutableFloat.exists = false;
                } else {
                    mutableFloat.value = (Float) fieldType.toObject(field, original.groupValue);
                }
                v = mutableFloat;
                break;
            case DOUBLE:
                MutableValueDouble mutableDouble = new MutableValueDouble();
                if (original.groupValue == null) {
                    mutableDouble.value = 0;
                    mutableDouble.exists = false;
                } else {
                    mutableDouble.value = (Double) fieldType.toObject(field, original.groupValue);
                }
                v = mutableDouble;
                break;
            case LONG:
                MutableValueLong mutableLong = new MutableValueLong();
                if (original.groupValue == null) {
                    mutableLong.value = 0;
                    mutableLong.exists = false;
                } else {
                    mutableLong.value = (Long) fieldType.toObject(field, original.groupValue);
                }
                v = mutableLong;
                break;
            case DATE:
                MutableValueDate mutableDate = new MutableValueDate();
                if (original.groupValue == null) {
                    mutableDate.value = 0;
                    mutableDate.exists = false;
                } else {
                    mutableDate.value = ((Date) fieldType.toObject(field, original.groupValue)).getTime();
                }
                v = mutableDate;
                break;
            default:
                throw new AssertionError();
        }
        converted.groupValue = v;
        result.add(converted);
    }
    return result;
}
Also used : SearchGroup(org.apache.lucene.search.grouping.SearchGroup) ArrayList(java.util.ArrayList) MutableValue(org.apache.lucene.util.mutable.MutableValue) MutableValueLong(org.apache.lucene.util.mutable.MutableValueLong) FieldType(org.apache.solr.schema.FieldType) MutableValueDate(org.apache.lucene.util.mutable.MutableValueDate) NumberType(org.apache.solr.schema.NumberType) MutableValueFloat(org.apache.lucene.util.mutable.MutableValueFloat) MutableValueDouble(org.apache.lucene.util.mutable.MutableValueDouble) MutableValueInt(org.apache.lucene.util.mutable.MutableValueInt) BytesRef(org.apache.lucene.util.BytesRef)

Example 2 with MutableValueFloat

use of org.apache.lucene.util.mutable.MutableValueFloat in project lucene-solr by apache.

the class TrieFloatField 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 FloatDocValues(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()) {
                        return docID == view.advance(docID);
                    } else {
                        return docID == view.docID();
                    }
                }

                @Override
                public float floatVal(int doc) throws IOException {
                    if (setDoc(doc)) {
                        BytesRef bytes = view.binaryValue();
                        assert bytes.length > 0;
                        return NumericUtils.sortableIntToFloat(LegacyNumericUtils.prefixCodedToInt(bytes));
                    } else {
                        return 0F;
                    }
                }

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

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

                        private final MutableValueFloat mval = new MutableValueFloat();

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

                        @Override
                        public void fillValue(int doc) throws IOException {
                            if (setDoc(doc)) {
                                mval.exists = true;
                                mval.value = NumericUtils.sortableIntToFloat(LegacyNumericUtils.prefixCodedToInt(view.binaryValue()));
                            } else {
                                mval.exists = false;
                                mval.value = 0F;
                            }
                        }
                    };
                }
            };
        }
    };
}
Also used : SortedSetDocValues(org.apache.lucene.index.SortedSetDocValues) MutableValueFloat(org.apache.lucene.util.mutable.MutableValueFloat) LeafReaderContext(org.apache.lucene.index.LeafReaderContext) FloatDocValues(org.apache.lucene.queries.function.docvalues.FloatDocValues) 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 3 with MutableValueFloat

use of org.apache.lucene.util.mutable.MutableValueFloat in project lucene-solr by apache.

the class QueryDocValues method getValueFiller.

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

        private final MutableValueFloat mval = new MutableValueFloat();

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

        @Override
        public void fillValue(int doc) {
            try {
                if (noMatches) {
                    mval.value = defVal;
                    mval.exists = false;
                    return;
                }
                scorer = weight.scorer(readerContext);
                scorerDoc = -1;
                if (scorer == null) {
                    noMatches = true;
                    mval.value = defVal;
                    mval.exists = false;
                    return;
                }
                it = scorer.iterator();
                lastDocRequested = doc;
                if (scorerDoc < doc) {
                    scorerDoc = it.advance(doc);
                }
                if (scorerDoc > doc) {
                    // query doesn't match this document... either because we hit the
                    // end, or because the next doc is after this doc.
                    mval.value = defVal;
                    mval.exists = false;
                    return;
                }
                // a match!
                mval.value = scorer.score();
                mval.exists = true;
            } catch (IOException e) {
                throw new RuntimeException("caught exception in QueryDocVals(" + q + ") doc=" + doc, e);
            }
        }
    };
}
Also used : MutableValueFloat(org.apache.lucene.util.mutable.MutableValueFloat) IOException(java.io.IOException)

Example 4 with MutableValueFloat

use of org.apache.lucene.util.mutable.MutableValueFloat in project lucene-solr by apache.

the class FloatFieldSource method getValues.

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

        int lastDocID;

        private float 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 = arr.docID();
            if (doc > curDocID) {
                curDocID = arr.advance(doc);
            }
            if (doc == curDocID) {
                return Float.intBitsToFloat((int) arr.longValue());
            } else {
                return 0f;
            }
        }

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

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

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

                private final MutableValueFloat mval = new MutableValueFloat();

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

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

Example 5 with MutableValueFloat

use of org.apache.lucene.util.mutable.MutableValueFloat in project lucene-solr by apache.

the class FloatDocValues method getValueFiller.

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

        private final MutableValueFloat mval = new MutableValueFloat();

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

        @Override
        public void fillValue(int doc) throws IOException {
            mval.value = floatVal(doc);
            mval.exists = exists(doc);
        }
    };
}
Also used : MutableValueFloat(org.apache.lucene.util.mutable.MutableValueFloat)

Aggregations

MutableValueFloat (org.apache.lucene.util.mutable.MutableValueFloat)5 FloatDocValues (org.apache.lucene.queries.function.docvalues.FloatDocValues)2 BytesRef (org.apache.lucene.util.BytesRef)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)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 SearchGroup (org.apache.lucene.search.grouping.SearchGroup)1 MutableValue (org.apache.lucene.util.mutable.MutableValue)1 MutableValueDate (org.apache.lucene.util.mutable.MutableValueDate)1 MutableValueDouble (org.apache.lucene.util.mutable.MutableValueDouble)1 MutableValueInt (org.apache.lucene.util.mutable.MutableValueInt)1 MutableValueLong (org.apache.lucene.util.mutable.MutableValueLong)1 FieldType (org.apache.solr.schema.FieldType)1 NumberType (org.apache.solr.schema.NumberType)1