@Override protected float func(int doc, FunctionValues[] valsArr) { if (valsArr.length == 0) return 0.0f; float val = Float.POSITIVE_INFINITY; for (FunctionValues vals : valsArr) { val = Math.min(vals.floatVal(doc), val); } return val; }
@Override protected void doSetNextReader(LeafReaderContext context) throws IOException { FunctionValues values = groupSource.getValues(vsContext, context); groupFiller = values.getValueFiller(); groupMval = groupFiller.getValue(); values = countSource.getValues(vsContext, context); countFiller = values.getValueFiller(); countMval = countFiller.getValue(); }
public void testDocValues() throws IOException { assertU(adoc("id", "1")); assertU(commit()); try (SolrCore core = h.getCoreInc()) { final RefCounted<SolrIndexSearcher> searcherRef = core.openNewSearcher(true, true); final SolrIndexSearcher searcher = searcherRef.get(); try { final LeafReader reader = searcher.getLeafReader(); 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.getLeafReader().leaves().get(0)); assertEquals(1f, values.floatVal(0), 0f); assertEquals(1f, values.objectVal(0)); values = intDv .getType() .getValueSource(intDv, null) .getValues(null, searcher.getLeafReader().leaves().get(0)); assertEquals(2, values.intVal(0)); assertEquals(2, values.objectVal(0)); values = doubleDv .getType() .getValueSource(doubleDv, null) .getValues(null, searcher.getLeafReader().leaves().get(0)); assertEquals(3d, values.doubleVal(0), 0d); assertEquals(3d, values.objectVal(0)); values = longDv .getType() .getValueSource(longDv, null) .getValues(null, searcher.getLeafReader().leaves().get(0)); assertEquals(4L, values.longVal(0)); assertEquals(4L, values.objectVal(0)); } finally { searcherRef.decref(); } } }
public void collapse(int ord, int contextDoc, int globalDoc) throws IOException { if (needsScores || cscore) { this.score = scorer.score(); this.collapseScore.score = score; } float val = functionValues.floatVal(contextDoc); if (ord > -1) { if (comp.test(val, ordVals[ord])) { ords[ord] = globalDoc; ordVals[ord] = val; if (needsScores) { scores[ord] = score; } } } else if (this.collapsedSet.get(globalDoc)) { // Elevated doc so do nothing } else if (this.nullPolicy == CollapsingPostFilter.NULL_POLICY_COLLAPSE) { if (comp.test(val, nullVal)) { nullVal = val; nullDoc = globalDoc; if (needsScores) { nullScore = score; } } } else if (this.nullPolicy == CollapsingPostFilter.NULL_POLICY_EXPAND) { this.collapsedSet.set(globalDoc); if (needsScores) { nullScores.add(score); } } }
protected double func(int doc, FunctionValues vals) throws IOException { double d = vals.doubleVal(doc); if (d < 0) { return d * -1; } else { return d; } }
@Override public void transform(SolrDocument doc, int docid) { // This is only good for random-access functions try { // TODO: calculate this stuff just once across diff functions int idx = ReaderUtil.subIndex(docid, readerContexts); LeafReaderContext rcontext = readerContexts.get(idx); FunctionValues values = docValuesArr[idx]; if (values == null) { docValuesArr[idx] = values = valueSource.getValues(fcontext, rcontext); } int localId = docid - rcontext.docBase; setValue(doc, values.objectVal(localId)); } catch (IOException e) { throw new SolrException( SolrException.ErrorCode.SERVER_ERROR, "exception at docid " + docid + " for valuesource " + valueSource, e); } }