List of usage examples for org.apache.lucene.util.mutable MutableValueDouble MutableValueDouble
MutableValueDouble
From source file:org.apache.solr.schema.SortableDoubleField.java
License:Apache License
@Override public FunctionValues getValues(Map context, AtomicReaderContext readerContext) throws IOException { final double def = defVal; return new DocTermsIndexDocValues(this, readerContext, field) { private final BytesRef spare = new BytesRef(); @Override//w w w .ja v a 2 s. c o m protected String toTerm(String readableValue) { return NumberUtils.double2sortableStr(readableValue); } @Override public boolean exists(int doc) { return termsIndex.getOrd(doc) >= 0; } @Override public float floatVal(int doc) { return (float) doubleVal(doc); } @Override public int intVal(int doc) { return (int) doubleVal(doc); } @Override public long longVal(int doc) { return (long) doubleVal(doc); } @Override public double doubleVal(int doc) { int ord = termsIndex.getOrd(doc); if (ord == -1) { return def; } else { termsIndex.lookupOrd(ord, spare); return NumberUtils.SortableStr2double(spare); } } @Override public String strVal(int doc) { return Double.toString(doubleVal(doc)); } @Override public Object objectVal(int doc) { return exists(doc) ? doubleVal(doc) : null; } @Override public String toString(int doc) { return description() + '=' + doubleVal(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) { int ord = termsIndex.getOrd(doc); if (ord == -1) { mval.value = def; mval.exists = false; } else { termsIndex.lookupOrd(ord, spare); mval.value = NumberUtils.SortableStr2double(spare); mval.exists = true; } } }; } }; }
From source file:org.apache.solr.schema.TrieDoubleField.java
License:Apache License
@Override protected ValueSource getSingleValueSource(SortedSetSelector.Type choice, SchemaField f) { return new SortedSetFieldSource(f.getName(), choice) { @Override/* w ww . j a v a 2s. c om*/ 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 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; } } }; } }; } }; }
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;/*www . j a v a2 s . c om*/ 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; }