Example usage for org.apache.solr.response XMLWriter writeResponse

List of usage examples for org.apache.solr.response XMLWriter writeResponse

Introduction

In this page you can find the example usage for org.apache.solr.response XMLWriter writeResponse.

Prototype

public static void writeResponse(Writer writer, SolrQueryRequest req, SolrQueryResponse rsp)
            throws IOException 

Source Link

Usage

From source file:org.socialhistoryservices.api.oai.OAIQueryResponseWriter.java

License:Open Source License

/**
 * Get the Lucene document from the index and add it to a temporary response.
 *
 * @param writer//from   w w w  . j  a  va2s.  co m
 * @param request
 * @param docId
 * @return
 * @throws IOException
 */
private void writeRecord(Writer writer, SolrQueryRequest request, int docId)
        throws IOException, TransformerException {

    SolrParams params = request.getParams();
    final SolrQueryResponse dummy = new SolrQueryResponse();
    dummy.add("solrparams", params.toNamedList()); // May be used in the xslt.
    dummy.add("result", request.getSearcher().doc(docId));
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    OutputStreamWriter osw;
    try {
        osw = new OutputStreamWriter(baos, "UTF-8");
        XMLWriter.writeResponse(osw, request, dummy);
        osw.close();
    } catch (IOException e) {
        error(writer, e.getMessage());
    }

    transform(writer, baos, params.get("metadataPrefix"));
}