Search in sources :

Example 1 with RangeMapFloatFunction

use of org.apache.lucene.queries.function.valuesource.RangeMapFloatFunction in project lucene-solr by apache.

the class TestValueSources method testRangeMap.

public void testRangeMap() throws Exception {
    assertHits(new FunctionQuery(new RangeMapFloatFunction(new FloatFieldSource("float"), 5, 6, 1, 0f)), new float[] { 1f, 0f });
    assertHits(new FunctionQuery(new RangeMapFloatFunction(new FloatFieldSource("float"), 5, 6, new SumFloatFunction(new ValueSource[] { new ConstValueSource(1f), new ConstValueSource(2f) }), new ConstValueSource(11f))), new float[] { 3f, 11f });
// TODO: what *should* the rules be for exist() ?
// ((source exists && source in range && target exists) OR (source not in range && default exists)) ?
}
Also used : RangeMapFloatFunction(org.apache.lucene.queries.function.valuesource.RangeMapFloatFunction) FloatFieldSource(org.apache.lucene.queries.function.valuesource.FloatFieldSource) MultiValuedFloatFieldSource(org.apache.lucene.queries.function.valuesource.MultiValuedFloatFieldSource) SumTotalTermFreqValueSource(org.apache.lucene.queries.function.valuesource.SumTotalTermFreqValueSource) DoubleConstValueSource(org.apache.lucene.queries.function.valuesource.DoubleConstValueSource) ConstValueSource(org.apache.lucene.queries.function.valuesource.ConstValueSource) QueryValueSource(org.apache.lucene.queries.function.valuesource.QueryValueSource) DocFreqValueSource(org.apache.lucene.queries.function.valuesource.DocFreqValueSource) NormValueSource(org.apache.lucene.queries.function.valuesource.NormValueSource) NumDocsValueSource(org.apache.lucene.queries.function.valuesource.NumDocsValueSource) MaxDocValueSource(org.apache.lucene.queries.function.valuesource.MaxDocValueSource) JoinDocFreqValueSource(org.apache.lucene.queries.function.valuesource.JoinDocFreqValueSource) LiteralValueSource(org.apache.lucene.queries.function.valuesource.LiteralValueSource) TotalTermFreqValueSource(org.apache.lucene.queries.function.valuesource.TotalTermFreqValueSource) IDFValueSource(org.apache.lucene.queries.function.valuesource.IDFValueSource) TermFreqValueSource(org.apache.lucene.queries.function.valuesource.TermFreqValueSource) TFValueSource(org.apache.lucene.queries.function.valuesource.TFValueSource) SumFloatFunction(org.apache.lucene.queries.function.valuesource.SumFloatFunction) DoubleConstValueSource(org.apache.lucene.queries.function.valuesource.DoubleConstValueSource) ConstValueSource(org.apache.lucene.queries.function.valuesource.ConstValueSource)

Example 2 with RangeMapFloatFunction

use of org.apache.lucene.queries.function.valuesource.RangeMapFloatFunction in project lucene-solr by apache.

the class TestFunctionQueryExplanations method testMapFunction.

public void testMapFunction() throws Exception {
    ValueSource rff = new RangeMapFloatFunction(new ConstValueSource(3), 0, 1, 2, new Float(4));
    Query q = new FunctionQuery(rff);
    qtest(q, new int[] { 0, 1, 2, 3 });
    assertEquals("map(const(3.0),0.0,1.0,const(2.0),const(4.0))", rff.description());
    assertEquals("map(const(3.0),min=0.0,max=1.0,target=const(2.0),defaultVal=const(4.0))", rff.getValues(null, null).toString(123));
    // DefaultValue is null -> defaults to source value
    rff = new RangeMapFloatFunction(new ConstValueSource(3), 0, 1, 2, null);
    assertEquals("map(const(3.0),0.0,1.0,const(2.0),null)", rff.description());
    assertEquals("map(const(3.0),min=0.0,max=1.0,target=const(2.0),defaultVal=null)", rff.getValues(null, null).toString(123));
}
Also used : RangeMapFloatFunction(org.apache.lucene.queries.function.valuesource.RangeMapFloatFunction) Query(org.apache.lucene.search.Query) BoostQuery(org.apache.lucene.search.BoostQuery) ConstValueSource(org.apache.lucene.queries.function.valuesource.ConstValueSource) ConstValueSource(org.apache.lucene.queries.function.valuesource.ConstValueSource)

Aggregations

ConstValueSource (org.apache.lucene.queries.function.valuesource.ConstValueSource)2 RangeMapFloatFunction (org.apache.lucene.queries.function.valuesource.RangeMapFloatFunction)2 DocFreqValueSource (org.apache.lucene.queries.function.valuesource.DocFreqValueSource)1 DoubleConstValueSource (org.apache.lucene.queries.function.valuesource.DoubleConstValueSource)1 FloatFieldSource (org.apache.lucene.queries.function.valuesource.FloatFieldSource)1 IDFValueSource (org.apache.lucene.queries.function.valuesource.IDFValueSource)1 JoinDocFreqValueSource (org.apache.lucene.queries.function.valuesource.JoinDocFreqValueSource)1 LiteralValueSource (org.apache.lucene.queries.function.valuesource.LiteralValueSource)1 MaxDocValueSource (org.apache.lucene.queries.function.valuesource.MaxDocValueSource)1 MultiValuedFloatFieldSource (org.apache.lucene.queries.function.valuesource.MultiValuedFloatFieldSource)1 NormValueSource (org.apache.lucene.queries.function.valuesource.NormValueSource)1 NumDocsValueSource (org.apache.lucene.queries.function.valuesource.NumDocsValueSource)1 QueryValueSource (org.apache.lucene.queries.function.valuesource.QueryValueSource)1 SumFloatFunction (org.apache.lucene.queries.function.valuesource.SumFloatFunction)1 SumTotalTermFreqValueSource (org.apache.lucene.queries.function.valuesource.SumTotalTermFreqValueSource)1 TFValueSource (org.apache.lucene.queries.function.valuesource.TFValueSource)1 TermFreqValueSource (org.apache.lucene.queries.function.valuesource.TermFreqValueSource)1 TotalTermFreqValueSource (org.apache.lucene.queries.function.valuesource.TotalTermFreqValueSource)1 BoostQuery (org.apache.lucene.search.BoostQuery)1 Query (org.apache.lucene.search.Query)1