* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*
* @package Solarium
* @subpackage Client
*/
/**
* Build a document analysis request
*
* @package Solarium
* @subpackage Client
*/
class Solarium_Client_RequestBuilder_Analysis_Document extends Solarium_Client_RequestBuilder_Analysis
{
/**
* Build request for an analysis document query
*
* @param Solarium_Query_Analysis_Document $query
* @return Solarium_Client_Request
*/
public function build($query)
{
$request = parent::build($query);
$request->setRawData($this->getRawData($query));
$request->setMethod(Solarium_Client_Request::METHOD_POST);
return $request;
}
/**
* Create the raw post data (xml)
*
* @param Solarium_Query_Analysis_Document $query
* @return string
*/
public function getRawData($query)
{
$xml = '';
foreach ($query->getDocuments() AS $doc) {
$xml .= '';
foreach ($doc->getFields() AS $name => $value) {
if (is_array($value)) {
foreach ($value AS $multival) {
$xml .= $this->_buildFieldXml($name, $multival);
}
} else {
$xml .= $this->_buildFieldXml($name, $value);
}
}
$xml .= '';
}
$xml .= '';
return $xml;
}
/**
* Build XML for a field
*
* @param string $name
* @param mixed $value
* @return string
*/
protected function _buildFieldXml($name, $value)
{
return '' . htmlspecialchars($value, ENT_NOQUOTES, 'UTF-8') . '';
}
}