SOLR-8317: use responseHeader and response accessors to SolrQueryResponse

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1721170 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Christine Poerschke 2015-12-21 14:39:21 +00:00
parent a38a69a979
commit c4db8d57a4
27 changed files with 48 additions and 48 deletions

View File

@ -368,7 +368,7 @@ Other Changes
* SOLR-8419: TermVectorComponent for distributed search now requires a uniqueKey in the schema. Also, it no longer
returns "uniqueKeyField" in the response. (David Smiley)
* SOLR-8317: add responseHeader and response accessors to SolrQueryResponse. (Christine Poerschke)
* SOLR-8317: add & use responseHeader and response accessors to SolrQueryResponse. (Christine Poerschke)
================== 5.4.0 ==================

View File

@ -273,7 +273,7 @@ public class ClusteringComponent extends SearchComponent implements SolrCoreAwar
SearchClusteringEngine engine = searchClusteringEngines.get(name);
if (engine != null) {
checkAvailable(name, engine);
SolrDocumentList solrDocList = (SolrDocumentList) rb.rsp.getValues().get("response");
SolrDocumentList solrDocList = (SolrDocumentList) rb.rsp.getResponse();
// TODO: Currently, docIds is set to null in distributed environment.
// This causes CarrotParams.PRODUCE_SUMMARY doesn't work.
// To work CarrotParams.PRODUCE_SUMMARY under distributed mode, we can choose either one of:

View File

@ -52,7 +52,7 @@ public class ClusteringComponentTest extends AbstractClusteringTestCase {
SolrRequestHandler handler = core.getRequestHandler("standard");
SolrQueryResponse rsp;
rsp = new SolrQueryResponse();
rsp.add("responseHeader", new SimpleOrderedMap<>());
rsp.addResponseHeader(new SimpleOrderedMap<>());
SolrQueryRequest req = new LocalSolrQueryRequest(core, params);
handler.handleRequest(req, rsp);
NamedList<?> values = rsp.getValues();
@ -70,7 +70,7 @@ public class ClusteringComponentTest extends AbstractClusteringTestCase {
handler = core.getRequestHandler("docClustering");
rsp = new SolrQueryResponse();
rsp.add("responseHeader", new SimpleOrderedMap<>());
rsp.addResponseHeader(new SimpleOrderedMap<>());
req = new LocalSolrQueryRequest(core, params);
handler.handleRequest(req, rsp);
values = rsp.getValues();

View File

@ -42,7 +42,7 @@ public class PageTool {
results_per_page = new Integer(rows);
}
//TODO: Handle group by results
Object docs = response.getValues().get("response");
Object docs = response.getResponse();
if (docs != null) {
if (docs instanceof DocSlice) {
DocSlice doc_slice = (DocSlice) docs;

View File

@ -2079,7 +2079,7 @@ public final class SolrCore implements SolrInfoMBean, Closeable {
public static void preDecorateResponse(SolrQueryRequest req, SolrQueryResponse rsp) {
// setup response header
final NamedList<Object> responseHeader = new SimpleOrderedMap<>();
rsp.add("responseHeader", responseHeader);
rsp.addResponseHeader(responseHeader);
// toLog is a local ref to the same NamedList used by the response
NamedList<Object> toLog = rsp.getToLog();

View File

@ -212,7 +212,7 @@ public class MoreLikeThisHandler extends RequestHandlerBase
if (mltDocs == null) {
mltDocs = new DocListAndSet(); // avoid NPE
}
rsp.add("response", mltDocs.docList);
rsp.addResponse(mltDocs.docList);
if (interesting != null) {

View File

@ -353,7 +353,7 @@ public class QueryComponent extends SearchComponent
rb.setResults(res);
ResultContext ctx = new BasicResultContext(rb);
rsp.add("response", ctx);
rsp.addResponse(ctx);
return;
}
@ -506,7 +506,7 @@ public class QueryComponent extends SearchComponent
if (grouping.mainResult != null) {
ResultContext ctx = new BasicResultContext(rb, grouping.mainResult);
rsp.add("response", ctx);
rsp.addResponse(ctx);
rsp.getToLog().add("hits", grouping.mainResult.matches());
} else if (!grouping.getCommands().isEmpty()) { // Can never be empty since grouping.execute() checks for this.
rsp.add("grouped", result.groupedResults);
@ -523,7 +523,7 @@ public class QueryComponent extends SearchComponent
rb.setResult(result);
ResultContext ctx = new BasicResultContext(rb);
rsp.add("response", ctx);
rsp.addResponse(ctx);
rsp.getToLog().add("hits", rb.getResults().docList.matches());
if ( ! rb.req.getParams().getBool(ShardParams.IS_SHARD,false) ) {
@ -822,7 +822,7 @@ public class QueryComponent extends SearchComponent
}
}
rb.rsp.add("response", rb._responseDocs);
rb.rsp.addResponse(rb._responseDocs);
if (null != rb.getNextCursorMark()) {
rb.rsp.add(CursorMarkParams.CURSOR_MARK_NEXT,
rb.getNextCursorMark().getSerializedTotem());

View File

@ -221,7 +221,7 @@ public class RealTimeGetComponent extends SearchComponent
rsp.add("doc", docList.size() > 0 ? docList.get(0) : null);
} else {
docList.setNumFound(docList.size());
rsp.add("response", docList);
rsp.addResponse(docList);
}
}
@ -499,7 +499,7 @@ public class RealTimeGetComponent extends SearchComponent
rb.rsp.add("doc", docList.size() > 0 ? docList.get(0) : null);
} else {
docList.setNumFound(docList.size());
rb.rsp.add("response", docList);
rb.rsp.addResponse(docList);
}
}

View File

@ -70,7 +70,7 @@ public class ResponseLogComponent extends SearchComponent {
IndexSchema schema = searcher.getSchema();
if (schema.getUniqueKeyField() == null) return;
ResultContext rc = (ResultContext) rb.rsp.getValues().get("response");
ResultContext rc = (ResultContext) rb.rsp.getResponse();
DocList docs = rc.getDocList();
if (docs.hasScores()) {

View File

@ -290,11 +290,11 @@ public class SearchHandler extends RequestHandlerBase implements SolrCoreAware ,
}
} catch (ExitableDirectoryReader.ExitingReaderException ex) {
log.warn( "Query: " + req.getParamString() + "; " + ex.getMessage());
SolrDocumentList r = (SolrDocumentList) rb.rsp.getValues().get("response");
SolrDocumentList r = (SolrDocumentList) rb.rsp.getResponse();
if(r == null)
r = new SolrDocumentList();
r.setNumFound(0);
rb.rsp.add("response", r);
rb.rsp.addResponse(r);
if(rb.isDebug()) {
NamedList debug = new NamedList();
debug.add("explain", new NamedList());

View File

@ -50,7 +50,7 @@ public class BinaryResponseWriter implements BinaryQueryResponseWriter {
public void write(OutputStream out, SolrQueryRequest req, SolrQueryResponse response) throws IOException {
Resolver resolver = new Resolver(req, response.getReturnFields());
Boolean omitHeader = req.getParams().getBool(CommonParams.OMIT_HEADER);
if (omitHeader != null && omitHeader) response.getValues().remove("responseHeader");
if (omitHeader != null && omitHeader) response.removeResponseHeader();
new JavaBinCodec(resolver).setWritableDocFields(resolver).marshal(response.getValues(), out);
}

View File

@ -236,7 +236,7 @@ class CSVWriter extends TextResponseWriter {
}
Collection<String> fields = returnFields.getRequestedFieldNames();
Object responseObj = rsp.getValues().get("response");
Object responseObj = rsp.getResponse();
boolean returnOnlyStored = false;
if (fields==null||returnFields.hasPatternMatching()) {
if (responseObj instanceof SolrDocumentList) {

View File

@ -92,7 +92,7 @@ class JSONWriter extends TextResponseWriter {
writer.write(wrapperFunction + "(");
}
Boolean omitHeader = req.getParams().getBool(CommonParams.OMIT_HEADER);
if(omitHeader != null && omitHeader) rsp.getValues().remove("responseHeader");
if(omitHeader != null && omitHeader) rsp.removeResponseHeader();
writeNamedList(null, rsp.getValues());
if(wrapperFunction!=null) {
writer.write(')');

View File

@ -81,7 +81,7 @@ class PHPSerializedWriter extends JSONWriter {
@Override
public void writeResponse() throws IOException {
Boolean omitHeader = req.getParams().getBool(CommonParams.OMIT_HEADER);
if(omitHeader != null && omitHeader) rsp.getValues().remove("responseHeader");
if(omitHeader != null && omitHeader) rsp.removeResponseHeader();
writeNamedList(null, rsp.getValues());
}

View File

@ -104,9 +104,9 @@ public class XMLWriter extends TextResponseWriter {
writer.write(XML_START2_NOSCHEMA);
// dump response values
NamedList<?> lst = rsp.getValues();
Boolean omitHeader = req.getParams().getBool(CommonParams.OMIT_HEADER);
if(omitHeader != null && omitHeader) lst.remove("responseHeader");
if(omitHeader != null && omitHeader) rsp.removeResponseHeader();
final NamedList<?> lst = rsp.getValues();
int sz = lst.size();
int start=0;

View File

@ -57,7 +57,7 @@ public class MainEndResultTransformer implements EndResultTransformer {
if (maxScore != Float.NEGATIVE_INFINITY) {
docList.setMaxScore(maxScore);
}
rb.rsp.add("response", docList);
rb.rsp.addResponse(docList);
}
}
}

View File

@ -139,7 +139,7 @@ public class IgnoreCommitOptimizeUpdateProcessorFactory extends UpdateRequestPro
} else {
responseHeader = new SimpleOrderedMap<Object>();
responseHeader.add("msg", responseMsg);
rsp.add("responseHeader", responseHeader);
rsp.addResponseHeader(responseHeader);
}
}
}

View File

@ -710,7 +710,7 @@ public class BasicFunctionalityTest extends SolrTestCaseJ4 {
SolrQueryResponse rsp = new SolrQueryResponse();
core.execute(core.getRequestHandler(req.getParams().get(CommonParams.QT)), req, rsp);
DocList dl = ((ResultContext) rsp.getValues().get("response")).getDocList();
DocList dl = ((ResultContext) rsp.getResponse()).getDocList();
StoredDocument d = req.getSearcher().doc(dl.iterator().nextDoc());
// ensure field in fl is not lazy
assertFalse( ((Field) d.getField("test_hlt")).getClass().getSimpleName().equals("LazyField"));
@ -735,7 +735,7 @@ public class BasicFunctionalityTest extends SolrTestCaseJ4 {
SolrQueryResponse rsp = new SolrQueryResponse();
core.execute(core.getRequestHandler(req.getParams().get(CommonParams.QT)), req, rsp);
DocList dl = ((ResultContext) rsp.getValues().get("response")).getDocList();
DocList dl = ((ResultContext) rsp.getResponse()).getDocList();
DocIterator di = dl.iterator();
StoredDocument d1 = req.getSearcher().doc(di.nextDoc());
StorableField[] values1 = null;
@ -757,7 +757,7 @@ public class BasicFunctionalityTest extends SolrTestCaseJ4 {
rsp = new SolrQueryResponse();
core.execute(core.getRequestHandler(req.getParams().get(CommonParams.QT)), req, rsp);
dl = ((ResultContext) rsp.getValues().get("response")).getDocList();
dl = ((ResultContext) rsp.getResponse()).getDocList();
di = dl.iterator();
StoredDocument d2 = req.getSearcher().doc(di.nextDoc());
// ensure same doc, same lazy field now

View File

@ -273,7 +273,7 @@ public class TestGroupingSearch extends SolrTestCaseJ4 {
SolrRequestInfo.clearRequestInfo();
}
assertEquals(6, ((ResultContext) response.getValues().get("response")).getDocList().matches());
assertEquals(6, ((ResultContext) response.getResponse()).getDocList().matches());
new BinaryResponseParser().processResponse(new ByteArrayInputStream(out.toByteArray()), "");
out.close();
}

View File

@ -297,7 +297,7 @@ public class SpellCheckComponentTest extends SolrTestCaseJ4 {
SolrRequestHandler handler = core.getRequestHandler("spellCheckCompRH");
SolrQueryResponse rsp = new SolrQueryResponse();
rsp.add("responseHeader", new SimpleOrderedMap());
rsp.addResponseHeader(new SimpleOrderedMap());
SolrQueryRequest req = new LocalSolrQueryRequest(core, params);
handler.handleRequest(req, rsp);
req.close();
@ -310,7 +310,7 @@ public class SpellCheckComponentTest extends SolrTestCaseJ4 {
params.remove(SpellingParams.SPELLCHECK_DICT);
params.add(SpellingParams.SPELLCHECK_DICT, "threshold_direct");
rsp = new SolrQueryResponse();
rsp.add("responseHeader", new SimpleOrderedMap());
rsp.addResponseHeader(new SimpleOrderedMap());
req = new LocalSolrQueryRequest(core, params);
handler.handleRequest(req, rsp);
req.close();

View File

@ -124,7 +124,7 @@ public class JSONWriterTest extends SolrTestCaseJ4 {
list.setMaxScore(0.7f);
list.add(solrDoc);
rsp.add("response", list);
rsp.addResponse(list);
w.write(buf, req, rsp);
String result = buf.toString();

View File

@ -130,7 +130,7 @@ public class SmileWriterTest extends SolrTestCaseJ4 {
list.setMaxScore(0.7f);
list.add(solrDoc);
rsp.add("response", list);
rsp.addResponse(list);
w.write(buf, req, rsp);

View File

@ -143,7 +143,7 @@ public class TestCSVResponseWriter extends SolrTestCaseJ4 {
SolrQueryRequest req = req("q","*:*");
SolrQueryResponse rsp = new SolrQueryResponse();
rsp.add("response", sdl);
rsp.addResponse(sdl);
QueryResponseWriter w = new CSVResponseWriter();
rsp.setReturnFields( new SolrReturnFields("id,foo_s", req) );

View File

@ -96,7 +96,7 @@ public class TestPHPSerializedResponseWriter extends SolrTestCaseJ4 {
SolrDocumentList sdl = new SolrDocumentList();
sdl.add(d1);
sdl.add(d2);
rsp.add("response", sdl);
rsp.addResponse(sdl);
w.write(buf, req, rsp);
assertEquals("a:1:{s:8:\"response\";a:3:{s:8:\"numFound\";i:0;s:5:\"start\";i:0;s:4:\"docs\";a:2:{i:0;a:6:{s:2:\"id\";s:1:\"1\";s:5:\"data1\";s:5:\"hello\";s:5:\"data2\";i:42;s:5:\"data3\";b:1;s:5:\"data4\";a:2:{s:7:\"data4.1\";s:7:\"hashmap\";s:7:\"data4.2\";s:5:\"hello\";}s:5:\"data5\";a:3:{i:0;s:7:\"data5.1\";i:1;s:7:\"data5.2\";i:2;s:7:\"data5.3\";}}i:1;a:1:{s:2:\"id\";s:1:\"2\";}}}}",

View File

@ -259,8 +259,8 @@ public class TestRangeQuery extends SolrTestCaseJ4 {
SolrQueryResponse qr = h.queryAndResponse(handler, req);
if (last != null) {
// we only test if the same docs matched since some queries will include factors like idf, etc.
DocList rA = ((ResultContext)qr.getValues().get("response")).getDocList();
DocList rB = ((ResultContext)last.getValues().get("response")).getDocList();
DocList rA = ((ResultContext)qr.getResponse()).getDocList();
DocList rB = ((ResultContext)last.getResponse()).getDocList();
sameDocs( rA, rB );
}
req.close();

View File

@ -112,7 +112,7 @@ public class SpellCheckCollatorTest extends SolrTestCaseJ4 {
{
SolrRequestHandler handler = core.getRequestHandler("spellCheckCompRH");
SolrQueryResponse rsp = new SolrQueryResponse();
rsp.add("responseHeader", new SimpleOrderedMap());
rsp.addResponseHeader(new SimpleOrderedMap());
SolrQueryRequest req = new LocalSolrQueryRequest(core, params);
handler.handleRequest(req, rsp);
req.close();
@ -144,7 +144,7 @@ public class SpellCheckCollatorTest extends SolrTestCaseJ4 {
{
SolrRequestHandler handler = core.getRequestHandler("spellCheckCompRH");
SolrQueryResponse rsp = new SolrQueryResponse();
rsp.add("responseHeader", new SimpleOrderedMap());
rsp.addResponseHeader(new SimpleOrderedMap());
SolrQueryRequest req = new LocalSolrQueryRequest(core, params);
handler.handleRequest(req, rsp);
req.close();
@ -238,7 +238,7 @@ public class SpellCheckCollatorTest extends SolrTestCaseJ4 {
//not want the collations to return us "lowerfilt:(+faith +hope +loaves)" as this only matches doc id#1.
SolrRequestHandler handler = core.getRequestHandler("spellCheckCompRH");
SolrQueryResponse rsp = new SolrQueryResponse();
rsp.add("responseHeader", new SimpleOrderedMap());
rsp.addResponseHeader(new SimpleOrderedMap());
SolrQueryRequest req = new LocalSolrQueryRequest(core, params);
handler.handleRequest(req, rsp);
req.close();
@ -273,7 +273,7 @@ public class SpellCheckCollatorTest extends SolrTestCaseJ4 {
//because requrying against this Request Handler results in 0 hits.
SolrRequestHandler handler = core.getRequestHandler("spellCheckCompRH");
SolrQueryResponse rsp = new SolrQueryResponse();
rsp.add("responseHeader", new SimpleOrderedMap());
rsp.addResponseHeader(new SimpleOrderedMap());
SolrQueryRequest req = new LocalSolrQueryRequest(core, params);
handler.handleRequest(req, rsp);
req.close();
@ -288,7 +288,7 @@ public class SpellCheckCollatorTest extends SolrTestCaseJ4 {
params.remove(SpellingParams.SPELLCHECK_BUILD);
handler = core.getRequestHandler("spellCheckCompRH1");
rsp = new SolrQueryResponse();
rsp.add("responseHeader", new SimpleOrderedMap());
rsp.addResponseHeader(new SimpleOrderedMap());
req = new LocalSolrQueryRequest(core, params);
handler.handleRequest(req, rsp);
req.close();
@ -320,7 +320,7 @@ public class SpellCheckCollatorTest extends SolrTestCaseJ4 {
// return no results if tried.
SolrRequestHandler handler = core.getRequestHandler("spellCheckCompRH");
SolrQueryResponse rsp = new SolrQueryResponse();
rsp.add("responseHeader", new SimpleOrderedMap());
rsp.addResponseHeader(new SimpleOrderedMap());
SolrQueryRequest req = new LocalSolrQueryRequest(core, params);
handler.handleRequest(req, rsp);
req.close();
@ -337,7 +337,7 @@ public class SpellCheckCollatorTest extends SolrTestCaseJ4 {
params.add(SpellingParams.SPELLCHECK_MAX_COLLATIONS, "1");
handler = core.getRequestHandler("spellCheckCompRH");
rsp = new SolrQueryResponse();
rsp.add("responseHeader", new SimpleOrderedMap());
rsp.addResponseHeader(new SimpleOrderedMap());
req = new LocalSolrQueryRequest(core, params);
handler.handleRequest(req, rsp);
req.close();
@ -355,7 +355,7 @@ public class SpellCheckCollatorTest extends SolrTestCaseJ4 {
params.add(SpellingParams.SPELLCHECK_MAX_COLLATIONS, "2");
handler = core.getRequestHandler("spellCheckCompRH");
rsp = new SolrQueryResponse();
rsp.add("responseHeader", new SimpleOrderedMap());
rsp.addResponseHeader(new SimpleOrderedMap());
req = new LocalSolrQueryRequest(core, params);
handler.handleRequest(req, rsp);
req.close();
@ -374,7 +374,7 @@ public class SpellCheckCollatorTest extends SolrTestCaseJ4 {
params.add(SpellingParams.SPELLCHECK_COLLATE_EXTENDED_RESULTS, "true");
handler = core.getRequestHandler("spellCheckCompRH");
rsp = new SolrQueryResponse();
rsp.add("responseHeader", new SimpleOrderedMap());
rsp.addResponseHeader(new SimpleOrderedMap());
req = new LocalSolrQueryRequest(core, params);
handler.handleRequest(req, rsp);
req.close();
@ -428,7 +428,7 @@ public class SpellCheckCollatorTest extends SolrTestCaseJ4 {
//not want the collations to return us "lowerfilt:(+faith +hope +loaves)" as this only matches doc id#1.
SolrRequestHandler handler = core.getRequestHandler("spellCheckCompRH");
SolrQueryResponse rsp = new SolrQueryResponse();
rsp.add("responseHeader", new SimpleOrderedMap());
rsp.addResponseHeader(new SimpleOrderedMap());
SolrQueryRequest req = new LocalSolrQueryRequest(core, params);
handler.handleRequest(req, rsp);
req.close();
@ -585,7 +585,7 @@ public class SpellCheckCollatorTest extends SolrTestCaseJ4 {
params.add(CommonParams.Q, "lowerfilt:(+fauth)");
SolrRequestHandler handler = core.getRequestHandler("spellCheckCompRH");
SolrQueryResponse rsp = new SolrQueryResponse();
rsp.add("responseHeader", new SimpleOrderedMap());
rsp.addResponseHeader(new SimpleOrderedMap());
SolrQueryRequest req = new LocalSolrQueryRequest(core, params);
handler.handleRequest(req, rsp);
req.close();

View File

@ -345,7 +345,7 @@ public class DocumentBuilderTest extends SolrTestCaseJ4 {
SolrQueryResponse rsp = new SolrQueryResponse();
core.execute(core.getRequestHandler(req.getParams().get(CommonParams.QT)), req, rsp);
DocList dl = ((ResultContext) rsp.getValues().get("response")).getDocList();
DocList dl = ((ResultContext) rsp.getResponse()).getDocList();
assertTrue("can't find the doc we just added", 1 == dl.size());
int docid = dl.iterator().nextDoc();