use of org.apache.lucene.queries.function.FunctionValues in project lucene-solr by apache.
the class RangeMapFloatFunction method getValues.
@Override
public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
final FunctionValues vals = source.getValues(context, readerContext);
final FunctionValues targets = target.getValues(context, readerContext);
final FunctionValues defaults = (this.defaultVal == null) ? null : defaultVal.getValues(context, readerContext);
return new FloatDocValues(this) {
@Override
public float floatVal(int doc) throws IOException {
float val = vals.floatVal(doc);
return (val >= min && val <= max) ? targets.floatVal(doc) : (defaultVal == null ? val : defaults.floatVal(doc));
}
@Override
public String toString(int doc) throws IOException {
return "map(" + vals.toString(doc) + ",min=" + min + ",max=" + max + ",target=" + targets.toString(doc) + ",defaultVal=" + (defaults == null ? "null" : (defaults.toString(doc))) + ")";
}
};
}
use of org.apache.lucene.queries.function.FunctionValues in project lucene-solr by apache.
the class MultiDoubleFunction 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 DoubleDocValues(this) {
@Override
public double doubleVal(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();
}
};
}
use of org.apache.lucene.queries.function.FunctionValues in project lucene-solr by apache.
the class MultiStringFunction 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 StrDocValues(this) {
@Override
public String strVal(int doc) throws IOException {
CharSequence cs = func(doc, valsArr);
return cs != null ? cs.toString() : null;
}
@Override
public boolean exists(int doc) throws IOException {
boolean exists = true;
for (FunctionValues val : valsArr) {
exists = exists & val.exists(doc);
}
return exists;
}
@Override
public boolean bytesVal(int doc, BytesRefBuilder bytes) throws IOException {
bytes.clear();
CharSequence cs = func(doc, valsArr);
if (cs != null) {
bytes.copyChars(func(doc, valsArr));
return true;
} else {
return false;
}
}
@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 MutableValueStr mval = new MutableValueStr();
@Override
public MutableValue getValue() {
return mval;
}
@Override
public void fillValue(int doc) throws IOException {
mval.exists = bytesVal(doc, mval.value);
}
};
}
};
}
use of org.apache.lucene.queries.function.FunctionValues in project lucene-solr by apache.
the class DualDoubleFunction method getValues.
@Override
public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
final FunctionValues aVals = a.getValues(context, readerContext);
final FunctionValues bVals = b.getValues(context, readerContext);
return new DoubleDocValues(this) {
@Override
public double doubleVal(int doc) throws IOException {
return func(doc, aVals, bVals);
}
@Override
public boolean exists(int doc) throws IOException {
return aVals.exists(doc) & bVals.exists(doc);
}
@Override
public String toString(int doc) throws IOException {
return name() + '(' + aVals.toString(doc) + ',' + bVals.toString(doc) + ')';
}
};
}
use of org.apache.lucene.queries.function.FunctionValues 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);
}
};
}
};
}
Aggregations