Search in sources :

Example 16 with ConstValueSource

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

the class TestFunctionQueryExplanations method testSimple.

public void testSimple() throws Exception {
    Query q = new FunctionQuery(new ConstValueSource(5));
    qtest(q, new int[] { 0, 1, 2, 3 });
}
Also used : Query(org.apache.lucene.search.Query) BoostQuery(org.apache.lucene.search.BoostQuery) ConstValueSource(org.apache.lucene.queries.function.valuesource.ConstValueSource)

Example 17 with ConstValueSource

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

the class TestValueSources method testMaxFloat.

public void testMaxFloat() throws Exception {
    ValueSource vs = new MaxFloatFunction(new ValueSource[] { new ConstValueSource(1f), new ConstValueSource(2f) });
    assertHits(new FunctionQuery(vs), new float[] { 2f, 2f });
    assertAllExist(vs);
    // as long as one value exists, then max exists
    vs = new MaxFloatFunction(new ValueSource[] { BOGUS_FLOAT_VS, new ConstValueSource(2F) });
    assertAllExist(vs);
    vs = new MaxFloatFunction(new ValueSource[] { BOGUS_FLOAT_VS, new ConstValueSource(2F), BOGUS_DOUBLE_VS });
    assertAllExist(vs);
    // if none exist, then max doesn't exist
    vs = new MaxFloatFunction(new ValueSource[] { BOGUS_FLOAT_VS, BOGUS_INT_VS, BOGUS_DOUBLE_VS });
    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) MaxFloatFunction(org.apache.lucene.queries.function.valuesource.MaxFloatFunction) DoubleConstValueSource(org.apache.lucene.queries.function.valuesource.DoubleConstValueSource) ConstValueSource(org.apache.lucene.queries.function.valuesource.ConstValueSource)

Example 18 with ConstValueSource

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

the class TestValueSources method testLinearFloat.

public void testLinearFloat() throws Exception {
    ValueSource vs = new LinearFloatFunction(new ConstValueSource(2.0f), 3, 1);
    assertHits(new FunctionQuery(vs), new float[] { 7f, 7f });
    assertAllExist(vs);
    vs = new LinearFloatFunction(BOGUS_FLOAT_VS, 3, 1);
    assertNoneExist(vs);
}
Also used : LinearFloatFunction(org.apache.lucene.queries.function.valuesource.LinearFloatFunction) 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 19 with ConstValueSource

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

the class TestCustomScoreExplanations method testOneTerm.

public void testOneTerm() throws Exception {
    Query q = new TermQuery(new Term(FIELD, "w1"));
    CustomScoreQuery csq = new CustomScoreQuery(q, new FunctionQuery(new ConstValueSource(5)));
    qtest(csq, 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)

Example 20 with ConstValueSource

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

the class TestCustomScoreExplanations method testTopLevelBoost.

public void testTopLevelBoost() throws Exception {
    Query q = new TermQuery(new Term(FIELD, "w1"));
    CustomScoreQuery csq = new CustomScoreQuery(q, new FunctionQuery(new ConstValueSource(5)));
    BooleanQuery.Builder bqB = new BooleanQuery.Builder();
    bqB.add(new MatchAllDocsQuery(), BooleanClause.Occur.MUST);
    bqB.add(csq, BooleanClause.Occur.MUST);
    BooleanQuery bq = bqB.build();
    qtest(new BoostQuery(bq, 6), new int[] { 0, 1, 2, 3 });
}
Also used : TermQuery(org.apache.lucene.search.TermQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) 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) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) BoostQuery(org.apache.lucene.search.BoostQuery)

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