Search in sources :

Example 1 with MutableValueBool

use of org.apache.lucene.util.mutable.MutableValueBool in project lucene-solr by apache.

the class BoolDocValues method getValueFiller.

@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 {
            mval.value = boolVal(doc);
            mval.exists = exists(doc);
        }
    };
}
Also used : MutableValueBool(org.apache.lucene.util.mutable.MutableValueBool)

Example 2 with MutableValueBool

use of org.apache.lucene.util.mutable.MutableValueBool 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)

Aggregations

MutableValueBool (org.apache.lucene.util.mutable.MutableValueBool)2 SortedDocValues (org.apache.lucene.index.SortedDocValues)1 BoolDocValues (org.apache.lucene.queries.function.docvalues.BoolDocValues)1 BytesRef (org.apache.lucene.util.BytesRef)1