Exemplo n.º 1
0
 public function testBlockedQueryTypeNotLoadbalanced()
 {
     $originalHost = $this->_client->getAdapter()->getHost();
     $servers = array('s1' => array('options' => $this->_serverOptions, 'weight' => 100), 's2' => array('options' => $this->_serverOptions, 'weight' => 1));
     $this->_plugin->setServers($servers);
     $request = new Solarium_Client_Request();
     $query = new Solarium_Query_Update();
     // this is a blocked querytype that should not be loadbalanced
     $this->_plugin->preCreateRequest($query);
     $this->_plugin->preExecuteRequest($request);
     $this->assertEquals($originalHost, $this->_client->getAdapter()->getHost());
     $this->assertEquals(null, $this->_plugin->getLastServerKey());
 }
Exemplo n.º 2
0
 /** 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;
 }
Exemplo n.º 3
0
 public function testSetAndGetAdapterWithObject()
 {
     $adapterClass = 'MyAdapter';
     $this->_client->setAdapter(new $adapterClass());
     $this->assertThat($this->_client->getAdapter(), $this->isInstanceOf($adapterClass));
 }
<?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>';