List of usage examples for org.apache.lucene.queries.function FunctionValues objectVal
public Object objectVal(int doc) throws IOException
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 . j av a 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.response.transform.ValueSourceAugmenter.java
License:Apache License
@Override public void transform(SolrDocument doc, int docid) { // This is only good for random-access functions try {// w ww. ja va 2s . c o m // TODO: calculate this stuff just once across diff functions int idx = ReaderUtil.subIndex(docid, readerContexts); AtomicReaderContext rcontext = readerContexts.get(idx); FunctionValues values = docValuesArr[idx]; if (values == null) { docValuesArr[idx] = values = valueSource.getValues(fcontext, rcontext); } int localId = docid - rcontext.docBase; Object val = values.objectVal(localId); if (val != null) { doc.setField(name, val); } } catch (IOException e) { throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "exception at docid " + docid + " for valuesource " + valueSource, e); } }
From source file:org.apache.solr.schema.DocValuesTest.java
License:Apache License
public void testDocValues() throws IOException { assertU(adoc("id", "1")); commit();// ww w. j a v a 2 s .c om 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(); } }