mirror of https://github.com/apache/lucene.git
SOLR-15031 Prevent null being wrapped in a QueryValueSource
closes #2118
This commit is contained in:
parent
1b67ed9516
commit
98f12f4aeb
|
@ -42,6 +42,10 @@ public class QueryValueSource extends ValueSource {
|
|||
final float defVal;
|
||||
|
||||
public QueryValueSource(Query q, float defVal) {
|
||||
super();
|
||||
if (q == null) {
|
||||
throw new IllegalArgumentException("query cannot be null");
|
||||
}
|
||||
this.q = q;
|
||||
this.defVal = defVal;
|
||||
}
|
||||
|
|
|
@ -268,6 +268,9 @@ Bug Fixes
|
|||
|
||||
* SOLR-14939: JSON range faceting to support cache=false parameter. (Christine Poerschke, Mike Drob)
|
||||
|
||||
* SOLR-15031: Fix preventing null being wrapped in a QueryValueSource subQuery. Such null queries can be caused by query text
|
||||
resulting in an empty token stream. (Pieter van Boxtel via Mike Drob)
|
||||
|
||||
Other Changes
|
||||
---------------------
|
||||
|
||||
|
|
|
@ -361,7 +361,9 @@ public class FunctionQParser extends QParser {
|
|||
((FunctionQParser)subParser).setParseMultipleSources(true);
|
||||
}
|
||||
Query subQuery = subParser.getQuery();
|
||||
if (subQuery instanceof FunctionQuery) {
|
||||
if (subQuery == null) {
|
||||
valueSource = new ConstValueSource(0.0f);
|
||||
} else if (subQuery instanceof FunctionQuery) {
|
||||
valueSource = ((FunctionQuery) subQuery).getValueSource();
|
||||
} else {
|
||||
valueSource = new QueryValueSource(subQuery, 0.0f);
|
||||
|
|
|
@ -1148,4 +1148,17 @@ public class TestFunctionQuery extends SolrTestCaseJ4 {
|
|||
/*id*/1, /*score*/2,
|
||||
/*id*/2, /*score*/2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests a specific (edge) case where a subQuery is null, because no terms are
|
||||
* found in the query. Below such subQuery is created from a field query on a
|
||||
* query text containing only stopwords. Feeding the resulting null-subQuery
|
||||
* into a QueryValueSource (and then using it in for example an if function)
|
||||
* may not produce NullPointerExceptions.
|
||||
*/
|
||||
@Test
|
||||
public void testNullSubQuery() throws Exception {
|
||||
clearIndex();
|
||||
assertJQ(req("q", "{!func}if($subQuery,1,0)", "subQuery", "{!field f=text v='stopworda'}"));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue