use of org.apache.lucene.util.mutable.MutableValueDate in project lucene-solr by apache.
the class DateFieldSource method getValues.
@Override
public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
final NumericDocValues arr = DocValues.getNumeric(readerContext.reader(), field);
return new LongDocValues(this) {
private long getDocValue(int doc) throws IOException {
int arrDocID = arr.docID();
if (arrDocID < doc) {
arrDocID = arr.advance(doc);
}
if (arrDocID == doc) {
return arr.longValue();
} else {
return 0;
}
}
@Override
public long longVal(int doc) throws IOException {
return getDocValue(doc);
}
@Override
public boolean exists(int doc) throws IOException {
getDocValue(doc);
return arr.docID() == doc;
}
@Override
public Object objectVal(int doc) throws IOException {
return exists(doc) ? longToObject(getDocValue(doc)) : null;
}
@Override
public String strVal(int doc) throws IOException {
return exists(doc) ? longToString(getDocValue(doc)) : null;
}
@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 = getDocValue(doc);
mval.exists = exists(doc);
}
};
}
};
}
use of org.apache.lucene.util.mutable.MutableValueDate 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);
}
};
}
};
}
use of org.apache.lucene.util.mutable.MutableValueDate 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;
}
use of org.apache.lucene.util.mutable.MutableValueDate in project lucene-solr by apache.
the class ConstDateSource method getValues.
@Override
public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
return new FloatDocValues(this) {
@Override
public float floatVal(int doc) {
return getFloat();
}
@Override
public int intVal(int doc) {
return getInt();
}
@Override
public long longVal(int doc) {
return getLong();
}
@Override
public double doubleVal(int doc) {
return getDouble();
}
@Override
public String toString(int doc) {
return description();
}
@Override
public Object objectVal(int doc) {
return new Date(longVal(doc));
}
@SuppressWarnings("deprecation")
@Override
public String strVal(int doc) {
return Instant.ofEpochMilli(longVal(doc)).toString();
}
@Override
public boolean boolVal(int doc) {
return getFloat() != 0.0f;
}
@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) {
mval.value = longVal(doc);
mval.exists = true;
}
};
}
};
}
Aggregations