Search in sources :

Example 1 with BoolDocValues

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();
        }
    };
}
Also used : ValueSource(org.apache.lucene.queries.function.ValueSource) BoolDocValues(org.apache.lucene.queries.function.docvalues.BoolDocValues) FunctionValues(org.apache.lucene.queries.function.FunctionValues)

Example 2 with BoolDocValues

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);
        }
    };
}
Also used : BoolDocValues(org.apache.lucene.queries.function.docvalues.BoolDocValues) FunctionValues(org.apache.lucene.queries.function.FunctionValues)

Example 3 with BoolDocValues

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);
                }
            };
        }
    };
}
Also used : BoolDocValues(org.apache.lucene.queries.function.docvalues.BoolDocValues) MutableValueBool(org.apache.lucene.util.mutable.MutableValueBool) SortedDocValues(org.apache.lucene.index.SortedDocValues) BytesRef(org.apache.lucene.util.BytesRef)

Example 4 with BoolDocValues

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);
        }
    };
}
Also used : Shape(org.locationtech.spatial4j.shape.Shape) Explanation(org.apache.lucene.search.Explanation) BoolDocValues(org.apache.lucene.queries.function.docvalues.BoolDocValues) ArrayList(java.util.ArrayList) FunctionValues(org.apache.lucene.queries.function.FunctionValues)

Aggregations

BoolDocValues (org.apache.lucene.queries.function.docvalues.BoolDocValues)4 FunctionValues (org.apache.lucene.queries.function.FunctionValues)3 ArrayList (java.util.ArrayList)1 SortedDocValues (org.apache.lucene.index.SortedDocValues)1 ValueSource (org.apache.lucene.queries.function.ValueSource)1 Explanation (org.apache.lucene.search.Explanation)1 BytesRef (org.apache.lucene.util.BytesRef)1 MutableValueBool (org.apache.lucene.util.mutable.MutableValueBool)1 Shape (org.locationtech.spatial4j.shape.Shape)1