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

json update extract boost from document value

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Minor
    • Resolution: Won't Do
    • 3.6
    • None
    • None

    Description

      The current JsonLoader in org.apache.solr.handler provides a way to add a boost to a document as a whole. But if you want to add multiple documents,
      each with its own boost, you have to create something like this:

      {
      "add": { "boost":2.0, "doc": {} },
      "add": { "boost":2.0, "doc": {} }
      ..
      }

      No idea which JSON-writer can do this (I use the one from perl,
      that does not support duplicate keys).

      Therefore I tried to alter some of the code in JsonLoader::handleAdds.
      The code is between "//test - start" and "//test - end":

      cmd.solrDoc = parseDoc(ev);

      //test - start
      if(boost_field != null){
      SolrInputField b_field = cmd.solrDoc.getField(boost_field);
      if(b_field != null)

      { log.info("boost_field found in document with value '"+b_field.getFirstValue()+"'"); float boost = Float.parseFloat((String)b_field.getFirstValue()); cmd.solrDoc.setDocumentBoost(boost); cmd.solrDoc.removeField(boost_field); }

      }
      //test - end

      processor.processAdd(cmd);

      In this code I try to extract the boost value for the document from the document itself. The default field is configured as "_boost", and is deleted
      from the document afterwards.

      I tried to subclass JsonLoader, but sadly the class is package-protected

      Could this be an interesting contribution?

      Attachments

        Activity

          People

            Unassigned Unassigned
            njfranck Nicolas Franck
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: