/** The constructor * */ public function __construct() { $this->_cache = Zend_Registry::get('cache'); $this->_config = Zend_Registry::get('config'); $this->_solrConfig = array('adapteroptions' => $this->_config->solr->toArray()); $this->_solr = new Solarium_Client($this->_solrConfig); $this->_solr->setAdapter('Solarium_Client_Adapter_ZendHttp'); $loadbalancer = $this->_solr->getPlugin('loadbalancer'); $master = $this->_config->solr->master->toArray(); $slave = $this->_config->solr->slave->toArray(); $loadbalancer->addServer('master', $master, 100); $loadbalancer->addServer('slave', $slave, 200); $loadbalancer->setFailoverEnabled(true); }
public function testExecuteRequestPostPlugin() { $request = new Solarium_Client_Request(); $dummyResponse = 'dummyresponse'; $mockAdapter = $this->getMock('Solarium_Client_Adapter', array('execute')); $mockAdapter->expects($this->any())->method('execute')->with($this->equalTo($request))->will($this->returnValue($dummyResponse)); $this->_client->setAdapter($mockAdapter); $response = $this->_client->executeRequest($request); $observer = $this->getMock('Solarium_Plugin_Abstract', array(), array($this->_client, array())); $observer->expects($this->once())->method('postExecuteRequest')->with($this->equalTo($request), $this->equalTo($response)); $this->_client->registerPlugin('testplugin', $observer); $this->_client->executeRequest($request); }
/** Get the solr object for querying cores * @access public * @return \Solarium_Client */ public function getSolr() { $this->_solr = new Solarium_Client($this->getSolrConfig()); $this->_solr->setAdapter('Solarium_Client_Adapter_ZendHttp'); $this->_solr->getAdapter()->getZendHttp(); $loadbalancer = $this->_solr->getPlugin('loadbalancer'); $master = $this->getConfig()->solr->master->toArray(); $asgard = $this->getConfig()->solr->asgard->toArray(); $valhalla = $this->getConfig()->solr->valhalla->toArray(); $loadbalancer->addServer('objects', $master, 100); $loadbalancer->addServer('asgard', $asgard, 200); $loadbalancer->addServer('valhalla', $valhalla, 150); $loadbalancer->setFailoverEnabled(true); $this->_solr->getAdapter()->getZendHttp(); $this->_loadbalancer = $loadbalancer; return $this->_solr; }
public function testFailoverMaxRetries() { $this->_plugin = new TestLoadbalancer(); // special loadbalancer that returns servers in fixed order $this->_client = new Solarium_Client(); $adapter = new TestAdapterForFailover(); $adapter->setFailCount(10); $this->_client->setAdapter($adapter); // set special mock that fails for all servers $this->_plugin->init($this->_client, array()); $request = new Solarium_Client_Request(); $servers = array('s1' => array('options' => $this->_serverOptions, 'weight' => 1), 's2' => array('options' => $this->_serverOptions, 'weight' => 1)); $this->_plugin->setServers($servers); $this->_plugin->setFailoverEnabled(true); $query = new Solarium_Query_Select(); $this->_plugin->preCreateRequest($query); $this->setExpectedException('Solarium_Exception', 'Maximum number of loadbalancer retries reached'); $this->_plugin->preExecuteRequest($request); }
<?php require_once 'Zend/Loader/Autoloader.php'; $loader = Zend_Loader_Autoloader::getInstance(); require 'init.php'; htmlHeader(); // create a client instance $client = new Solarium_Client($config); // set the adapter to curl $client->setAdapter('Solarium_Client_Adapter_Curl'); // get a select query instance $query = $client->createSelect(); // this executes the query and returns the result $resultset = $client->select($query); // display the total number of documents found by solr echo 'NumFound: ' . $resultset->getNumFound(); // show documents using the resultset iterator foreach ($resultset as $document) { echo '<hr/><table>'; // the documents are also iterable, to get all fields foreach ($document as $field => $value) { // this converts multivalue fields to a comma-separated string if (is_array($value)) { $value = implode(', ', $value); } echo '<tr><th>' . $field . '</th><td>' . $value . '</td></tr>'; } echo '</table>'; } htmlFooter();
<?php require_once 'Zend/Loader/Autoloader.php'; $loader = Zend_Loader_Autoloader::getInstance(); require 'init.php'; htmlHeader(); // create a client instance $client = new Solarium_Client($config); // set the adapter to zendhttp and get a zendhttp client instance reference $client->setAdapter('Solarium_Client_Adapter_ZendHttp'); $zendHttp = $client->getAdapter()->getZendHttp(); // you can use any of the zend_http features, like http-authentication $zendHttp->setAuth('user', 'password!', Zend_Http_Client::AUTH_BASIC); // get a select query instance $query = $client->createSelect(); // this executes the query and returns the result $resultset = $client->select($query); // display the total number of documents found by solr echo 'NumFound: ' . $resultset->getNumFound(); // show documents using the resultset iterator foreach ($resultset as $document) { echo '<hr/><table>'; // the documents are also iterable, to get all fields foreach ($document as $field => $value) { // this converts multivalue fields to a comma-separated string if (is_array($value)) { $value = implode(', ', $value); } echo '<tr><th>' . $field . '</th><td>' . $value . '</td></tr>'; } echo '</table>';
/** * Instantiates the class; sets and configures the Solarium client * @param Solarium_Client $client */ public function __construct(Solarium_Client $client) { $this->client = $client; $this->client->setAdapter('Solarium_Client_Adapter_Curl'); parent::__construct(); }
<?php require_once 'Zend/Loader/Autoloader.php'; $loader = Zend_Loader_Autoloader::getInstance(); require 'init.php'; htmlHeader(); // create a client instance $client = new Solarium_Client($config); // set the adapter to peclhttp $client->setAdapter('Solarium_Client_Adapter_PeclHttp'); // get a select query instance $query = $client->createSelect(); // this executes the query and returns the result $resultset = $client->select($query); // display the total number of documents found by solr echo 'NumFound: ' . $resultset->getNumFound(); // show documents using the resultset iterator foreach ($resultset as $document) { echo '<hr/><table>'; // the documents are also iterable, to get all fields foreach ($document as $field => $value) { // this converts multivalue fields to a comma-separated string if (is_array($value)) { $value = implode(', ', $value); } echo '<tr><th>' . $field . '</th><td>' . $value . '</td></tr>'; } echo '</table>'; } htmlFooter();