Esempio n. 1
0
 /** List of the papers available
  * @access public
  * @return void
  */
 public function indexAction()
 {
     $ping = $this->_solr->createPing();
     if (!$this->_solr->ping($ping)) {
         echo '<h2>Search engine system error</h2>';
         echo '<p>Solr service not responding.</p>';
     } else {
         $form = new SolrForm();
         $form->removeElement('thumbnail');
         $this->view->form = $form;
         if ($this->_request->isPost()) {
             $data = $this->getAllParams();
             if ($form->isValid($data)) {
                 $this->redirect($this->view->url(array('module' => 'search', 'controller' => 'results', 'action' => 'index', 'q' => $data['q'])));
             } else {
                 $form->populate($form->getValues());
             }
         }
     }
 }
Esempio n. 2
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->input = $input;
     $this->output = $output;
     $parts = parse_url($input->getArgument('url'));
     $config = array('adapteroptions' => array('host' => $parts['host'], 'port' => isset($parts['port']) ? $parts['port'] : 80, 'path' => $parts['path']));
     $client = new \Solarium_Client($config);
     $ping = $client->createPing();
     $q_start = microtime(TRUE);
     $response = $client->execute($ping);
     $client_query_time = round((microtime(TRUE) - $q_start) * 1000, 1) . 'ms';
     $body = $response->getResponse()->getBody();
     if (!empty($body)) {
         $data = json_decode($body);
         $status = isset($data->status) ? $data->status : 'Unknown';
         $server_query_time = isset($data->responseHeader->QTime) ? $data->responseHeader->QTime . 'ms' : 'Unknown';
         $output->writeln("Ping status {$status} completed in (client/server) {$client_query_time}/{$server_query_time}");
     }
 }
$optionsSolrOne = array('host' => '127.0.0.1', 'port' => 8983);
$optionsSolrTwo = array('host' => '127.0.0.1', 'port' => 7574);
$loadbalancer->addServer('solr1', $optionsSolrOne, 100);
$loadbalancer->addServer('solr2', $optionsSolrTwo, 200);
$loadbalancer->addServer('solr3', $optionsSolrTwo, 1);
// create a basic query to execute
$query = $client->createSelect();
// execute the query multiple times, displaying the server for each execution
for ($i = 1; $i <= 8; $i++) {
    $resultset = $client->select($query);
    echo 'Query execution #' . $i . '<br/>';
    echo 'NumFound: ' . $resultset->getNumFound() . '<br/>';
    echo 'Server: ' . $loadbalancer->getLastServerKey() . '<hr/>';
}
// force a server for a query (normally solr 3 is extremely unlikely based on it's weight)
$loadbalancer->setForcedServerForNextQuery('solr3');
$resultset = $client->select($query);
echo 'Query execution with server forced to solr3<br/>';
echo 'NumFound: ' . $resultset->getNumFound() . '<br/>';
echo 'Server: ' . $loadbalancer->getLastServerKey() . '<hr/>';
// test a ping query
$query = $client->createPing();
$client->ping($query);
echo 'Loadbalanced ping query, should display a loadbalancing server:<br/>';
echo 'Ping server: ' . $loadbalancer->getLastServerKey() . '<hr/>';
// exclude ping query from loadbalancing
$loadbalancer->addBlockedQueryType(Solarium_Client::QUERYTYPE_PING);
$client->ping($query);
echo 'Non-loadbalanced ping query, should not display a loadbalancing server:<br/>';
echo 'Ping server: ' . $loadbalancer->getLastServerKey() . '<hr/>';
htmlFooter();
 /**
  * Test whether the server environment is configured properly.
  *
  * Run a series of tests to determine whether the correct software is installed, permissions
  * are correct, and settings are enabled.
  *
  * @throws Exception if the environment test fails
  */
 function test_environment()
 {
     /*
      * Make sure that the PHP Data Objects extension is enabled.
      */
     if (!defined('PDO::ATTR_DRIVER_NAME')) {
         $this->logger->message('PHP Data Objects (PDO) must be enabled.', 10);
         $error = TRUE;
     }
     /*
      * Make sure that PDO MySQL support exists.
      */
     if (!in_array('mysql', PDO::getAvailableDrivers())) {
         $this->logger->message('PHP Data Objects (PDO) must have a MySQL driver enabled.', 10);
         $error = TRUE;
     }
     /*
      * Make sure that HTML Tidy is available within PHP or, failing that, at the command line.
      */
     if (class_exists('tidy', FALSE) == FALSE) {
         /*
          * A non-zero return status from a program called via exec() indicates an error.
          */
         exec('which tidy', $result, $status);
         if ($status != 0) {
             $this->logger->message('HTML Tidy must be installed.', 10);
             $error = TRUE;
         }
     }
     /*
      * Make sure that php-xml is installed.
      */
     if (extension_loaded('xml') == FALSE) {
         $this->logger->message('PHP’s XML extension must be installed and enabled.', 10);
         $error = TRUE;
     }
     /*
      * Make sure that xmllint is installed.
      */
     exec('which xmllint', $result, $status);
     if ($status != 0) {
         $this->logger->message('xmllint must be installed.', 10);
         $error = TRUE;
     }
     /*
      * Make sure that zip is installed.
      */
     exec('which zip', $result, $status);
     if ($status != 0) {
         $this->logger->message('zip must be installed.', 10);
         $error = TRUE;
     }
     /*
      * Make sure that the configuration file is writable.
      */
     if (is_writable(INCLUDE_PATH . '/config.inc.php') !== TRUE) {
         $this->logger->message('config.inc.php must be writable by the server.', 10);
         $error = TRUE;
     }
     /*
      * Make sure that sitemap.xml is writable.
      */
     if (is_writable(WEB_ROOT . '/sitemap.xml') !== TRUE) {
         $this->logger->message('sitemap.xml must be writable by the server', 3);
         $error = TRUE;
     }
     /*
      * Make sure that .htaccess is writable.
      */
     if (is_writable(WEB_ROOT . '/.htaccess') !== TRUE) {
         $this->logger->message('.htaccess must be writable by the server', 3);
         $error = TRUE;
     }
     /*
      * If the Downloads directory exists, make sure that it's writable.
      */
     if (is_writable(WEB_ROOT . '/downloads') !== TRUE) {
         $this->logger->message('The downloads directory (' . WEB_ROOT . '/downloads/' . ') must be writable by the server.', 10);
         $error = TRUE;
     }
     if (defined('SOLR_URL')) {
         /*
          * Make sure that Solr is responsive.
          */
         Solarium_Autoloader::register();
         $client = new Solarium_Client($GLOBALS['solr_config']);
         $ping = $client->createPing();
         try {
             $result = $client->ping($ping);
         } catch (Solarium_Exception $e) {
             $this->logger->message('Solr must be installed, configured in config.inc.php, and running.', 10);
             $error = TRUE;
         }
     }
     if (isset($error)) {
         return FALSE;
     }
     return TRUE;
 }
<?php

require 'init.php';
htmlHeader();
// check solarium version available
echo 'Solarium library version: ' . Solarium_Version::VERSION . ' - ';
// create a client instance
$client = new Solarium_Client($config);
// create a ping query
$ping = $client->createPing();
// execute the ping query
try {
    $client->ping($ping);
    echo 'Ping query succesful';
} catch (Solarium_Exception $e) {
    echo 'Ping query failed';
}
htmlFooter();