Search in sources :

Example 1 with MultiFloatFunction

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

the class TestValueSources method testQuery.

public void testQuery() throws Exception {
    Similarity saved = searcher.getSimilarity(true);
    try {
        searcher.setSimilarity(new ClassicSimilarity());
        ValueSource vs = new QueryValueSource(new TermQuery(new Term("string", "bar")), 42F);
        assertHits(new FunctionQuery(vs), new float[] { 42F, 1.4054651F });
        // valuesource should exist only for things matching the term query
        // sanity check via quick & dirty wrapper arround tf
        ValueSource expected = new MultiFloatFunction(new ValueSource[] { new TFValueSource("bogus", "bogus", "string", new BytesRef("bar")) }) {

            @Override
            protected String name() {
                return "tf_based_exists";
            }

            @Override
            protected float func(int doc, FunctionValues[] valsArr) throws IOException {
                return valsArr[0].floatVal(doc);
            }

            @Override
            protected boolean exists(int doc, FunctionValues[] valsArr) throws IOException {
                // if tf > 0, then it should exist
                return 0 < func(doc, valsArr);
            }
        };
        assertExists(expected, vs);
        // Query matches all docs, func exists for all docs
        vs = new QueryValueSource(new TermQuery(new Term("text", "test")), 0F);
        assertAllExist(vs);
        // Query matches no docs, func exists for no docs
        vs = new QueryValueSource(new TermQuery(new Term("bogus", "does not exist")), 0F);
        assertNoneExist(vs);
    } finally {
        searcher.setSimilarity(saved);
    }
}
Also used : ClassicSimilarity(org.apache.lucene.search.similarities.ClassicSimilarity) TermQuery(org.apache.lucene.search.TermQuery) ClassicSimilarity(org.apache.lucene.search.similarities.ClassicSimilarity) Similarity(org.apache.lucene.search.similarities.Similarity) MultiFloatFunction(org.apache.lucene.queries.function.valuesource.MultiFloatFunction) 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) TFValueSource(org.apache.lucene.queries.function.valuesource.TFValueSource) Term(org.apache.lucene.index.Term) QueryValueSource(org.apache.lucene.queries.function.valuesource.QueryValueSource) BytesRef(org.apache.lucene.util.BytesRef)

Aggregations

Term (org.apache.lucene.index.Term)1 ConstValueSource (org.apache.lucene.queries.function.valuesource.ConstValueSource)1 DocFreqValueSource (org.apache.lucene.queries.function.valuesource.DocFreqValueSource)1 DoubleConstValueSource (org.apache.lucene.queries.function.valuesource.DoubleConstValueSource)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 MultiFloatFunction (org.apache.lucene.queries.function.valuesource.MultiFloatFunction)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 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 TermQuery (org.apache.lucene.search.TermQuery)1 ClassicSimilarity (org.apache.lucene.search.similarities.ClassicSimilarity)1 Similarity (org.apache.lucene.search.similarities.Similarity)1 BytesRef (org.apache.lucene.util.BytesRef)1