APISonar


org.elasticsearch.common.lucene.search.function.FieldValueFactorFunction.Modifier.LOG

> org > elasticsearch > common > lucene > search > function > FieldValueFactorFunction > Modifier > LOG
org APIs elasticsearch APIs common APIs lucene APIs search APIs function APIs FieldValueFactorFunction APIs Modifier APIs LOG APIs

Example 1
public void testExceptionOnLogNegativeScores() {
        IndexSearcher localSearcher = new IndexSearcher(reader);
        TermQuery termQuery = new TermQuery(new Term(FIELD, "out"));

        // test that field_value_factor function using modifier log throws an exception on negative scores
        FieldValueFactorFunction.Modifier modifier = FieldValueFactorFunction.Modifier.LOG;
        final ScoreFunction fvfFunction = new FieldValueFactorFunction(FIELD, 0.5f, modifier, 1.0, new IndexNumericFieldDataStub());
        FunctionScoreQuery fsQuery1 =
                new FunctionScoreQuery(termQuery, fvfFunction, CombineFunction.REPLACE, null, Float.POSITIVE_INFINITY);
        IllegalArgumentException exc = expectThrows(IllegalArgumentException.class, () -> localSearcher.search(fsQuery1, 1));
        assertThat(exc.getMessage(), containsString("consider using log1p or log2p instead of log to avoid negative scores"));
    }