* @license http://github.com/basdenooijer/solarium/raw/master/COPYING * @link http://www.solarium-project.org/ * * @package Solarium * @subpackage Client */ /** * Class for building Solarium client requests * * @package Solarium * @subpackage Client */ abstract class Solarium_Client_RequestBuilder { /** * Build request for a select query * * @param Solarium_Query $query * @return Solarium_Client_Request */ public function build($query) { $request = new Solarium_Client_Request; $request->setHandler($query->getHandler()); $request->addParams($query->getParams()); $request->addParam('wt', 'json'); return $request; } /** * Render a param with localParams * * LocalParams can be use in various Solr GET params. * @link http://wiki.apache.org/solr/LocalParams * * @param string $value * @param array $localParams in key => value format * @return string with Solr localparams syntax */ public function renderLocalParams($value, $localParams = array()) { $params = ''; foreach ($localParams AS $paramName => $paramValue) { if (empty($paramValue)) continue; if (is_array($paramValue)) { $paramValue = implode($paramValue, ','); } $params .= $paramName . '=' . $paramValue . ' '; } if ($params !== '') { $value = '{!' . trim($params) . '}' . $value; } return $value; } /** * Render a boolean attribute * * For use in building XML messages * * @param string $name * @param boolean $value * @return string */ public function boolAttrib($name, $value) { if (null !== $value) { $value = (true == $value) ? 'true' : 'false'; return $this->attrib($name, $value); } else { return ''; } } /** * Render an attribute * * For use in building XML messages * * @param string $name * @param striung $value * @return string */ public function attrib($name, $value) { if (null !== $value) { return ' ' . $name . '="' . $value . '"'; } else { return ''; } } }