Example usage for org.apache.lucene.queries.function.docvalues BoolDocValues BoolDocValues

List of usage examples for org.apache.lucene.queries.function.docvalues BoolDocValues BoolDocValues

Introduction

In this page you can find the example usage for org.apache.lucene.queries.function.docvalues BoolDocValues BoolDocValues.

Prototype

public BoolDocValues(ValueSource vs) 

Source Link

Usage

From source file:alba.solr.docvalues.FunctionExecutor.java

License:Apache License

@Override
public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
    final Map<String, FunctionValues> valsMap = this.valsMap(sources, context, readerContext);

    final CallableFunction fn = this.function;

    FunctionExecutor host = this;

    if ((this.function.getReturnType() == Boolean.class) || (this.function.getReturnType() == boolean.class)) {
        logger.error("calling boolean function!");
        return new BoolDocValues(this.sources.get(0)) {

            @Override//  w ww.  ja  v  a2 s .c  o m
            public boolean boolVal(int doc) {
                // TODO Auto-generated method stub
                Object[] objParams = host.populateObjParams(valsMap, doc);
                return host.getBooleanResult(fn, objParams);
            }
        };
    } else if (this.function.getReturnType() == Double.class) {
        return new DoubleDocValues(this.sources.get(0)) {

            @Override
            public double doubleVal(int doc) {
                // TODO Auto-generated method stub
                return 12.0d;
            }
        };
    } else if (this.function.getReturnType() == String.class) {
        return new StrDocValues(this.vs) {
            @Override
            public String strVal(int doc) {
                Object[] objParams = host.populateObjParams(valsMap, doc);
                return host.getStringResult(fn, objParams);
            }
        };
    } else if (this.function.getReturnType() == Float.class) {
        return new FloatDocValues(this.sources.get(0)) {

            @Override
            public float floatVal(int doc) {
                // TODO Auto-generated method stub
                Object[] objParams = host.populateObjParams(valsMap, doc);
                return host.getFloatResult(fn, objParams, doc);
            }
        };
    } else if ((this.function.getReturnType() == Integer.class)) {
        // with this snippet of code we could avoid to instantiate a new object of type IntDocValues
        // simply by using the existing instance of WrappedIntDocValues.
        // but.. this cause a crash :(
        // wrappedIntDocValues.setFunction(fn);
        // wrappedIntDocValues.setExpectedParams(this.expectedParams);
        // return wrappedIntDocValues;

        // so for now, just go on with the good old new instance of IntDocValues

        return new IntDocValues(this.sources.get(0)) {

            @Override
            public int intVal(int doc) {
                // TODO Auto-generated method stub

                Object[] objParams = host.populateObjParams(valsMap, doc);
                return host.getIntegerResult(fn, objParams, doc);

            }

        };
    }

    //apparently we dind't find an appropriate DocValues for this function.
    //it could be a function which should generate two or more additional fields in the resulting docs
    //but HOW can we do that??? 
    //for now, just return a null, so no field will be added.
    host.ping2caller();

    logger.error("I don't know how to deal with class " + this.function.getReturnType()
            + ", check FunctionExecutor.java");

    /*
     * instanziare e restituire x forza un DocValues altrimenti non valorizza i parametri!!
     * poi in doctransformer togliere questo campo (capire come!)
     */
    IntDocValues dd = new IntDocValues(this.vs) {

        @Override
        public int intVal(int doc) {
            // TODO Auto-generated method stub

            Object[] objParams = host.populateObjParams(valsMap, doc);
            try {
                host.function.getMethod().invoke(fn.getInstance(), objParams);
            } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
                // TODO Auto-generated catch block
                logger.error("argggg", e);
            }
            return 0; //we're not going to use this value

        }

    };
    return dd; // new StrFunctionValue(null);

}

From source file:org.apache.solr.schema.BoolField.java

License:Apache License

@Override
public FunctionValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
    final SortedDocValues sindex = FieldCache.DEFAULT.getTermsIndex(readerContext.reader(), field);

    // figure out what ord maps to true
    int nord = sindex.getValueCount();
    BytesRef br = new BytesRef();
    // if no values in the segment, default trueOrd to something other then -1 (missing)
    int tord = -2;
    for (int i = 0; i < nord; i++) {
        sindex.lookupOrd(i, br);/*  w ww . j av  a 2 s .  c  o m*/
        if (br.length == 1 && br.bytes[br.offset] == 'T') {
            tord = i;
            break;
        }
    }

    final int trueOrd = tord;

    return new BoolDocValues(this) {
        @Override
        public boolean boolVal(int doc) {
            return sindex.getOrd(doc) == trueOrd;
        }

        @Override
        public boolean exists(int doc) {
            return sindex.getOrd(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) {
                    int ord = sindex.getOrd(doc);
                    mval.value = (ord == trueOrd);
                    mval.exists = (ord != -1);
                }
            };
        }
    };
}

From source file:org.apache.solr.search.ValueSourceParser.java

License:Apache License

@Override
public FunctionValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
    return new BoolDocValues(this) {
        @Override/* w ww . j  a  va  2 s  .  com*/
        public boolean boolVal(int doc) {
            return constant;
        }
    };
}