protected function Apache_Solr_Service::_documentToXmlFragment in Apache Solr Search 5
Create an XML fragment from a {@link Apache_Solr_Document} instance appropriate for use inside a Solr add call
Return value
string
2 calls to Apache_Solr_Service::_documentToXmlFragment()
- Apache_Solr_Service::addDocument in SolrPhpClient/
Apache/ Solr/ Service.php - Add a Solr Document to the index
- Apache_Solr_Service::addDocuments in SolrPhpClient/
Apache/ Solr/ Service.php - Add an array of Solr Documents to the index all at once
File
- SolrPhpClient/
Apache/ Solr/ Service.php, line 710
Class
- Apache_Solr_Service
- Starting point for the Solr API. Represents a Solr server resource and has methods for pinging, adding, deleting, committing, optimizing and searching.
Code
protected function _documentToXmlFragment(Apache_Solr_Document $document) {
$xml = '<doc>';
foreach ($document as $key => $value) {
$key = htmlspecialchars($key, ENT_QUOTES, 'UTF-8');
if (is_array($value)) {
foreach ($value as $multivalue) {
$multivalue = htmlspecialchars($multivalue, ENT_NOQUOTES, 'UTF-8');
$xml .= '<field name="' . $key . '">' . $multivalue . '</field>';
}
}
else {
$value = htmlspecialchars($value, ENT_NOQUOTES, 'UTF-8');
$xml .= '<field name="' . $key . '">' . $value . '</field>';
}
}
$xml .= '</doc>';
return $xml;
}