mirror of https://github.com/apache/lucene.git
SOLR-9701: NPE in export handler when fl parameter is omitted.
This commit is contained in:
parent
0f8802ba20
commit
42eab7035e
|
@ -91,6 +91,11 @@ Optimizations
|
||||||
* SOLR-9704: Facet Module / JSON Facet API: Optimize blockChildren facets that have
|
* SOLR-9704: Facet Module / JSON Facet API: Optimize blockChildren facets that have
|
||||||
filters specified by using those filters as acceptDocs. (yonik)
|
filters specified by using those filters as acceptDocs. (yonik)
|
||||||
|
|
||||||
|
Bug Fixes
|
||||||
|
----------------------
|
||||||
|
* SOLR-9701: NPE in export handler when "fl" parameter is omitted.
|
||||||
|
(Erick Erickson)
|
||||||
|
|
||||||
Other Changes
|
Other Changes
|
||||||
----------------------
|
----------------------
|
||||||
|
|
||||||
|
|
|
@ -85,21 +85,23 @@ public class SortingResponseWriter implements QueryResponseWriter {
|
||||||
|
|
||||||
SolrRequestInfo info = SolrRequestInfo.getRequestInfo();
|
SolrRequestInfo info = SolrRequestInfo.getRequestInfo();
|
||||||
SortSpec sortSpec = info.getResponseBuilder().getSortSpec();
|
SortSpec sortSpec = info.getResponseBuilder().getSortSpec();
|
||||||
Exception exception = null;
|
|
||||||
|
|
||||||
if(sortSpec == null) {
|
if(sortSpec == null) {
|
||||||
exception = new IOException(new SyntaxError("No sort criteria was provided."));
|
writeException((new IOException(new SyntaxError("No sort criteria was provided."))), writer, true);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SolrIndexSearcher searcher = req.getSearcher();
|
SolrIndexSearcher searcher = req.getSearcher();
|
||||||
Sort sort = searcher.weightSort(sortSpec.getSort());
|
Sort sort = searcher.weightSort(sortSpec.getSort());
|
||||||
|
|
||||||
if(sort == null) {
|
if(sort == null) {
|
||||||
exception = new IOException(new SyntaxError("No sort criteria was provided."));
|
writeException((new IOException(new SyntaxError("No sort criteria was provided."))), writer, true);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(sort != null && sort.needsScores()) {
|
if(sort != null && sort.needsScores()) {
|
||||||
exception = new IOException(new SyntaxError("Scoring is not currently supported with xsort."));
|
writeException((new IOException(new SyntaxError("Scoring is not currently supported with xsort."))), writer, true);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// There is a bailout in SolrIndexSearcher.getDocListNC when there are _no_ docs in the index at all.
|
// There is a bailout in SolrIndexSearcher.getDocListNC when there are _no_ docs in the index at all.
|
||||||
|
@ -117,7 +119,8 @@ public class SortingResponseWriter implements QueryResponseWriter {
|
||||||
totalHits = ((Integer)req.getContext().get("totalHits")).intValue();
|
totalHits = ((Integer)req.getContext().get("totalHits")).intValue();
|
||||||
sets = (FixedBitSet[]) req.getContext().get("export");
|
sets = (FixedBitSet[]) req.getContext().get("export");
|
||||||
if (sets == null) {
|
if (sets == null) {
|
||||||
exception = new IOException(new SyntaxError("xport RankQuery is required for xsort: rq={!xport}"));
|
writeException((new IOException(new SyntaxError("xport RankQuery is required for xsort: rq={!xport}"))), writer, true);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SolrParams params = req.getParams();
|
SolrParams params = req.getParams();
|
||||||
|
@ -126,7 +129,8 @@ public class SortingResponseWriter implements QueryResponseWriter {
|
||||||
String[] fields = null;
|
String[] fields = null;
|
||||||
|
|
||||||
if(fl == null) {
|
if(fl == null) {
|
||||||
exception = new IOException(new SyntaxError("export field list (fl) must be specified."));
|
writeException((new IOException(new SyntaxError("export field list (fl) must be specified."))), writer, true);
|
||||||
|
return;
|
||||||
} else {
|
} else {
|
||||||
fields = fl.split(",");
|
fields = fl.split(",");
|
||||||
|
|
||||||
|
@ -135,8 +139,8 @@ public class SortingResponseWriter implements QueryResponseWriter {
|
||||||
fields[i] = fields[i].trim();
|
fields[i] = fields[i].trim();
|
||||||
|
|
||||||
if(fields[i].equals("score")) {
|
if(fields[i].equals("score")) {
|
||||||
exception = new IOException(new SyntaxError("Scoring is not currently supported with xsort."));
|
writeException((new IOException(new SyntaxError("Scoring is not currently supported with xsort."))), writer, true);
|
||||||
break;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -146,12 +150,7 @@ public class SortingResponseWriter implements QueryResponseWriter {
|
||||||
try {
|
try {
|
||||||
fieldWriters = getFieldWriters(fields, req.getSearcher());
|
fieldWriters = getFieldWriters(fields, req.getSearcher());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
exception = e;
|
writeException(e, writer, true);
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if(exception != null) {
|
|
||||||
writeException(exception, writer, true);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -170,7 +170,21 @@ public class TestSortingResponseWriter extends SolrTestCaseJ4 {
|
||||||
|
|
||||||
s = h.query(req("q", "id:8", "qt", "/export", "fl", "stringdv", "sort", "intdv asc"));
|
s = h.query(req("q", "id:8", "qt", "/export", "fl", "stringdv", "sort", "intdv asc"));
|
||||||
assertEquals(s, "{\"responseHeader\": {\"status\": 0}, \"response\":{\"numFound\":1, \"docs\":[{\"stringdv\":\"chello \\\"world\\\"\"}]}}");
|
assertEquals(s, "{\"responseHeader\": {\"status\": 0}, \"response\":{\"numFound\":1, \"docs\":[{\"stringdv\":\"chello \\\"world\\\"\"}]}}");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testExportRequiredParams() throws Exception {
|
||||||
|
|
||||||
|
//Test whether missing required parameters returns expected errors.
|
||||||
|
|
||||||
|
//String s = h.query(req("q", "id:1", "qt", "/export", "fl", "floatdv,intdv,stringdv,longdv,doubledv", "sort", "intdv asc"));
|
||||||
|
String s;
|
||||||
|
s = h.query(req("qt", "/export"));
|
||||||
|
assertTrue("Should have had a sort error", s.contains("No sort criteria"));
|
||||||
|
s = h.query(req("sort", "intdv asc", "qt", "/export"));
|
||||||
|
assertTrue("Should have had fl error", s.contains("export field list (fl) must be specified"));
|
||||||
|
s = h.query(req("sort", "intdv asc", "qt", "/export", "fl", "stringdv"));
|
||||||
|
// Interesting you don't even need to specify a "q" parameter.
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue