Example usage for org.apache.lucene.util.mutable MutableValueFloat MutableValueFloat

List of usage examples for org.apache.lucene.util.mutable MutableValueFloat MutableValueFloat

Introduction

In this page you can find the example usage for org.apache.lucene.util.mutable MutableValueFloat MutableValueFloat.

Prototype

MutableValueFloat

Source Link

Usage

From source file:org.apache.solr.schema.SortableFloatField.java

License:Apache License

@Override
public FunctionValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
    final float def = defVal;

    return new DocTermsIndexDocValues(this, readerContext, field) {
        private final BytesRef spare = new BytesRef();

        @Override// w  w  w. ja va2 s.co  m
        protected String toTerm(String readableValue) {
            return NumberUtils.float2sortableStr(readableValue);
        }

        @Override
        public boolean exists(int doc) {
            return termsIndex.getOrd(doc) >= 0;
        }

        @Override
        public float floatVal(int doc) {
            int ord = termsIndex.getOrd(doc);
            if (ord == -1) {
                return def;
            } else {
                termsIndex.lookupOrd(ord, spare);
                return NumberUtils.SortableStr2float(spare);
            }
        }

        @Override
        public int intVal(int doc) {
            return (int) floatVal(doc);
        }

        @Override
        public long longVal(int doc) {
            return (long) floatVal(doc);
        }

        @Override
        public double doubleVal(int doc) {
            return (double) floatVal(doc);
        }

        @Override
        public String strVal(int doc) {
            return Float.toString(floatVal(doc));
        }

        @Override
        public String toString(int doc) {
            return description() + '=' + floatVal(doc);
        }

        @Override
        public Object objectVal(int doc) {
            return exists(doc) ? floatVal(doc) : null;
        }

        @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) {
                    int ord = termsIndex.getOrd(doc);
                    if (ord == -1) {
                        mval.value = def;
                        mval.exists = false;
                    } else {
                        termsIndex.lookupOrd(ord, spare);
                        mval.value = NumberUtils.SortableStr2float(spare);
                        mval.exists = true;
                    }
                }
            };
        }
    };
}

From source file:org.apache.solr.schema.TrieFloatField.java

License:Apache License

@Override
protected ValueSource getSingleValueSource(SortedSetSelector.Type choice, SchemaField f) {

    return new SortedSetFieldSource(f.getName(), choice) {
        @Override//from  www  .j a  v a2s .  c  o m
        public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
            SortedSetFieldSource thisAsSortedSetFieldSource = this; // needed for nested anon class ref

            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;
                            }
                        }
                    };
                }
            };
        }
    };
}

From source file:org.apache.solr.search.grouping.distributed.command.GroupConverter.java

License:Apache License

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; // ?
        TrieField.TrieTypes type = ((TrieField) fieldType).getType();
        final MutableValue v;
        switch (type) {
        case INTEGER:
            MutableValueInt mutableInt = new MutableValueInt();
            if (original.groupValue == null) {
                mutableInt.value = 0;/*from   ww  w  . j  a  va 2 s  . c  o  m*/
                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;
}