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; }