Exemplo n.º 1
0
 public function testServerStatus()
 {
     $client = new Elastica_Client();
     $status = $client->getStatus();
     $serverStatus = $status->getServerStatus();
     $this->assertTrue(!empty($serverStatus));
     $this->assertTrue('array' == gettype($serverStatus));
     $this->assertArrayHasKey('ok', $serverStatus);
     $this->assertTrue($serverStatus['ok']);
     $this->assertArrayHasKey('version', $serverStatus);
     $versionInfo = $serverStatus['version'];
     $this->assertArrayHasKey('number', $versionInfo);
 }
Exemplo n.º 2
0
 public function testShutdown()
 {
     $this->markTestSkipped('This test shuts down the cluster which means the following tests would not work');
     $client = new Elastica_Client();
     $cluster = $client->getCluster();
     $cluster->shutdown('2s');
     sleep(5);
     try {
         $client->getStatus();
         $this->fail('Should throw exception because cluster is shut down');
     } catch (Elastica_Exception_Client $e) {
         $this->assertTrue(true);
     }
 }
/**
 * Main search controller.
 * 
 * @param string $key
 */
function find_search($key)
{
    drupal_add_css(drupal_get_path('module', 'find') . '/css/find_search.css', array('group' => CSS_DEFAULT, 'every_page' => true));
    drupal_add_css(drupal_get_path('module', 'find') . '/css/find_print.css', array('group' => CSS_DEFAULT, 'every_page' => true, 'media' => 'print'));
    drupal_add_js('http://maps.google.com/maps/api/js?sensor=false&libraries=geometry,places', array('group' => JS_LIBRARY));
    drupal_add_library('system', 'ui.sortable');
    drupal_add_js(drupal_get_path('module', 'area') . '/css/overlay-style.js');
    drupal_add_js(drupal_get_path('module', 'area') . '/js/geometry.js');
    drupal_add_js(drupal_get_path('module', 'find') . '/js/find.js');
    drupal_add_css(drupal_get_path('module', 'gallery') . '/css/jquery.lightbox.css', array('group' => CSS_DEFAULT, 'every_page' => TRUE));
    drupal_add_js(drupal_get_path('module', 'gallery') . '/js/jquery.lightbox.js', array('weight' => 100));
    drupal_add_js(drupal_get_path('module', 'gallery') . '/js/gallery.lightbox.js');
    $variables = array('#theme' => 'find.search');
    // fetch $_GET parameters
    $params = find_query_params(array('search' => '', 'geo' => array(), 'date' => array(), 'class' => array(), 'user' => array(), 'family' => array(), 'genus' => array(), 'town' => array(), 'canton' => array(), 'redlist' => array(), 'habitat' => array(), 'image_type' => array(), 'columns' => array(), 'sort' => array()));
    $params['uid'] = $GLOBALS['user']->uid;
    try {
        $client = new Elastica_Client();
        $status = $client->getStatus();
        // ping to make sure elasticsearch is running
        $index = $client->getIndex('naturwerk');
        $parameters = new Parameters($params);
        $variables['#organisms'] = new Organisms($index, $parameters);
        $variables['#sightings'] = new Sightings($index, $parameters);
        $variables['#inventories'] = new Inventories($index, $parameters);
        $variables['#areas'] = new Areas($index, $parameters);
        $variables['#images'] = new Images($index, $parameters);
        // make parameters available to JavaScript
        $parameters = drupal_get_query_parameters();
        if (count($parameters) == 0) {
            $parameters = new stdClass();
            // force empty JSON object
        }
        drupal_add_js(array('find' => array('url' => url($_GET['q']), 'parameters' => $parameters, 'geo' => $params['geo'])), 'setting');
        $variables['#key'] = $key;
        $variables['#current'] = $variables['#' . $key];
        $output = array();
        $output['search'] = $variables;
        return $output;
    } catch (Elastica_Exception_Client $e) {
        watchdog('find', $e->getMessage(), array(), WATCHDOG_ERROR);
        drupal_set_message(t('Search error. Elasticsearch running?'), 'error');
        return array();
    }
}
 public static function init($host = '', $index_name = '', $username = '', $password = '')
 {
     if (self::$client !== NULL && self::$index !== NULL) {
         return;
     }
     $config = Symphony::Engine()->Configuration()->get('elasticsearch');
     if (empty($host)) {
         $host = $config['host'];
     }
     if (empty($index_name)) {
         $index_name = $config['index-name'];
     }
     if (empty($username)) {
         $username = $config['username'];
     }
     if (empty($password)) {
         $password = $config['password'];
     }
     if (empty($host)) {
         throw new Exception('ElasticSearch "host" not set in configuration.');
     }
     if (empty($index_name)) {
         throw new Exception('ElasticSearch "index-name" not set in configuration.');
     }
     try {
         $client = new Elastica_Client(array('url' => $host));
         if (!empty($username) && !empty($password)) {
             $client->addHeader('Authorization', 'Basic ' . base64_encode($username . ':' . $password));
         }
         $client->getStatus();
     } catch (Exception $e) {
         throw new Exception('ElasticSearch client: ' . $e->getMessage());
     }
     $index = $client->getIndex($index_name);
     if ($auto_create_index) {
         //if(!$index->exists()) $index->create(array(), TRUE);
     }
     self::$client = $client;
     self::$index = $index;
 }