use of org.apache.lucene.queries.function.valuesource.ConstValueSource 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);
}
use of org.apache.lucene.queries.function.valuesource.ConstValueSource in project lucene-solr by apache.
the class TestValueSources method testProduct.
public void testProduct() throws Exception {
ValueSource vs = new ProductFloatFunction(new ValueSource[] { new ConstValueSource(2f), new ConstValueSource(3f) });
assertHits(new FunctionQuery(vs), new float[] { 6f, 6f });
assertAllExist(vs);
vs = new ProductFloatFunction(new ValueSource[] { BOGUS_FLOAT_VS, new ConstValueSource(3f) });
assertNoneExist(vs);
}
use of org.apache.lucene.queries.function.valuesource.ConstValueSource in project lucene-solr by apache.
the class TestCustomScoreExplanations method testSubExplanations.
public void testSubExplanations() throws IOException {
Query query = new FunctionQuery(new ConstValueSource(5));
IndexSearcher searcher = newSearcher(BaseExplanationTestCase.searcher.getIndexReader());
searcher.setSimilarity(new BM25Similarity());
Explanation expl = searcher.explain(query, 0);
assertEquals(2, expl.getDetails().length);
// function
assertEquals(5f, expl.getDetails()[0].getValue(), 0f);
// boost
assertEquals("boost", expl.getDetails()[1].getDescription());
assertEquals(1f, expl.getDetails()[1].getValue(), 0f);
query = new BoostQuery(query, 2);
expl = searcher.explain(query, 0);
assertEquals(2, expl.getDetails().length);
// function
assertEquals(5f, expl.getDetails()[0].getValue(), 0f);
// boost
assertEquals("boost", expl.getDetails()[1].getDescription());
assertEquals(2f, expl.getDetails()[1].getValue(), 0f);
// in order to have a queryNorm != 1
searcher.setSimilarity(new ClassicSimilarity());
expl = searcher.explain(query, 0);
assertEquals(2, expl.getDetails().length);
// function
assertEquals(5f, expl.getDetails()[0].getValue(), 0f);
// boost
assertEquals("boost", expl.getDetails()[1].getDescription());
assertEquals(2f, expl.getDetails()[1].getValue(), 0f);
}
use of org.apache.lucene.queries.function.valuesource.ConstValueSource in project lucene-solr by apache.
the class TestCustomScoreExplanations method testBoost.
public void testBoost() throws Exception {
Query q = new TermQuery(new Term(FIELD, "w1"));
CustomScoreQuery csq = new CustomScoreQuery(q, new FunctionQuery(new ConstValueSource(5)));
qtest(new BoostQuery(csq, 4), new int[] { 0, 1, 2, 3 });
}
use of org.apache.lucene.queries.function.valuesource.ConstValueSource in project lucene-solr by apache.
the class TestBoostedQuery method testBasic.
public void testBasic() throws Exception {
Query q = new MatchAllDocsQuery();
TopDocs docs = is.search(q, 10);
assertEquals(1, docs.totalHits);
float score = docs.scoreDocs[0].score;
Query boostedQ = new BoostedQuery(q, new ConstValueSource(2.0f));
assertHits(boostedQ, new float[] { score * 2 });
}
Aggregations