use of org.apache.lucene.queries.function.docvalues.FloatDocValues in project lucene-solr by apache.
the class TrieFloatField 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 FloatDocValues(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()) {
return docID == view.advance(docID);
} else {
return docID == view.docID();
}
}
@Override
public float floatVal(int doc) throws IOException {
if (setDoc(doc)) {
BytesRef bytes = view.binaryValue();
assert bytes.length > 0;
return NumericUtils.sortableIntToFloat(LegacyNumericUtils.prefixCodedToInt(bytes));
} else {
return 0F;
}
}
@Override
public boolean exists(int doc) throws IOException {
return setDoc(doc);
}
@Override
public ValueFiller getValueFiller() {
return new ValueFiller() {
private final MutableValueFloat mval = new MutableValueFloat();
@Override
public MutableValue getValue() {
return mval;
}
@Override
public void fillValue(int doc) throws IOException {
if (setDoc(doc)) {
mval.exists = true;
mval.value = NumericUtils.sortableIntToFloat(LegacyNumericUtils.prefixCodedToInt(view.binaryValue()));
} else {
mval.exists = false;
mval.value = 0F;
}
}
};
}
};
}
};
}
use of org.apache.lucene.queries.function.docvalues.FloatDocValues in project lucene-solr by apache.
the class ScaleFloatFunction method getValues.
@Override
public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
ScaleInfo scaleInfo = (ScaleInfo) context.get(ScaleFloatFunction.this);
if (scaleInfo == null) {
scaleInfo = createScaleInfo(context, readerContext);
}
final float scale = (scaleInfo.maxVal - scaleInfo.minVal == 0) ? 0 : (max - min) / (scaleInfo.maxVal - scaleInfo.minVal);
final float minSource = scaleInfo.minVal;
final float maxSource = scaleInfo.maxVal;
final FunctionValues vals = source.getValues(context, readerContext);
return new FloatDocValues(this) {
@Override
public boolean exists(int doc) throws IOException {
return vals.exists(doc);
}
@Override
public float floatVal(int doc) throws IOException {
return (vals.floatVal(doc) - minSource) * scale + min;
}
@Override
public String toString(int doc) throws IOException {
return "scale(" + vals.toString(doc) + ",toMin=" + min + ",toMax=" + max + ",fromMin=" + minSource + ",fromMax=" + maxSource + ")";
}
};
}
use of org.apache.lucene.queries.function.docvalues.FloatDocValues in project lucene-solr by apache.
the class FloatFieldSource method getValues.
@Override
public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
final NumericDocValues arr = getNumericDocValues(context, readerContext);
return new FloatDocValues(this) {
int lastDocID;
private float 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 Float.intBitsToFloat((int) arr.longValue());
} else {
return 0f;
}
}
@Override
public float floatVal(int doc) throws IOException {
return getValueForDoc(doc);
}
@Override
public boolean exists(int doc) throws IOException {
getValueForDoc(doc);
return arr.docID() == doc;
}
@Override
public ValueFiller getValueFiller() {
return new ValueFiller() {
private final MutableValueFloat mval = new MutableValueFloat();
@Override
public MutableValue getValue() {
return mval;
}
@Override
public void fillValue(int doc) throws IOException {
mval.value = floatVal(doc);
mval.exists = arr.docID() == doc;
}
};
}
};
}
use of org.apache.lucene.queries.function.docvalues.FloatDocValues in project lucene-solr by apache.
the class NormValueSource method getValues.
@Override
public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
IndexSearcher searcher = (IndexSearcher) context.get("searcher");
final TFIDFSimilarity similarity = IDFValueSource.asTFIDF(searcher.getSimilarity(true), field);
if (similarity == null) {
throw new UnsupportedOperationException("requires a TFIDFSimilarity (such as ClassicSimilarity)");
}
// Only works if the contribution of the tf is 1 when the freq is 1 and contribution of the idf
// is 1 when docCount == docFreq == 1
final SimWeight simWeight = similarity.computeWeight(1f, new CollectionStatistics(field, 1, 1, 1, 1), new TermStatistics(new BytesRef("bogus"), 1, 1));
final SimScorer simScorer = similarity.simScorer(simWeight, readerContext);
return new FloatDocValues(this) {
int lastDocID = -1;
@Override
public float floatVal(int docID) throws IOException {
if (docID < lastDocID) {
throw new AssertionError("docs out of order: lastDocID=" + lastDocID + " docID=" + docID);
}
lastDocID = docID;
return simScorer.score(docID, 1f);
}
};
}
use of org.apache.lucene.queries.function.docvalues.FloatDocValues 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