solrupgradesolrcloudsolr5

Method for converting a Document from the index into a SolrDocument suitable for inclusion in a SolrQueryResponse


Struggling to find method for converting a Document from the index into a SolrDocument suitable for inclusion in a SolrQueryResponse for solr-core-5.5.2.jar

solr-core-5.2.1.jar had an ResponseWriterUtil.toSolrDocument(Document doc, IndexSchema schema) which is removed from solr-core-5.3.0 version

Thanks in advance


Solution

  • The ResponseWriterUtil class has been replaced with DocsStreamer (org.apache.solr.response.DocsStreamer).

    Depending on the API version, you either give it it's parameters from the ResultContext (for 5.5.2):

    DocsStreamer(DocList docList, Query query, SolrQueryRequest req, ReturnFields returnFields)
    static SolrDocument getDoc(Document doc, IndexSchema schema) 
    

    or in newer versions, you give it the resultcontext directly:

    DocsStreamer(ResultContext rctx) 
    static SolrDocument getDoc(Document doc, IndexSchema schema) 
    

    If you use the constructor you get an iterator over the doclist from the result context, and you can use .next() to move to the next document as necessary.