Search in sources :

Example 1 with LongDocValues

use of org.apache.lucene.queries.function.docvalues.LongDocValues in project lucene-solr by apache.

the class LongFieldSource method getValues.

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

        int lastDocID;

        private long 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 arr.longValue();
            } else {
                return 0;
            }
        }

        @Override
        public long longVal(int doc) throws IOException {
            return getValueForDoc(doc);
        }

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

        @Override
        public Object objectVal(int doc) throws IOException {
            long value = getValueForDoc(doc);
            if (arr.docID() == doc) {
                return longToObject(value);
            } else {
                return null;
            }
        }

        @Override
        public String strVal(int doc) throws IOException {
            long value = getValueForDoc(doc);
            if (arr.docID() == doc) {
                return longToString(value);
            } else {
                return null;
            }
        }

        @Override
        protected long externalToLong(String extVal) {
            return LongFieldSource.this.externalToLong(extVal);
        }

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

                private final MutableValueLong mval = newMutableValueLong();

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

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

Example 2 with LongDocValues

use of org.apache.lucene.queries.function.docvalues.LongDocValues 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 3 with LongDocValues

use of org.apache.lucene.queries.function.docvalues.LongDocValues 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 4 with LongDocValues

use of org.apache.lucene.queries.function.docvalues.LongDocValues in project lucene-solr by apache.

the class TrieLongField 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 LongDocValues(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 long longVal(int doc) throws IOException {
                    if (setDoc(doc)) {
                        BytesRef bytes = view.binaryValue();
                        assert bytes.length > 0;
                        return LegacyNumericUtils.prefixCodedToLong(bytes);
                    } else {
                        return 0L;
                    }
                }

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

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

                        private final MutableValueLong mval = new MutableValueLong();

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

                        @Override
                        public void fillValue(int doc) throws IOException {
                            if (setDoc(doc)) {
                                mval.exists = true;
                                mval.value = LegacyNumericUtils.prefixCodedToLong(view.binaryValue());
                            } else {
                                mval.exists = false;
                                mval.value = 0L;
                            }
                        }
                    };
                }
            };
        }
    };
}
Also used : SortedSetDocValues(org.apache.lucene.index.SortedSetDocValues) LeafReaderContext(org.apache.lucene.index.LeafReaderContext) MutableValueLong(org.apache.lucene.util.mutable.MutableValueLong) Map(java.util.Map) SortedSetFieldSource(org.apache.lucene.queries.function.valuesource.SortedSetFieldSource) SortedDocValues(org.apache.lucene.index.SortedDocValues) BytesRef(org.apache.lucene.util.BytesRef) LongDocValues(org.apache.lucene.queries.function.docvalues.LongDocValues)

Example 5 with LongDocValues

use of org.apache.lucene.queries.function.docvalues.LongDocValues in project lucene-solr by apache.

the class SumTotalTermFreqValueSource method createWeight.

@Override
public void createWeight(Map context, IndexSearcher searcher) throws IOException {
    long sumTotalTermFreq = 0;
    for (LeafReaderContext readerContext : searcher.getTopReaderContext().leaves()) {
        Terms terms = readerContext.reader().terms(indexedField);
        if (terms == null)
            continue;
        long v = terms.getSumTotalTermFreq();
        if (v == -1) {
            sumTotalTermFreq = -1;
            break;
        } else {
            sumTotalTermFreq += v;
        }
    }
    final long ttf = sumTotalTermFreq;
    context.put(this, new LongDocValues(this) {

        @Override
        public long longVal(int doc) {
            return ttf;
        }
    });
}
Also used : Terms(org.apache.lucene.index.Terms) LeafReaderContext(org.apache.lucene.index.LeafReaderContext) LongDocValues(org.apache.lucene.queries.function.docvalues.LongDocValues)

Aggregations

LongDocValues (org.apache.lucene.queries.function.docvalues.LongDocValues)6 LeafReaderContext (org.apache.lucene.index.LeafReaderContext)3 NumericDocValues (org.apache.lucene.index.NumericDocValues)2 MutableValueDate (org.apache.lucene.util.mutable.MutableValueDate)2 MutableValueLong (org.apache.lucene.util.mutable.MutableValueLong)2 Map (java.util.Map)1 SortedDocValues (org.apache.lucene.index.SortedDocValues)1 SortedSetDocValues (org.apache.lucene.index.SortedSetDocValues)1 Term (org.apache.lucene.index.Term)1 Terms (org.apache.lucene.index.Terms)1 FunctionValues (org.apache.lucene.queries.function.FunctionValues)1 SortedSetFieldSource (org.apache.lucene.queries.function.valuesource.SortedSetFieldSource)1 BytesRef (org.apache.lucene.util.BytesRef)1