public function postSearch()
 {
     $enabled = Config::get("search.enabled");
     if (!$enabled) {
         App::abort(404);
         return;
     }
     $term = isset($_POST["term"]) ? $_POST["term"] : "";
     $client = Elasticsearch\ClientBuilder::create()->setHosts(Config::get("search.hosts"))->build();
     $params = ['index' => 'website', 'type' => 'mediaItem', 'body' => ['query' => ['dis_max' => ['tie_breaker' => 0.3, 'queries' => [['dis_max' => ['tie_breaker' => 0.3, 'queries' => [['multi_match' => ['query' => $term, 'type' => 'most_fields', 'fields' => ['name^10', 'name.std'], 'boost' => 13]], ['multi_match' => ['query' => $term, 'type' => 'most_fields', 'fields' => ['description^10', 'description.std'], 'boost' => 11]]]]], ['nested' => ['path' => 'playlists.playlist', 'query' => ['dis_max' => ['tie_breaker' => 0.3, 'queries' => [['multi_match' => ['query' => $term, 'type' => 'most_fields', 'fields' => ['playlists.playlist.name^10', 'playlists.playlist.name.std'], 'boost' => 8]], ['multi_match' => ['query' => $term, 'type' => 'most_fields', 'fields' => ['playlists.playlist.description^10', 'playlists.playlist.description.std'], 'boost' => 6]]]]]]], ['nested' => ['path' => 'playlists.playlist.show', 'query' => ['dis_max' => ['tie_breaker' => 0.3, 'queries' => [['multi_match' => ['query' => $term, 'type' => 'most_fields', 'fields' => ['playlists.playlist.show.name^10', 'playlists.playlist.show.name.std'], 'boost' => 3]], ['multi_match' => ['query' => $term, 'type' => 'most_fields', 'fields' => ['playlists.playlist.show.description^10', 'playlists.playlist.show.description.std'], 'boost' => 1]]]]]]]]]]]];
     $result = $client->search($params);
     if ($result["timed_out"]) {
         App::abort(500);
         // server error
         return;
     }
     $results = array();
     if ($result["hits"]["total"] > 0) {
         foreach ($result["hits"]["hits"] as $hit) {
             $source = $hit["_source"];
             $result = array("title" => $source["name"], "description" => $source["description"], "thumbnailUri" => $source["playlists"][0]["coverArtUri"], "url" => $source["playlists"][0]["url"]);
             $results[] = $result;
         }
     }
     return Response::json(array("results" => $results));
 }
Exemple #2
1
 public static function removeFromIndex($b)
 {
     if (defined('ELIB_BLOG_ELASTIC') && ELIB_BLOG_ELASTIC) {
         $params = ['index' => 'elib_blog', 'type' => 'blog', 'id' => $b->id];
         $client = ClientBuilder::create()->build();
         $response = $client->delete($params);
     }
 }
 /**
  * @author Martin Lonsky (martin@lonsky.net, +420 736 645876)
  * @return \Elasticsearch\Client
  */
 public function getElasticSearchClient()
 {
     if ($this->_elasticsearch instanceof \Elasticsearch\Client) {
         return $this->_elasticsearch;
     }
     $this->_elasticsearch = $this->_elasticsearch_builder->build();
     $this->_elasticsearch_builder = null;
     return $this->_elasticsearch;
 }
 /**
  * Register any application services.
  *
  * @return void
  */
 public function register()
 {
     $this->app->singleton('elasticsearch', function ($app) {
         $es = new ClientBuilder();
         $client = $es->create()->setHosts(config('elasticsearch.hosts', ['localhost']))->build();
         $this->app->instance('elasticsearch', $client);
         return $client;
     });
 }
 protected function setUp()
 {
     $config = ['db_name' => 'test', 'hosts' => ['127.0.0.1:9200']];
     $client = ClientBuilder::create()->setHosts($config['hosts'])->build();
     $this->client = new ElasticSearch($config, $client);
     $this->client->drop('test');
 }
 /**
  * Create a new command instance.
  */
 public function __construct(CLImate $cli, IpUtils $ipUtils)
 {
     parent::__construct();
     $this->cli = $cli;
     $this->ipUtils = $ipUtils;
     $this->esClient = ClientBuilder::create()->setHosts(config('elasticsearch.hosts'))->build();
 }
Exemple #7
0
 function __construct()
 {
     $this->hosts = array(ES_HOST . ":" . ES_PORT);
     $this->clientBuilder = \Elasticsearch\ClientBuilder::create();
     $this->clientBuilder->setHosts($this->hosts);
     $this->client = $this->clientBuilder->build();
 }
Exemple #8
0
 public function testConstructor()
 {
     $elasticsearchClient = \Elasticsearch\ClientBuilder::create()->build();
     $cmClient = new CM_Elasticsearch_Client($elasticsearchClient);
     $this->assertInstanceOf('CM_Elasticsearch_Client', $cmClient);
     $this->assertEquals($elasticsearchClient, CMTest_TH::callProtectedMethod($cmClient, '_getClient'));
 }
Exemple #9
0
 private function hotSwapIndices($versionedIndex, $entityIndexName)
 {
     $client = ClientBuilder::create()->setHosts(config('elasticquent.config.hosts'))->build();
     $indexExists = $client->indices()->exists(['index' => $entityIndexName]);
     $previousIndexName = null;
     $indices = $client->indices()->getAliases();
     foreach ($indices as $indexName => $indexData) {
         if (array_key_exists('aliases', $indexData) && isset($indexData['aliases'][$entityIndexName])) {
             $previousIndexName = $indexName;
             break;
         }
     }
     if ($indexExists === true && $previousIndexName === null) {
         $client->indices()->delete(['index' => $entityIndexName]);
         $client->indices()->putAlias(['name' => $entityIndexName, 'index' => $versionedIndex]);
     } else {
         if ($previousIndexName !== null) {
             $client->indices()->deleteAlias(['name' => $entityIndexName, 'index' => $previousIndexName]);
         }
         $client->indices()->putAlias(['name' => $entityIndexName, 'index' => $versionedIndex]);
         if ($previousIndexName !== null) {
             $client->indices()->delete(['index' => $previousIndexName]);
         }
     }
 }
 public function client()
 {
     if (empty($this->clientConnection)) {
         $this->clientConnection = ClientBuilder::create()->setHosts($this->hosts())->build();
     }
     return $this->clientConnection;
 }
 /**
  * Build and configure an Elasticsearch client.
  *
  * @param array $config
  * @return \Elasticsearch\Client
  */
 protected function buildClient(array $config)
 {
     $clientBuilder = ClientBuilder::create();
     // Configure hosts
     $clientBuilder->setHosts($config['hosts']);
     // Configure logging
     if (array_get($config, 'logging')) {
         $logObject = array_get($config, 'logObject');
         $logPath = array_get($config, 'logPath');
         $logLevel = array_get($config, 'logLevel');
         if ($logObject && $logObject instanceof LoggerInterface) {
             $clientBuilder->setLogger($logObject);
         } else {
             if ($logPath && $logLevel) {
                 $logObject = ClientBuilder::defaultLogger($logPath, $logLevel);
                 $clientBuilder->setLogger($logObject);
             }
         }
     }
     // Set additional client configuration
     foreach ($this->configMappings as $key => $method) {
         $value = array_get($config, $key);
         if ($value !== null) {
             call_user_func([$clientBuilder, $method], $value);
         }
     }
     // Build and return the client
     return $clientBuilder->build();
 }
Exemple #12
0
 public function testCustomQueryParams()
 {
     $params = array();
     $client = Elasticsearch\ClientBuilder::create()->setHosts([$_SERVER['ES_TEST_HOST']])->build();
     $getParams = array('index' => 'test', 'type' => 'test', 'id' => 1, 'parent' => 'abc', 'custom' => array('customToken' => 'abc', 'otherToken' => 123));
     $exists = $client->exists($getParams);
 }
Exemple #13
0
 public function __construct($hostUrl, $index)
 {
     $hosts = array($hostUrl);
     $this->esClient = ClientBuilder::create()->setHosts($hosts)->setRetries(2)->build();
     $this->index = $index;
     $this->jobs = ['body' => []];
 }
 /**
  * Create a new command instance.
  */
 public function __construct(Ubench $bench, IpUtils $ipUtils)
 {
     parent::__construct();
     $this->bench = $bench;
     $this->ipUtils = $ipUtils;
     $this->esClient = ClientBuilder::create()->setHosts(config('elasticsearch.hosts'))->build();
 }
Exemple #15
0
 public function __construct()
 {
     global $argv;
     $this->colors = new Colors();
     if (file_exists('resume.lock') && $argv[1] != 'resume') {
         $this->resume();
     }
     if (isset($argv[1]) && $argv[1] == 'resume') {
         echo PHP_EOL . 'Resuming from previous state' . PHP_EOL;
         if (file_exists('resume.lock')) {
             $this->offset = (int) file_get_contents('resume.lock');
         } else {
             echo PHP_EOL . 'resume.lock file does not exist. Exiting...';
             die(PHP_EOL);
         }
     }
     if (strlen(DB_TABLE) == 0) {
         echo PHP_EOL . $this->colors->getColoredString("Database table is not defined. Please check the Config.php file.", 'red') . PHP_EOL;
         die;
     }
     try {
         $this->database = new medoo(['database_type' => 'mysql', 'database_name' => DB_NAME, 'server' => DB_HOST, 'username' => DB_USER, 'password' => DB_PASS, 'charset' => 'utf8', 'port' => DB_PORT]);
     } catch (Exception $e) {
         echo PHP_EOL . $this->colors->getColoredString("Error While Connection to mySQL Database,\nPlease check your Database connection settings in config.php", 'red') . PHP_EOL;
         die;
     }
     if (USE_DB_COLUMN == TRUE) {
         $this->idCol = DB_COL;
     }
     global $ES_HOST;
     $this->logger = \Elasticsearch\ClientBuilder::defaultLogger('mySQLtoes.log');
     $this->elasticSearch = \Elasticsearch\ClientBuilder::create()->setLogger($this->logger)->setHosts($ES_HOST)->build();
 }
 /**
  * Create a new logger instance for the Elasticsearch client and modify the
  * config for the client builder accordingly.
  *
  * @param  array $config
  * @return array
  */
 protected function createLoggerConfig($config)
 {
     $logger = \Elasticsearch\ClientBuilder::defaultLogger($config['logPath'], $config['logLevel']);
     unset($config['logPath'], $config['logLevel']);
     $config['logger'] = $logger;
     return $config;
 }
Exemple #17
0
 public function __construct($host)
 {
     $builder = Elasticsearch\ClientBuilder::create();
     $builder->setHosts(array($host));
     $this->client = $builder->build();
     $this->logger = new NullLogger();
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $this->info('Creating search index.');
     // (re)set all version numbers in the database to make sure everything gets indexed
     $data = ["pending_search_index_version" => 1, "current_search_index_version" => 0];
     DB::table("media_items")->update($data);
     DB::table("playlists")->update($data);
     DB::table("shows")->update($data);
     $esClient = Elasticsearch\ClientBuilder::create()->setHosts(Config::get("search.hosts"))->build();
     $showProperties = ['id' => ['type' => 'integer', 'index' => 'no'], 'name' => ['type' => 'string', 'analyzer' => 'english', 'fields' => ['std' => ['type' => 'string', 'analyzer' => 'standard']]], 'description' => ['type' => 'string', 'analyzer' => 'english', 'fields' => ['std' => ['type' => 'string', 'analyzer' => 'standard']]], 'url' => ['type' => 'string', 'index' => 'no']];
     $playlistProperties = ['id' => ['type' => 'integer', 'index' => 'no'], 'name' => ['type' => 'string', 'analyzer' => 'english', 'fields' => ['std' => ['type' => 'string', 'analyzer' => 'standard']]], 'description' => ['type' => 'string', 'analyzer' => 'english', 'fields' => ['std' => ['type' => 'string', 'analyzer' => 'standard']]], 'scheduledPublishTime' => ['type' => 'date'], 'coverArtUri' => ['type' => 'string', 'index' => 'no'], 'seriesNo' => ['type' => 'integer', 'index' => 'no'], 'url' => ['type' => 'string', 'index' => 'no'], 'show' => ['type' => 'nested', 'properties' => $showProperties]];
     $mediaItemProperties = ['id' => ['type' => 'integer', 'index' => 'no'], 'name' => ['type' => 'string', 'analyzer' => 'english', 'fields' => ['std' => ['type' => 'string', 'analyzer' => 'standard']]], 'description' => ['type' => 'string', 'analyzer' => 'english', 'fields' => ['std' => ['type' => 'string', 'analyzer' => 'standard']]], 'scheduledPublishTime' => ['type' => 'date'], 'playlists' => ['type' => 'nested', 'properties' => ['generatedName' => ['type' => 'string', 'analyzer' => 'english', 'fields' => ['std' => ['type' => 'string', 'analyzer' => 'standard']]], 'coverArtUri' => ['type' => 'string', 'index' => 'no'], 'url' => ['type' => 'string', 'index' => 'no'], 'playlist' => ['type' => 'nested', 'properties' => $playlistProperties]]]];
     // creating 3 indexes "mediaItem", "playlist" and "show".
     // the "mediaItem" index contains copies of data in "playlist" and "show" and
     // the "playlist" index contains copies of data in "show"
     // this duplication is more optimum for searching according to https://www.elastic.co/guide/en/elasticsearch/guide/current/denormalization.html
     // https://www.elastic.co/guide/en/elasticsearch/guide/current/root-object.html
     $params = ['index' => 'website', 'body' => ['mappings' => ['_default_' => ['dynamic' => "strict", 'include_in_all' => false], 'mediaItem' => ['properties' => $mediaItemProperties], 'playlist' => ['properties' => $playlistProperties], 'show' => ['properties' => $showProperties]]]];
     $response = $esClient->indices()->create($params);
     if ($response['acknowledged']) {
         $this->info("Index created!");
     } else {
         $this->error("Something went wrong.");
     }
     $this->info('Done.');
 }
Exemple #19
0
 /**
  * 构造函数,初始化基本的链接es客户端
  *
  * @Author   tianyunzi
  * @DateTime 2016-05-26T14:26:49+0800
  * @param    [type]                   $hosts [description]
  */
 public function __construct($hosts)
 {
     if (empty($hosts)) {
         throw new Exception("please give really es config!");
     }
     $this->client = ClientBuilder::create()->setHosts($hosts)->build();
 }
 /**
  * Register the service provider.
  *
  * @return void
  */
 public function register()
 {
     $this->mergeConfigFrom(__DIR__ . '/../../config/config.php', 'bouncy');
     $this->app->singleton('elastic', function ($app) {
         //return new ElasticSearch($app['config']->get('elasticsearch'));
         return ClientBuilder::create()->build();
     });
 }
 private function savePodcasts($podcastList)
 {
     $client = ClientBuilder::create()->build();
     foreach ($podcastList as $id => $podcast) {
         echo "Adding podcast number: {$id}\n";
         $client->index($this->build($id, $podcast));
     }
 }
 /**
  * Create a new command instance.
  *
  * @return void
  */
 public function __construct()
 {
     parent::__construct();
     $this->bench = new Ubench();
     $this->esClient = ClientBuilder::create()->setHosts(config('elasticsearch.hosts'))->build();
     $this->versionedIndex = $this->indexName . '_' . time();
     $this->ipUtils = new IpUtils();
 }
 /**
  * Register Elasticsearch client.
  */
 protected function registerDuctibleClient()
 {
     $this->app->singleton(['Elasticsearch\\Client' => 'ductible.client'], function ($app) {
         $config = $app->make('config')->get('ductible');
         $client = ClientBuilder::create()->setHosts(explode('|', $config['hosts']))->setRetries($config['retries'])->setLogger($app->make('ductible.client.logger'))->setHandler($app->make('ductible.client.handler'))->setConnectionPool($config['pool'])->setSelector($config['selector'])->setSerializer($config['serializer'])->build();
         return $client;
     });
 }
 /**
  * Register the application services.
  *
  * @return void
  */
 public function register()
 {
     $this->app->singleton('elastic', function () {
         $clientBuilder = ClientBuilder::create();
         $clientBuilder->setHosts(config('eswrapper.hosts'), ['localhost:9200']);
         return $clientBuilder->build();
     });
 }
 /**
  */
 public static function setUpBeforeClass()
 {
     if (!class_exists('Elasticsearch\\Client') || self::skipTest()) {
         self::markTestSkipped("ElasticSearch library not found.");
     }
     self::$index = uniqid('test_');
     self::$type = uniqid();
     self::$client = ClientBuilder::create()->build();
 }
 /**
  * Register the Elasticsearch Client.
  *
  * @param array $config
  * @return void
  */
 protected function registerElasticsearchClient(array $config = [])
 {
     $this->app->bind(ElasticsearchClient::class, function () use($config) {
         return ElasticsearchClientBuilder::fromConfig($config);
     }, isset($config['singleton']) && $config['singleton']);
     $this->app->alias(ElasticsearchClient::class, $this->prefix());
 }
 /**
  * @param array $config
  *
  * @return Client
  */
 public function create(array $config)
 {
     if (class_exists('\\Elasticsearch\\ClientBuilder')) {
         return \Elasticsearch\ClientBuilder::fromConfig($config);
     }
     return new Client($config);
 }
 /**
  * Get ElasticSearch Client
  *
  * @return \Elasticsearch\Client
  */
 public function getElasticSearchClient()
 {
     $config = array();
     if (config()->has('elasticquent.config')) {
         $config = config()->get('elasticquent.config');
     }
     return \Elasticsearch\ClientBuilder::fromConfig($config);
 }
 /**
  * @return Client
  */
 public static function build($hosts)
 {
     $params = [];
     if (isset($hosts)) {
         $params['hosts'] = $hosts;
     }
     return ClientBuilder::fromConfig($params);
 }
 /**
  * Get ElasticSearch Client
  *
  * @return \Elasticsearch\Client
  */
 public function getElasticSearchClient()
 {
     $config = array();
     if (\Config::has('elasticquent.config')) {
         $config = \Config::get('elasticquent.config');
     }
     return \Elasticsearch\ClientBuilder::fromConfig($config, true);
 }