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