use of org.apache.lucene.queries.function.docvalues.BoolDocValues in project lucene-solr by apache.
the class MultiBoolFunction method getValues.
@Override
public BoolDocValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
final FunctionValues[] vals = new FunctionValues[sources.size()];
int i = 0;
for (ValueSource source : sources) {
vals[i++] = source.getValues(context, readerContext);
}
return new BoolDocValues(this) {
@Override
public boolean boolVal(int doc) throws IOException {
return func(doc, vals);
}
@Override
public String toString(int doc) throws IOException {
StringBuilder sb = new StringBuilder(name());
sb.append('(');
boolean first = true;
for (FunctionValues dv : vals) {
if (first) {
first = false;
} else {
sb.append(',');
}
sb.append(dv.toString(doc));
}
return sb.toString();
}
};
}
use of org.apache.lucene.queries.function.docvalues.BoolDocValues in project lucene-solr by apache.
the class ComparisonBoolFunction method getValues.
@Override
public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
final FunctionValues lhsVal = this.lhs.getValues(context, readerContext);
final FunctionValues rhsVal = this.rhs.getValues(context, readerContext);
final String compLabel = this.name();
return new BoolDocValues(this) {
@Override
public boolean boolVal(int doc) throws IOException {
return compare(doc, lhsVal, rhsVal);
}
@Override
public String toString(int doc) throws IOException {
return compLabel + "(" + lhsVal.toString(doc) + "," + rhsVal.toString(doc) + ")";
}
@Override
public boolean exists(int doc) throws IOException {
return lhsVal.exists(doc) && rhsVal.exists(doc);
}
};
}
use of org.apache.lucene.queries.function.docvalues.BoolDocValues in project lucene-solr by apache.
the class BoolFieldSource method getValues.
@Override
public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
final SortedDocValues sindex = DocValues.getSorted(readerContext.reader(), field);
// figure out what ord maps to true
int nord = sindex.getValueCount();
// if no values in the segment, default trueOrd to something other then -1 (missing)
int tord = -2;
for (int i = 0; i < nord; i++) {
final BytesRef br = sindex.lookupOrd(i);
if (br.length == 1 && br.bytes[br.offset] == 'T') {
tord = i;
break;
}
}
final int trueOrd = tord;
return new BoolDocValues(this) {
private int getOrdForDoc(int doc) throws IOException {
if (doc > sindex.docID()) {
sindex.advance(doc);
}
if (doc == sindex.docID()) {
return sindex.ordValue();
} else {
return -1;
}
}
@Override
public boolean boolVal(int doc) throws IOException {
return getOrdForDoc(doc) == trueOrd;
}
@Override
public boolean exists(int doc) throws IOException {
return getOrdForDoc(doc) != -1;
}
@Override
public ValueFiller getValueFiller() {
return new ValueFiller() {
private final MutableValueBool mval = new MutableValueBool();
@Override
public MutableValue getValue() {
return mval;
}
@Override
public void fillValue(int doc) throws IOException {
int ord = getOrdForDoc(doc);
mval.value = (ord == trueOrd);
mval.exists = (ord != -1);
}
};
}
};
}
use of org.apache.lucene.queries.function.docvalues.BoolDocValues in project lucene-solr by apache.
the class ShapePredicateValueSource method getValues.
@Override
public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
final FunctionValues shapeValues = shapeValuesource.getValues(context, readerContext);
return new BoolDocValues(this) {
@Override
public boolean boolVal(int doc) throws IOException {
Shape indexedShape = (Shape) shapeValues.objectVal(doc);
if (indexedShape == null)
return false;
return op.evaluate(indexedShape, queryShape);
}
@Override
public Explanation explain(int doc) throws IOException {
Explanation exp = super.explain(doc);
List<Explanation> details = new ArrayList<>(Arrays.asList(exp.getDetails()));
details.add(shapeValues.explain(doc));
return Explanation.match(exp.getValue(), exp.getDescription(), details);
}
};
}
Aggregations