Search in sources :

Example 11 with ConstValueSource

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

the class TestValueSources method testDiv.

public void testDiv() throws Exception {
    ValueSource vs = new DivFloatFunction(new ConstValueSource(10f), new ConstValueSource(5f));
    assertHits(new FunctionQuery(vs), new float[] { 2f, 2f });
    assertAllExist(vs);
    vs = new DivFloatFunction(new ConstValueSource(10f), BOGUS_FLOAT_VS);
    assertNoneExist(vs);
    vs = new DivFloatFunction(BOGUS_FLOAT_VS, new ConstValueSource(10f));
    assertNoneExist(vs);
}
Also used : DivFloatFunction(org.apache.lucene.queries.function.valuesource.DivFloatFunction) 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 12 with ConstValueSource

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

the class TestValueSources method testQueryWrapedFuncWrapedQuery.

public void testQueryWrapedFuncWrapedQuery() throws Exception {
    ValueSource vs = new QueryValueSource(new FunctionQuery(new ConstValueSource(2f)), 0f);
    assertHits(new FunctionQuery(vs), new float[] { 2f, 2f });
    assertAllExist(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) DoubleConstValueSource(org.apache.lucene.queries.function.valuesource.DoubleConstValueSource) ConstValueSource(org.apache.lucene.queries.function.valuesource.ConstValueSource) QueryValueSource(org.apache.lucene.queries.function.valuesource.QueryValueSource)

Example 13 with ConstValueSource

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

the class TestValueSources method testSumFloat.

public void testSumFloat() throws Exception {
    ValueSource vs = new SumFloatFunction(new ValueSource[] { new ConstValueSource(1f), new ConstValueSource(2f) });
    assertHits(new FunctionQuery(vs), new float[] { 3f, 3f });
    assertAllExist(vs);
    vs = new SumFloatFunction(new ValueSource[] { BOGUS_FLOAT_VS, new ConstValueSource(2f) });
    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) SumFloatFunction(org.apache.lucene.queries.function.valuesource.SumFloatFunction) DoubleConstValueSource(org.apache.lucene.queries.function.valuesource.DoubleConstValueSource) ConstValueSource(org.apache.lucene.queries.function.valuesource.ConstValueSource)

Example 14 with ConstValueSource

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

the class TestValueSources method testRangeMap.

public void testRangeMap() throws Exception {
    assertHits(new FunctionQuery(new RangeMapFloatFunction(new FloatFieldSource("float"), 5, 6, 1, 0f)), new float[] { 1f, 0f });
    assertHits(new FunctionQuery(new RangeMapFloatFunction(new FloatFieldSource("float"), 5, 6, new SumFloatFunction(new ValueSource[] { new ConstValueSource(1f), new ConstValueSource(2f) }), new ConstValueSource(11f))), new float[] { 3f, 11f });
// TODO: what *should* the rules be for exist() ?
// ((source exists && source in range && target exists) OR (source not in range && default exists)) ?
}
Also used : RangeMapFloatFunction(org.apache.lucene.queries.function.valuesource.RangeMapFloatFunction) FloatFieldSource(org.apache.lucene.queries.function.valuesource.FloatFieldSource) MultiValuedFloatFieldSource(org.apache.lucene.queries.function.valuesource.MultiValuedFloatFieldSource) 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) SumFloatFunction(org.apache.lucene.queries.function.valuesource.SumFloatFunction) DoubleConstValueSource(org.apache.lucene.queries.function.valuesource.DoubleConstValueSource) ConstValueSource(org.apache.lucene.queries.function.valuesource.ConstValueSource)

Example 15 with ConstValueSource

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

the class TestFunctionQueryExplanations method testMapFunction.

public void testMapFunction() throws Exception {
    ValueSource rff = new RangeMapFloatFunction(new ConstValueSource(3), 0, 1, 2, new Float(4));
    Query q = new FunctionQuery(rff);
    qtest(q, new int[] { 0, 1, 2, 3 });
    assertEquals("map(const(3.0),0.0,1.0,const(2.0),const(4.0))", rff.description());
    assertEquals("map(const(3.0),min=0.0,max=1.0,target=const(2.0),defaultVal=const(4.0))", rff.getValues(null, null).toString(123));
    // DefaultValue is null -> defaults to source value
    rff = new RangeMapFloatFunction(new ConstValueSource(3), 0, 1, 2, null);
    assertEquals("map(const(3.0),0.0,1.0,const(2.0),null)", rff.description());
    assertEquals("map(const(3.0),min=0.0,max=1.0,target=const(2.0),defaultVal=null)", rff.getValues(null, null).toString(123));
}
Also used : RangeMapFloatFunction(org.apache.lucene.queries.function.valuesource.RangeMapFloatFunction) Query(org.apache.lucene.search.Query) BoostQuery(org.apache.lucene.search.BoostQuery) ConstValueSource(org.apache.lucene.queries.function.valuesource.ConstValueSource) ConstValueSource(org.apache.lucene.queries.function.valuesource.ConstValueSource)

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