use of org.apache.lucene.queries.function.valuesource.IfFunction in project lucene-solr by apache.
the class TestValueSources method testIf.
public void testIf() throws Exception {
ValueSource vs = new IfFunction(new BytesRefFieldSource("id"), // match
new ConstValueSource(1.0f), new ConstValueSource(2.0f));
assertHits(new FunctionQuery(vs), new float[] { 1f, 1f });
assertAllExist(vs);
// true just if a test value exists...
vs = new IfFunction(new LiteralValueSource("false"), // match
new ConstValueSource(1.0f), new ConstValueSource(2.0f));
assertHits(new FunctionQuery(vs), new float[] { 1f, 1f });
assertAllExist(vs);
// false value if tests value does not exist
vs = new IfFunction(BOGUS_FLOAT_VS, new ConstValueSource(1.0f), // match
new ConstValueSource(2.0f));
assertHits(new FunctionQuery(vs), new float[] { 2F, 2F });
assertAllExist(vs);
// final value may still not exist
vs = new IfFunction(new BytesRefFieldSource("id"), // match
BOGUS_FLOAT_VS, new ConstValueSource(1.0f));
assertNoneExist(vs);
}
Aggregations