Class SolrQueryResponse

java.lang.Object
org.apache.solr.response.SolrQueryResponse

public class SolrQueryResponse extends Object
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.

  • String
  • Integer
  • Long
  • Float
  • Double
  • Boolean
  • Date
  • DocList
  • SolrDocument (since 1.3)
  • SolrDocumentList (since 1.3)
  • Map containing any of the items in this list
  • NamedList containing any of the items in this list
  • Collection containing 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 Details

  • Constructor Details

    • SolrQueryResponse

      public SolrQueryResponse()
  • Method Details

    • getValues

      public org.apache.solr.common.util.NamedList<Object> getValues()
      Gets data to be returned in this response
      See Also:
    • setAllValues

      public void setAllValues(org.apache.solr.common.util.NamedList<Object> nameValuePairs)
      Sets data to be returned in this response
      See Also:
    • setReturnFields

      public void setReturnFields(ReturnFields fields)
      Sets the document field names of fields to return by default when returning DocLists
    • getReturnFields

      public ReturnFields getReturnFields()
      Gets the document field names of fields to return by default when returning DocLists
    • setPartialResults

      public void setPartialResults(SolrQueryRequest req)
      If getResponseHeader() is available, set RESPONSE_HEADER_PARTIAL_RESULTS_KEY attribute to true or "omitted" as required.
    • partialResultsStatus

      public static Object partialResultsStatus(boolean discarding)
    • isPartialResults

      public static boolean isPartialResults(org.apache.solr.common.util.NamedList<?> header)
      If getResponseHeader() is available, return the value of RESPONSE_HEADER_PARTIAL_RESULTS_KEY or 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

      public void addPartialResponseDetail(Object detail)
      If getResponseHeader() 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

      public void add(String name, Object val)
      Appends a named value to the list of named values to be returned.
      Parameters:
      name - the name of the value - may be null if unnamed
      val - the value to add - also may be null since null is a legal value
      See Also:
    • setException

      public void setException(Exception e)
      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

      public Exception getException()
      Returns an Exception if there was a fatal error in processing the request. Returns null if the request succeeded.
    • addResponseHeader

      public void addResponseHeader(org.apache.solr.common.util.NamedList<Object> header)
      Set response header
    • removeResponseHeader

      public void removeResponseHeader()
      Clear response header
    • getResponseHeader

      public org.apache.solr.common.util.NamedList<Object> getResponseHeader()
      Response header to be logged
    • addResponse

      public void addResponse(Object response)
      Set response
    • getResponse

      public Object getResponse()
      Return response
    • addToLog

      public void addToLog(String name, Object val)
      Add a value to be logged.
      Parameters:
      name - name of the thing to log
      val - value of the thing to log
    • getToLog

      public org.apache.solr.common.util.NamedList<Object> getToLog()
      Get loggable items.
      Returns:
      things to log
    • getToLogAsString

      public String getToLogAsString()
    • getToLogAsString

      public String getToLogAsString(String prefix)
      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

      public void setHttpHeader(String name, String value)
      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 header
      value - 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

      public void addHttpHeader(String name, String value)
      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 header
      value - 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

      public String getHttpHeader(String name)
      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 null if no header with the given name has been set on this response
    • getHttpHeaders

      public Collection<String> getHttpHeaders(String name)
      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) Collection of the values of the response header with the given name
    • removeHttpHeader

      public String removeHttpHeader(String name)
      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 null if no value is found for the given header name
    • removeHttpHeaders

      public Collection<String> removeHttpHeaders(String name)
      Removes all previously added headers with the given name.
      Parameters:
      name - the name of the response headers to remove
      Returns:
      a Collection with all the values of the removed entries. It returns null if no entries are found for the given name
    • httpHeaders

      public Iterator<Map.Entry<String,String>> httpHeaders()
      Returns a new iterator of response headers
      Returns:
      a new Iterator instance for the response headers