Search in sources :

Example 1 with MutableValueDate

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);
                }
            };
        }
    };
}
Also used : MutableValueDate(org.apache.lucene.util.mutable.MutableValueDate) NumericDocValues(org.apache.lucene.index.NumericDocValues) LongDocValues(org.apache.lucene.queries.function.docvalues.LongDocValues)

Example 2 with MutableValueDate

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);
                }
            };
        }
    };
}
Also used : MutableValueDate(org.apache.lucene.util.mutable.MutableValueDate) FunctionValues(org.apache.lucene.queries.function.FunctionValues) LongDocValues(org.apache.lucene.queries.function.docvalues.LongDocValues)

Example 3 with MutableValueDate

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;
}
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 4 with MutableValueDate

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;
                }
            };
        }
    };
}
Also used : MutableValueDate(org.apache.lucene.util.mutable.MutableValueDate) FloatDocValues(org.apache.lucene.queries.function.docvalues.FloatDocValues) Date(java.util.Date) MutableValueDate(org.apache.lucene.util.mutable.MutableValueDate)

Aggregations

MutableValueDate (org.apache.lucene.util.mutable.MutableValueDate)4 LongDocValues (org.apache.lucene.queries.function.docvalues.LongDocValues)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 NumericDocValues (org.apache.lucene.index.NumericDocValues)1 FunctionValues (org.apache.lucene.queries.function.FunctionValues)1 FloatDocValues (org.apache.lucene.queries.function.docvalues.FloatDocValues)1 SearchGroup (org.apache.lucene.search.grouping.SearchGroup)1 BytesRef (org.apache.lucene.util.BytesRef)1 MutableValue (org.apache.lucene.util.mutable.MutableValue)1 MutableValueDouble (org.apache.lucene.util.mutable.MutableValueDouble)1 MutableValueFloat (org.apache.lucene.util.mutable.MutableValueFloat)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