Uploaded image for project: 'Solr'
  1. Solr
  2. SOLR-948

Add helper functions to SolrPluginUtils that replace the DocList response with SolrDocumentList

    XMLWordPrintableJSON

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.4
    • Component/s: None
    • Labels:
      None

      Description

      We should add an easy (reusable) way for a search component to augment/modify the SolrDocuments before they are returned.

      This patch adds two functions to SolrPluginUtils:

        public static SolrDocumentList docListToSolrDocumentList( 
            DocList docs, 
            SolrIndexSearcher searcher, 
            Set<String> fields, 
            Map<SolrDocument, Integer> ids ) throws IOException
        {
      

      and

        public static void addOrReplaceResults(SolrQueryResponse rsp, SolrDocumentList docs) 
      

      Typical usage may look like this:

        public void process(ResponseBuilder builder) throws IOException 
        {
          if( you want to ) {
      
            SolrDocumentList docs = SolrPluginUtils.docListToSolrDocumentList(
                builder.getResults().docList, 
                builder.req.getSearcher(), 
                builder.rsp.getReturnFields(),
                null );
      
            for( SolrDocument doc : docs ) {
              doc.setField( "field", "your field value..."   );
            }
            
            SolrPluginUtils.addOrReplaceResults( builder.rsp, docs );
          }
        }
      
      

        Attachments

        1. SOLR-948-augment-helper.patch
          3 kB
          Ryan McKinley

          Issue Links

            Activity

              People

              • Assignee:
                ryantxu Ryan McKinley
                Reporter:
                ryantxu Ryan McKinley
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: