SolrPHP doesn't provide any method to update a specific field in Solr.
However, you can make a Curl call in PHP to update a specific field:
<?php
// Update array
$update = array(
'id' => $docId,
$solrFieldName => array(
'set' => $solrFieldValue
)
);
$update = json_encode(array($update));
// Create curl resource and URL
$ch = curl_init('http://'.SOLR_HOSTNAME.':'.SOLR_PORT.'/'.SOLR_COLLECTION.'/update?commit=true');
// Set Login/Password auth (if required)
curl_setopt($ch, CURLOPT_USERPWD, SOLR_LOGIN.':'.SOLR_PASSWORD);
// Set POST fields
curl_setopt($ch, CURLOPT_POST,true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $update);
// Return transfert
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// Set type of data sent
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
// Get response result
$output = json_decode(curl_exec($ch));
// Get response code
$responseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
// Close Curl resource
curl_close($ch);
if ($responseCode == 200)
{
echo 'SOLR: Updated successfully field '.$solrFieldName.' for id:'.$docId.' (query time: '.$output->responseHeader->QTime.'ms).';
}
else
{
echo ('SOLR: Can\'t update field '.$solrFieldName.' for id:'.$docId.', response ('.$responseCode.') is: '.print_r($output,true));
}
I use this code to update in JSON, you can also provide data in XML.