Solr 4.0 has a new feature of Atomic Updates, http://wiki.apache.org/solr/Atomic_Updates. Can I use it with 7.x? I just want to update a multivalued field manually. Is there any hook to use? Thanks.

Comments

monisha-malik’s picture

Issue summary: View changes
monisha-malik’s picture

You can either use a terminal command like this to change value of solr document :

curl 'localhost:8983/solr/update?commit=true' -H 'Content-type:application/json' -d '[{"id":"qq9att/node/2441","entity_id":{"set":100}}]'

This will change the entity id from 2441 to 100

Or
You can do this dynamically whenever your field is getting saved:

function apache_solr_atomic_update($entity_id, $fields, $entity_type) {
  $id  = apachesolr_document_id($entity_id, $entity_type);
  $options['method'] = 'POST';
  $options['headers']['Content-Type'] = 'application/json';
  $options['data'] = '[{"id":"qq9att/node/2442","entity_id":{"set":100}}]'; //This will change the entity id from 2441 to 100
  $environment = apachesolr_environment_load('solr');     //This will give you host and port where solr is running
  $url = $environment['url'].'/update?commit=true'; 
  $result = drupal_http_request($url, $options); //You can print $result to see the status. Status 200 is for successful updation
}

Note: Make sure you make the following changes in Solr configuration
1. In schema.xml add :-

    <field name="_version_" type="long" indexed="true" stored="true"/>
    

2. In solrconfig.xml add :-

    <updateLog class="solr.FSUpdateLog">
      <str name="dir">${solr.data.dir:}</str>
    </updateLog>