Example usage for org.apache.lucene.queries.function FunctionValues doubleVal

List of usage examples for org.apache.lucene.queries.function FunctionValues doubleVal

Introduction

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

Prototype

public double doubleVal(int doc) throws IOException 

Source Link

Usage

From source file:org.apache.solr.analytics.util.valuesource.AbsoluteValueDoubleFunction.java

License:Apache License

protected double func(int doc, FunctionValues vals) {
    double d = vals.doubleVal(doc);
    if (d < 0) {
        return d * -1;
    } else {/*from  ww  w  . j  a va 2s . co  m*/
        return d;
    }
}

From source file:org.apache.solr.analytics.util.valuesource.AddDoubleFunction.java

License:Apache License

@Override
protected double func(int doc, FunctionValues[] valsArr) {
    double sum = 0d;
    for (FunctionValues val : valsArr) {
        sum += val.doubleVal(doc);
    }/*ww  w .  j  av  a2s  . c  om*/
    return sum;
}

From source file:org.apache.solr.analytics.util.valuesource.DivDoubleFunction.java

License:Apache License

@Override
protected double func(int doc, FunctionValues aVals, FunctionValues bVals) {
    return aVals.doubleVal(doc) / bVals.doubleVal(doc);
}

From source file:org.apache.solr.analytics.util.valuesource.FilterFieldSource.java

License:Apache License

@Override
public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
    final FunctionValues vals = source.getValues(context, readerContext);
    return new FunctionValues() {

        @Override/*  w  w  w .  ja va  2s  .c  o  m*/
        public byte byteVal(int doc) {
            return vals.byteVal(doc);
        }

        @Override
        public short shortVal(int doc) {
            return vals.shortVal(doc);
        }

        @Override
        public float floatVal(int doc) {
            return vals.floatVal(doc);
        }

        @Override
        public int intVal(int doc) {
            return vals.intVal(doc);
        }

        @Override
        public long longVal(int doc) {
            return vals.longVal(doc);
        }

        @Override
        public double doubleVal(int doc) {
            return vals.doubleVal(doc);
        }

        @Override
        public String strVal(int doc) {
            return vals.strVal(doc);
        }

        @Override
        public Object objectVal(int doc) {
            return exists(doc) ? vals.objectVal(doc) : null;
        }

        @Override
        public boolean exists(int doc) {
            Object other = vals.objectVal(doc);
            return other != null && !missValue.equals(other);
        }

        @Override
        public String toString(int doc) {
            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) {
                    delegateFiller.fillValue(doc);
                    mval.exists = exists(doc);
                }
            };
        }
    };
}

From source file:org.apache.solr.analytics.util.valuesource.LogDoubleFunction.java

License:Apache License

@Override
protected double func(int doc, FunctionValues aVals, FunctionValues bVals) {
    return Math.log(aVals.doubleVal(doc)) / Math.log(bVals.doubleVal(doc));
}

From source file:org.apache.solr.analytics.util.valuesource.MultiplyDoubleFunction.java

License:Apache License

@Override
protected double func(int doc, FunctionValues[] valsArr) {
    double product = 1d;
    for (FunctionValues val : valsArr) {
        product *= val.doubleVal(doc);
    }/*from  w w w.j  av a2  s .  c o  m*/
    return product;
}

From source file:org.apache.solr.analytics.util.valuesource.NegateDoubleFunction.java

License:Apache License

protected double func(int doc, FunctionValues vals) {
    return vals.doubleVal(doc) * -1;
}

From source file:org.apache.solr.analytics.util.valuesource.PowDoubleFunction.java

License:Apache License

@Override
protected double func(int doc, FunctionValues aVals, FunctionValues bVals) {
    return Math.pow(aVals.doubleVal(doc), bVals.doubleVal(doc));
}

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

License:Apache License

public void testDocValues() throws IOException {
    assertU(adoc("id", "1"));
    commit();//from   w  w w . j a v a2 s.  c  o m
    SolrCore core = h.getCoreInc();
    try {
        final RefCounted<SolrIndexSearcher> searcherRef = core.openNewSearcher(true, true);
        final SolrIndexSearcher searcher = searcherRef.get();
        try {
            final AtomicReader reader = searcher.getAtomicReader();
            assertEquals(1, reader.numDocs());
            final FieldInfos infos = reader.getFieldInfos();
            assertEquals(DocValuesType.NUMERIC, infos.fieldInfo("floatdv").getDocValuesType());
            assertEquals(DocValuesType.NUMERIC, infos.fieldInfo("intdv").getDocValuesType());
            assertEquals(DocValuesType.NUMERIC, infos.fieldInfo("doubledv").getDocValuesType());
            assertEquals(DocValuesType.NUMERIC, infos.fieldInfo("longdv").getDocValuesType());
            assertEquals(DocValuesType.SORTED, infos.fieldInfo("stringdv").getDocValuesType());

            assertEquals((long) Float.floatToIntBits(1), reader.getNumericDocValues("floatdv").get(0));
            assertEquals(2L, reader.getNumericDocValues("intdv").get(0));
            assertEquals(Double.doubleToLongBits(3), reader.getNumericDocValues("doubledv").get(0));
            assertEquals(4L, reader.getNumericDocValues("longdv").get(0));

            final IndexSchema schema = core.getLatestSchema();
            final SchemaField floatDv = schema.getField("floatdv");
            final SchemaField intDv = schema.getField("intdv");
            final SchemaField doubleDv = schema.getField("doubledv");
            final SchemaField longDv = schema.getField("longdv");

            FunctionValues values = floatDv.getType().getValueSource(floatDv, null).getValues(null,
                    searcher.getAtomicReader().leaves().get(0));
            assertEquals(1f, values.floatVal(0), 0f);
            assertEquals(1f, values.objectVal(0));
            values = intDv.getType().getValueSource(intDv, null).getValues(null,
                    searcher.getAtomicReader().leaves().get(0));
            assertEquals(2, values.intVal(0));
            assertEquals(2, values.objectVal(0));
            values = doubleDv.getType().getValueSource(doubleDv, null).getValues(null,
                    searcher.getAtomicReader().leaves().get(0));
            assertEquals(3d, values.doubleVal(0), 0d);
            assertEquals(3d, values.objectVal(0));
            values = longDv.getType().getValueSource(longDv, null).getValues(null,
                    searcher.getAtomicReader().leaves().get(0));
            assertEquals(4L, values.longVal(0));
            assertEquals(4L, values.objectVal(0));
        } finally {
            searcherRef.decref();
        }
    } finally {
        core.close();
    }
}

From source file:org.apache.solr.search.function.distance.GeohashFunction.java

License:Apache License

@Override
public FunctionValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
    final FunctionValues latDV = lat.getValues(context, readerContext);
    final FunctionValues lonDV = lon.getValues(context, readerContext);

    return new FunctionValues() {

        @Override/*  ww w .jav a 2  s . c  o m*/
        public String strVal(int doc) {
            return GeohashUtils.encodeLatLon(latDV.doubleVal(doc), lonDV.doubleVal(doc));
        }

        @Override
        public String toString(int doc) {
            StringBuilder sb = new StringBuilder();
            sb.append(name()).append('(');
            sb.append(latDV.toString(doc)).append(',').append(lonDV.toString(doc));
            sb.append(')');
            return sb.toString();
        }
    };
}