Search in sources :

Example 1 with ConstValueSource

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);
}
Also used : 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) LiteralValueSource(org.apache.lucene.queries.function.valuesource.LiteralValueSource) IfFunction(org.apache.lucene.queries.function.valuesource.IfFunction) BytesRefFieldSource(org.apache.lucene.queries.function.valuesource.BytesRefFieldSource) DoubleConstValueSource(org.apache.lucene.queries.function.valuesource.DoubleConstValueSource) ConstValueSource(org.apache.lucene.queries.function.valuesource.ConstValueSource)

Example 2 with ConstValueSource

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);
}
Also used : ProductFloatFunction(org.apache.lucene.queries.function.valuesource.ProductFloatFunction) 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) DoubleConstValueSource(org.apache.lucene.queries.function.valuesource.DoubleConstValueSource) ConstValueSource(org.apache.lucene.queries.function.valuesource.ConstValueSource)

Example 3 with ConstValueSource

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);
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) ClassicSimilarity(org.apache.lucene.search.similarities.ClassicSimilarity) FunctionQuery(org.apache.lucene.queries.function.FunctionQuery) Query(org.apache.lucene.search.Query) FunctionQuery(org.apache.lucene.queries.function.FunctionQuery) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) TermQuery(org.apache.lucene.search.TermQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) BoostQuery(org.apache.lucene.search.BoostQuery) Explanation(org.apache.lucene.search.Explanation) BM25Similarity(org.apache.lucene.search.similarities.BM25Similarity) ConstValueSource(org.apache.lucene.queries.function.valuesource.ConstValueSource) BoostQuery(org.apache.lucene.search.BoostQuery)

Example 4 with ConstValueSource

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 });
}
Also used : TermQuery(org.apache.lucene.search.TermQuery) FunctionQuery(org.apache.lucene.queries.function.FunctionQuery) Query(org.apache.lucene.search.Query) FunctionQuery(org.apache.lucene.queries.function.FunctionQuery) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) TermQuery(org.apache.lucene.search.TermQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) BoostQuery(org.apache.lucene.search.BoostQuery) Term(org.apache.lucene.index.Term) ConstValueSource(org.apache.lucene.queries.function.valuesource.ConstValueSource) BoostQuery(org.apache.lucene.search.BoostQuery)

Example 5 with ConstValueSource

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 });
}
Also used : TopDocs(org.apache.lucene.search.TopDocs) Query(org.apache.lucene.search.Query) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) ConstValueSource(org.apache.lucene.queries.function.valuesource.ConstValueSource) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery)

Aggregations

ConstValueSource (org.apache.lucene.queries.function.valuesource.ConstValueSource)20 DocFreqValueSource (org.apache.lucene.queries.function.valuesource.DocFreqValueSource)12 DoubleConstValueSource (org.apache.lucene.queries.function.valuesource.DoubleConstValueSource)12 IDFValueSource (org.apache.lucene.queries.function.valuesource.IDFValueSource)12 JoinDocFreqValueSource (org.apache.lucene.queries.function.valuesource.JoinDocFreqValueSource)12 LiteralValueSource (org.apache.lucene.queries.function.valuesource.LiteralValueSource)12 MaxDocValueSource (org.apache.lucene.queries.function.valuesource.MaxDocValueSource)12 NormValueSource (org.apache.lucene.queries.function.valuesource.NormValueSource)12 NumDocsValueSource (org.apache.lucene.queries.function.valuesource.NumDocsValueSource)12 QueryValueSource (org.apache.lucene.queries.function.valuesource.QueryValueSource)12 SumTotalTermFreqValueSource (org.apache.lucene.queries.function.valuesource.SumTotalTermFreqValueSource)12 TFValueSource (org.apache.lucene.queries.function.valuesource.TFValueSource)12 TermFreqValueSource (org.apache.lucene.queries.function.valuesource.TermFreqValueSource)12 TotalTermFreqValueSource (org.apache.lucene.queries.function.valuesource.TotalTermFreqValueSource)12 Query (org.apache.lucene.search.Query)8 BoostQuery (org.apache.lucene.search.BoostQuery)7 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)5 FunctionQuery (org.apache.lucene.queries.function.FunctionQuery)4 BooleanQuery (org.apache.lucene.search.BooleanQuery)4 TermQuery (org.apache.lucene.search.TermQuery)4