Class SolrQueryResponse
SolrQueryResponse is used by a query handler to return the response to a query
request.
Note On Returnable Data...
A SolrQueryResponse may contain the following types of Objects generated by the
SolrRequestHandler that processed the request.
StringIntegerLongFloatDoubleBooleanDateDocListSolrDocument(since 1.3)SolrDocumentList(since 1.3)Mapcontaining any of the items in this listNamedListcontaining any of the items in this listCollectioncontaining any of the items in this list- Array containing any of the items in this list
- null
Other data types may be added to the SolrQueryResponse, but there is no guarantee that QueryResponseWriters will be able to deal with unexpected types.
- Since:
- solr 0.9
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Exceptionprotected booleanShould this response be tagged with HTTP caching headers?static final Stringstatic final Stringstatic final Stringstatic final StringHeader to indicate that the search was terminated early because of hits exceeding the query configured limit (maxHitsAllowed).static final Stringstatic final Stringstatic final Stringprotected ReturnFieldsprotected org.apache.solr.common.util.NamedList<Object> Container for storing information that should be logged by Solr before returning.protected org.apache.solr.common.util.NamedList<Object> Container for user defined values -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAppends a named value to the list of named values to be returned.voidaddHttpHeader(String name, String value) Adds a response header with the given name and value.voidaddPartialResponseDetail(Object detail) IfgetResponseHeader()is available, add a reason for returning partial response.voidaddResponse(Object response) Set responsevoidaddResponseHeader(org.apache.solr.common.util.NamedList<Object> header) Set response headervoidAdd a value to be logged.Returns an Exception if there was a fatal error in processing the request.getHttpHeader(String name) Gets the value of the response header with the given name.getHttpHeaders(String name) Gets the values of the response header with the given name.Return responseorg.apache.solr.common.util.NamedList<Object> Response header to be loggedGets the document field names of fields to return by default when returning DocListsorg.apache.solr.common.util.NamedList<Object> getToLog()Get loggable items.getToLogAsString(String prefix) Returns a string of the form "prefix name1=value1 name2=value2 ..."org.apache.solr.common.util.NamedList<Object> Gets data to be returned in this responsestatic booleanhaveCompleteResults(org.apache.solr.common.util.NamedList<?> header) Test if the entire results have been returned, or if some form of limit/cancel/tolerant logic has returned incomplete (or possibly empty) results.Returns a new iterator of response headersbooleanShould this response emit HTTP caching headers?static booleanisPartialResults(org.apache.solr.common.util.NamedList<?> header) IfgetResponseHeader()is available, return the value ofRESPONSE_HEADER_PARTIAL_RESULTS_KEYor false.static ObjectpartialResultsStatus(boolean discarding) removeHttpHeader(String name) Removes a previously added header with the given name (only the first one if multiple are present for the same name)removeHttpHeaders(String name) Removes all previously added headers with the given name.voidClear response headervoidsetAllValues(org.apache.solr.common.util.NamedList<Object> nameValuePairs) Sets data to be returned in this responsevoidCauses an error to be returned instead of the results.voidsetHttpCaching(boolean httpCaching) Enables or disables the emission of HTTP caching headers for this response.voidsetHttpHeader(String name, String value) Sets a response header with the given name and value.voidIfgetResponseHeader()is available, setRESPONSE_HEADER_PARTIAL_RESULTS_KEYattribute to true or "omitted" as required.voidsetReturnFields(ReturnFields fields) Sets the document field names of fields to return by default when returning DocLists
-
Field Details
-
NAME
- See Also:
-
RESPONSE_HEADER_PARTIAL_RESULTS_KEY
- See Also:
-
RESPONSE_HEADER_PARTIAL_RESULTS_DETAILS_KEY
- See Also:
-
RESPONSE_HEADER_SEGMENT_TERMINATED_EARLY_KEY
- See Also:
-
RESPONSE_HEADER_MAX_HITS_TERMINATED_EARLY_KEY
Header to indicate that the search was terminated early because of hits exceeding the query configured limit (maxHitsAllowed). Presence of this flag also indicates the partialResults, however in the absence of maxHitsTerminatedEarly, partialResults would be due to other limits like time/cpu.- See Also:
-
RESPONSE_HEADER_APPROXIMATE_TOTAL_HITS_KEY
- See Also:
-
RESPONSE_HEADER_KEY
- See Also:
-
values
Container for user defined values- See Also:
-
toLog
Container for storing information that should be logged by Solr before returning. -
returnFields
-
err
-
httpCaching
protected boolean httpCachingShould this response be tagged with HTTP caching headers?
-
-
Constructor Details
-
SolrQueryResponse
public SolrQueryResponse()
-
-
Method Details
-
getValues
Gets data to be returned in this response- See Also:
-
setAllValues
Sets data to be returned in this response- See Also:
-
setReturnFields
Sets the document field names of fields to return by default when returning DocLists -
getReturnFields
Gets the document field names of fields to return by default when returning DocLists -
setPartialResults
IfgetResponseHeader()is available, setRESPONSE_HEADER_PARTIAL_RESULTS_KEYattribute to true or "omitted" as required. -
partialResultsStatus
-
isPartialResults
public static boolean isPartialResults(org.apache.solr.common.util.NamedList<?> header) IfgetResponseHeader()is available, return the value ofRESPONSE_HEADER_PARTIAL_RESULTS_KEYor false.- Parameters:
header- the response header- Returns:
- true if there are results, but they do not represent the full results, false if the results are complete, or intentionally omitted
-
haveCompleteResults
public static boolean haveCompleteResults(org.apache.solr.common.util.NamedList<?> header) Test if the entire results have been returned, or if some form of limit/cancel/tolerant logic has returned incomplete (or possibly empty) results.- Parameters:
header- the response header- Returns:
- true if full results are returning normally false otherwise.
-
addPartialResponseDetail
IfgetResponseHeader()is available, add a reason for returning partial response.- Parameters:
detail- reason for returning partial response. Multiple components can add multiple reasons at different stages in request processing.
-
add
Appends a named value to the list of named values to be returned.- Parameters:
name- the name of the value - may be null if unnamedval- the value to add - also may be null since null is a legal value- See Also:
-
setException
Causes an error to be returned instead of the results.In general, new calls to this method should not be added. In most cases you should simply throw an exception and let it bubble out to RequestHandlerBase, which will set the exception thrown.
-
getException
Returns an Exception if there was a fatal error in processing the request. Returns null if the request succeeded. -
addResponseHeader
Set response header -
removeResponseHeader
public void removeResponseHeader()Clear response header -
getResponseHeader
Response header to be logged -
addResponse
Set response -
getResponse
Return response -
addToLog
Add a value to be logged.- Parameters:
name- name of the thing to logval- value of the thing to log
-
getToLog
Get loggable items.- Returns:
- things to log
-
getToLogAsString
-
getToLogAsString
Returns a string of the form "prefix name1=value1 name2=value2 ..." -
setHttpCaching
public void setHttpCaching(boolean httpCaching) Enables or disables the emission of HTTP caching headers for this response.- Parameters:
httpCaching- true=emit caching headers, false otherwise
-
isHttpCaching
public boolean isHttpCaching()Should this response emit HTTP caching headers?- Returns:
- true=yes emit headers, false otherwise
-
setHttpHeader
Sets a response header with the given name and value. This header will be included in the HTTP response If the header had already been set, the new value overwrites the previous ones (all of them if there are multiple for the same name).- Parameters:
name- the name of the headervalue- the header value If it contains octet string, it should be encoded according to RFC 2047 (http://www.ietf.org/rfc/rfc2047.txt)- See Also:
-
addHttpHeader
Adds a response header with the given name and value. This header will be included in the HTTP response This method allows response headers to have multiple values.- Parameters:
name- the name of the headervalue- the additional header value If it contains octet string, it should be encoded according to RFC 2047 (http://www.ietf.org/rfc/rfc2047.txt)- See Also:
-
getHttpHeader
Gets the value of the response header with the given name.If a response header with the given name exists and contains multiple values, the value that was added first will be returned.
NOTE: this runs in linear time (it scans starting at the beginning of the list until it finds the first pair with the specified name).
- Parameters:
name- the name of the response header whose value to return- Returns:
- the value of the response header with the given name, or
nullif no header with the given name has been set on this response
-
getHttpHeaders
Gets the values of the response header with the given name.- Parameters:
name- the name of the response header whose values to return- Returns:
- a (possibly empty)
Collectionof the values of the response header with the given name
-
removeHttpHeader
Removes a previously added header with the given name (only the first one if multiple are present for the same name)NOTE: this runs in linear time (it scans starting at the beginning of the list until it finds the first pair with the specified name).
- Parameters:
name- the name of the response header to remove- Returns:
- the value of the removed entry or
nullif no value is found for the given header name
-
removeHttpHeaders
Removes all previously added headers with the given name.- Parameters:
name- the name of the response headers to remove- Returns:
- a
Collectionwith all the values of the removed entries. It returnsnullif no entries are found for the given name
-
httpHeaders
Returns a new iterator of response headers- Returns:
- a new Iterator instance for the response headers
-