use of org.apache.lucene.queries.function.FunctionValues in project lucene-solr by apache.
the class VectorValueSource method getValues.
@Override
public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
int size = sources.size();
// special-case x,y and lat,lon since it's so common
if (size == 2) {
final FunctionValues x = sources.get(0).getValues(context, readerContext);
final FunctionValues y = sources.get(1).getValues(context, readerContext);
return new FunctionValues() {
@Override
public void byteVal(int doc, byte[] vals) throws IOException {
vals[0] = x.byteVal(doc);
vals[1] = y.byteVal(doc);
}
@Override
public void shortVal(int doc, short[] vals) throws IOException {
vals[0] = x.shortVal(doc);
vals[1] = y.shortVal(doc);
}
@Override
public void intVal(int doc, int[] vals) throws IOException {
vals[0] = x.intVal(doc);
vals[1] = y.intVal(doc);
}
@Override
public void longVal(int doc, long[] vals) throws IOException {
vals[0] = x.longVal(doc);
vals[1] = y.longVal(doc);
}
@Override
public void floatVal(int doc, float[] vals) throws IOException {
vals[0] = x.floatVal(doc);
vals[1] = y.floatVal(doc);
}
@Override
public void doubleVal(int doc, double[] vals) throws IOException {
vals[0] = x.doubleVal(doc);
vals[1] = y.doubleVal(doc);
}
@Override
public void strVal(int doc, String[] vals) throws IOException {
vals[0] = x.strVal(doc);
vals[1] = y.strVal(doc);
}
@Override
public String toString(int doc) throws IOException {
return name() + "(" + x.toString(doc) + "," + y.toString(doc) + ")";
}
};
}
final FunctionValues[] valsArr = new FunctionValues[size];
for (int i = 0; i < size; i++) {
valsArr[i] = sources.get(i).getValues(context, readerContext);
}
return new FunctionValues() {
@Override
public void byteVal(int doc, byte[] vals) throws IOException {
for (int i = 0; i < valsArr.length; i++) {
vals[i] = valsArr[i].byteVal(doc);
}
}
@Override
public void shortVal(int doc, short[] vals) throws IOException {
for (int i = 0; i < valsArr.length; i++) {
vals[i] = valsArr[i].shortVal(doc);
}
}
@Override
public void floatVal(int doc, float[] vals) throws IOException {
for (int i = 0; i < valsArr.length; i++) {
vals[i] = valsArr[i].floatVal(doc);
}
}
@Override
public void intVal(int doc, int[] vals) throws IOException {
for (int i = 0; i < valsArr.length; i++) {
vals[i] = valsArr[i].intVal(doc);
}
}
@Override
public void longVal(int doc, long[] vals) throws IOException {
for (int i = 0; i < valsArr.length; i++) {
vals[i] = valsArr[i].longVal(doc);
}
}
@Override
public void doubleVal(int doc, double[] vals) throws IOException {
for (int i = 0; i < valsArr.length; i++) {
vals[i] = valsArr[i].doubleVal(doc);
}
}
@Override
public void strVal(int doc, String[] vals) throws IOException {
for (int i = 0; i < valsArr.length; i++) {
vals[i] = valsArr[i].strVal(doc);
}
}
@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 FilterFieldSource method getValues.
@Override
public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
final FunctionValues vals = source.getValues(context, readerContext);
return new FunctionValues() {
@Override
public byte byteVal(int doc) throws IOException {
return vals.byteVal(doc);
}
@Override
public short shortVal(int doc) throws IOException {
return vals.shortVal(doc);
}
@Override
public float floatVal(int doc) throws IOException {
return vals.floatVal(doc);
}
@Override
public int intVal(int doc) throws IOException {
return vals.intVal(doc);
}
@Override
public long longVal(int doc) throws IOException {
return vals.longVal(doc);
}
@Override
public double doubleVal(int doc) throws IOException {
return vals.doubleVal(doc);
}
@Override
public String strVal(int doc) throws IOException {
return vals.strVal(doc);
}
@Override
public Object objectVal(int doc) throws IOException {
return exists(doc) ? vals.objectVal(doc) : null;
}
@Override
public boolean exists(int doc) throws IOException {
Object other = vals.objectVal(doc);
return other != null && !missValue.equals(other);
}
@Override
public String toString(int doc) throws IOException {
return NAME + '(' + vals.toString(doc) + ')';
}
@Override
public ValueFiller getValueFiller() {
return new ValueFiller() {
private final ValueFiller delegateFiller = vals.getValueFiller();
private final MutableValue mval = delegateFiller.getValue();
@Override
public MutableValue getValue() {
return mval;
}
@Override
public void fillValue(int doc) throws IOException {
delegateFiller.fillValue(doc);
mval.exists = exists(doc);
}
};
}
};
}
use of org.apache.lucene.queries.function.FunctionValues in project lucene-solr by apache.
the class GeohashFunction method getValues.
@Override
public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
final FunctionValues latDV = lat.getValues(context, readerContext);
final FunctionValues lonDV = lon.getValues(context, readerContext);
return new FunctionValues() {
@Override
public String strVal(int doc) throws IOException {
return GeohashUtils.encodeLatLon(latDV.doubleVal(doc), lonDV.doubleVal(doc));
}
@Override
public String toString(int doc) throws IOException {
StringBuilder sb = new StringBuilder();
sb.append(name()).append('(');
sb.append(latDV.toString(doc)).append(',').append(lonDV.toString(doc));
sb.append(')');
return sb.toString();
}
};
}
use of org.apache.lucene.queries.function.FunctionValues in project lucene-solr by apache.
the class GeohashHaversineFunction method getValues.
@Override
public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
final FunctionValues gh1DV = geoHash1.getValues(context, readerContext);
final FunctionValues gh2DV = geoHash2.getValues(context, readerContext);
return new DoubleDocValues(this) {
@Override
public double doubleVal(int doc) throws IOException {
return distance(doc, gh1DV, gh2DV);
}
@Override
public String toString(int doc) throws IOException {
StringBuilder sb = new StringBuilder();
sb.append(name()).append('(');
sb.append(gh1DV.toString(doc)).append(',').append(gh2DV.toString(doc));
sb.append(')');
return sb.toString();
}
};
}
use of org.apache.lucene.queries.function.FunctionValues in project lucene-solr by apache.
the class HaversineFunction method getValues.
@Override
public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
final FunctionValues vals1 = p1.getValues(context, readerContext);
final FunctionValues vals2 = p2.getValues(context, readerContext);
return new DoubleDocValues(this) {
@Override
public double doubleVal(int doc) throws IOException {
return distance(doc, vals1, vals2);
}
@Override
public String toString(int doc) throws IOException {
StringBuilder sb = new StringBuilder();
sb.append(name()).append('(');
sb.append(vals1.toString(doc)).append(',').append(vals2.toString(doc));
sb.append(')');
return sb.toString();
}
};
}
Aggregations