use of org.apache.lucene.queries.function.valuesource.ConstValueSource in project lucene-solr by apache.
the class TestValueSources method testDiv.
public void testDiv() throws Exception {
ValueSource vs = new DivFloatFunction(new ConstValueSource(10f), new ConstValueSource(5f));
assertHits(new FunctionQuery(vs), new float[] { 2f, 2f });
assertAllExist(vs);
vs = new DivFloatFunction(new ConstValueSource(10f), BOGUS_FLOAT_VS);
assertNoneExist(vs);
vs = new DivFloatFunction(BOGUS_FLOAT_VS, new ConstValueSource(10f));
assertNoneExist(vs);
}
use of org.apache.lucene.queries.function.valuesource.ConstValueSource in project lucene-solr by apache.
the class TestValueSources method testQueryWrapedFuncWrapedQuery.
public void testQueryWrapedFuncWrapedQuery() throws Exception {
ValueSource vs = new QueryValueSource(new FunctionQuery(new ConstValueSource(2f)), 0f);
assertHits(new FunctionQuery(vs), new float[] { 2f, 2f });
assertAllExist(vs);
}
use of org.apache.lucene.queries.function.valuesource.ConstValueSource in project lucene-solr by apache.
the class TestValueSources method testSumFloat.
public void testSumFloat() throws Exception {
ValueSource vs = new SumFloatFunction(new ValueSource[] { new ConstValueSource(1f), new ConstValueSource(2f) });
assertHits(new FunctionQuery(vs), new float[] { 3f, 3f });
assertAllExist(vs);
vs = new SumFloatFunction(new ValueSource[] { BOGUS_FLOAT_VS, new ConstValueSource(2f) });
assertNoneExist(vs);
}
use of org.apache.lucene.queries.function.valuesource.ConstValueSource 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)) ?
}
use of org.apache.lucene.queries.function.valuesource.ConstValueSource 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));
}
Aggregations