Java Code Examples for org.apache.lucene.queries.function.FunctionValues#floatVal()
The following examples show how to use
org.apache.lucene.queries.function.FunctionValues#floatVal() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ValueSourceParser.java From lucene-solr with Apache License 2.0 | 6 votes |
@Override public ValueSource parse(FunctionQParser fp) throws SyntaxError { ValueSource a = fp.parseValueSource(); ValueSource b = fp.parseValueSource(); return new DualFloatFunction(a, b) { @Override protected String name() { return "sub"; } @Override protected float func(int doc, FunctionValues aVals, FunctionValues bVals) throws IOException { return aVals.floatVal(doc) - bVals.floatVal(doc); } }; }
Example 2
Source File: NvlValueSourceParser.java From lucene-solr with Apache License 2.0 | 6 votes |
@Override public ValueSource parse(FunctionQParser fp) throws SyntaxError { ValueSource source = fp.parseValueSource(); final float nvl = fp.parseFloat(); return new SimpleFloatFunction(source) { @Override protected String name() { return "nvl"; } @Override protected float func(int doc, FunctionValues vals) throws IOException { float v = vals.floatVal(doc); if (v == nvlFloatValue) { return nvl; } else { return v; } } }; }
Example 3
Source File: SumFloatFunction.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override protected float func(int doc, FunctionValues[] valsArr) throws IOException { float val = 0.0f; for (FunctionValues vals : valsArr) { val += vals.floatVal(doc); } return val; }
Example 4
Source File: ScaleFloatFunction.java From lucene-solr with Apache License 2.0 | 5 votes |
private ScaleInfo createScaleInfo(Map<Object, Object> context, LeafReaderContext readerContext) throws IOException { final List<LeafReaderContext> leaves = ReaderUtil.getTopLevelContext(readerContext).leaves(); float minVal = Float.POSITIVE_INFINITY; float maxVal = Float.NEGATIVE_INFINITY; for (LeafReaderContext leaf : leaves) { int maxDoc = leaf.reader().maxDoc(); FunctionValues vals = source.getValues(context, leaf); for (int i=0; i<maxDoc; i++) { if ( ! vals.exists(i) ) { continue; } float val = vals.floatVal(i); if ((Float.floatToRawIntBits(val) & (0xff<<23)) == 0xff<<23) { // if the exponent in the float is all ones, then this is +Inf, -Inf or NaN // which don't make sense to factor into the scale function continue; } if (val < minVal) { minVal = val; } if (val > maxVal) { maxVal = val; } } } if (minVal == Float.POSITIVE_INFINITY) { // must have been an empty index minVal = maxVal = 0; } ScaleInfo scaleInfo = new ScaleInfo(); scaleInfo.minVal = minVal; scaleInfo.maxVal = maxVal; context.put(ScaleFloatFunction.this, scaleInfo); return scaleInfo; }
Example 5
Source File: ProductFloatFunction.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override protected float func(int doc, FunctionValues[] valsArr) throws IOException { float val = 1.0f; for (FunctionValues vals : valsArr) { val *= vals.floatVal(doc); } return val; }
Example 6
Source File: ValueSourceParser.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override public ValueSource parse(FunctionQParser fp) throws SyntaxError { ValueSource a = fp.parseValueSource(); ValueSource b = fp.parseValueSource(); return new DualFloatFunction(a, b) { @Override protected String name() { return "mod"; } @Override protected float func(int doc, FunctionValues aVals, FunctionValues bVals) throws IOException { return aVals.floatVal(doc) % bVals.floatVal(doc); } }; }
Example 7
Source File: DivFloatFunction.java From lucene-solr with Apache License 2.0 | 4 votes |
@Override protected float func(int doc, FunctionValues aVals, FunctionValues bVals) throws IOException { return aVals.floatVal(doc) / bVals.floatVal(doc); }
Example 8
Source File: AdditiveBoostFunctionTest.java From querqy with Apache License 2.0 | 4 votes |
@Test public void testGradedScoresForNegBoostScoringFunction() throws IOException { when(scoringFunctionValues1.exists(ArgumentMatchers.eq(1))).thenReturn(true); when(scoringFunctionValues1.floatVal(ArgumentMatchers.eq(1))).thenReturn(0f); when(scoringFunctionValues1.exists(ArgumentMatchers.eq(2))).thenReturn(true); when(scoringFunctionValues1.floatVal(ArgumentMatchers.eq(2))).thenReturn(1f); when(scoringFunctionValues1.exists(ArgumentMatchers.eq(3))).thenReturn(true); when(scoringFunctionValues1.floatVal(ArgumentMatchers.eq(3))).thenReturn(4f); final AdditiveBoostFunction func = new AdditiveBoostFunction(scoringFunction1, -20f); final FunctionValues values = func.getValues(new HashMap(), null); float match0Score = values.floatVal(1); float match1Score = values.floatVal(2); float match4Score = values.floatVal(3); assertEquals(20f, match0Score, 0.00001); assertTrue(match1Score < match0Score); assertTrue(match4Score < match1Score); }