diff --git a/composer.json b/composer.json index 9f11bca5b2..9adaf3f7c9 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ "dailymotion/sdk" : "~1.5", "data-uri/data-uri" : "~0.1.0", "doctrine/orm" : "~2.4.0", - "elasticsearch/elasticsearch" : "~0.4", + "elasticsearch/elasticsearch" : "~1.0", "facebook/php-sdk" : "~3.0", "gedmo/doctrine-extensions" : "~2.3.0", "alchemy/google-plus-api-client" : "~0.6.2", diff --git a/composer.lock b/composer.lock index 5df66f544b..ece5645a0c 100644 --- a/composer.lock +++ b/composer.lock @@ -3,7 +3,7 @@ "This file locks the dependencies of your project to a known state", "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file" ], - "hash": "0d8e038306a0c58deac6187e6a607e71", + "hash": "88bbe728663cb23ecfba31d240af17c3", "packages": [ { "name": "alchemy-fr/tcpdf-clone", @@ -1150,16 +1150,16 @@ }, { "name": "elasticsearch/elasticsearch", - "version": "v0.4.4", + "version": "v1.0", "source": { "type": "git", "url": "https://github.com/elasticsearch/elasticsearch-php.git", - "reference": "53df7beea2d66b3ec41e023945e97fe0e240f72b" + "reference": "09a81a85ab015cd1350c622bebe9111941259782" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/elasticsearch/elasticsearch-php/zipball/53df7beea2d66b3ec41e023945e97fe0e240f72b", - "reference": "53df7beea2d66b3ec41e023945e97fe0e240f72b", + "url": "https://api.github.com/repos/elasticsearch/elasticsearch-php/zipball/09a81a85ab015cd1350c622bebe9111941259782", + "reference": "09a81a85ab015cd1350c622bebe9111941259782", "shasum": "" }, "require": { @@ -1172,12 +1172,13 @@ }, "require-dev": { "athletic/athletic": "~0.1", - "elasticsearch/elasticsearch_src": "*", + "elasticsearch/elasticsearch_src": "dev-master", "mikey179/vfsstream": "~1.2", "mockery/mockery": "dev-master@dev", "phpunit/phpunit": "3.7.*", "satooshi/php-coveralls": "dev-master", - "symfony/yaml": "2.4.*@dev" + "symfony/yaml": "2.4.*@dev", + "twig/twig": "1.*" }, "type": "library", "autoload": { @@ -1202,7 +1203,7 @@ "elasticsearch", "search" ], - "time": "2014-01-07 22:34:33" + "time": "2014-02-12 14:57:02" }, { "name": "evenement/evenement", diff --git a/lib/Alchemy/Phrasea/SearchEngine/Elastic/ElasticSearchEngine.php b/lib/Alchemy/Phrasea/SearchEngine/Elastic/ElasticSearchEngine.php index 99f3fee79e..cce4ad4b5f 100644 --- a/lib/Alchemy/Phrasea/SearchEngine/Elastic/ElasticSearchEngine.php +++ b/lib/Alchemy/Phrasea/SearchEngine/Elastic/ElasticSearchEngine.php @@ -286,8 +286,9 @@ class ElasticSearchEngine implements SearchEngineInterface $n = 0; foreach ($res['hits']['hits'] as $hit) { - $results[] = new \record_adapter($this->app, $hit['fields']['databox_id'], $hit['fields']['record_id'], $n); - $n++; + $databoxId = is_array($hit['fields']['databox_id']) ? array_pop($hit['fields']['databox_id']) : $hit['fields']['databox_id']; + $recordId = is_array($hit['fields']['record_id']) ? array_pop($hit['fields']['record_id']) : $hit['fields']['record_id']; + $results[] = new \record_adapter($this->app, $databoxId, $recordId, $n++); } return new SearchEngineResult($results, $query, $res['took'], $offset, $res['hits']['total'], $res['hits']['total'], null, null, $suggestions, [], $this->indexName); @@ -310,6 +311,7 @@ class ElasticSearchEngine implements SearchEngineInterface $params = $this->createQueryParams($query, $options ?: new SearchEngineOptions(), $record); $res = $this->doExecute('search', $params); + $ret = []; foreach ($fields as $name => $field) { if (isset($res['hits']['hits'][0]['highlight']['caption.'.$name])) { diff --git a/lib/Alchemy/Phrasea/SearchEngine/Elastic/Indexer.php b/lib/Alchemy/Phrasea/SearchEngine/Elastic/Indexer.php index 892f22924c..8e51756c97 100644 --- a/lib/Alchemy/Phrasea/SearchEngine/Elastic/Indexer.php +++ b/lib/Alchemy/Phrasea/SearchEngine/Elastic/Indexer.php @@ -246,11 +246,23 @@ class Indexer $ret = $this->engine->getClient()->indices()->create($indexParams); - if (isset($ret['error']) || !$ret['ok']) { + if (!$this->isResultOk($ret)) { throw new \RuntimeException('Unable to create index'); } } + private function isResultOk(array $ret) + { + if (isset($ret['acknowledged']) && $ret['acknowledged']) { + return true; + } + if (isset($ret['ok']) && $ret['ok']) { + return true; + } + + return false; + } + public function reindexAll() { $qty = 10; @@ -260,7 +272,7 @@ class Indexer $ret = $this->engine->getClient()->indices()->putSettings($params); - if (!isset($ret['ok']) || !$ret['ok']) { + if (!$this->isResultOk($ret)) { $this->logger->error('Unable to set the refresh interval to 300 s. .'); } @@ -290,7 +302,7 @@ class Indexer $ret = $this->engine->getClient()->indices()->putSettings($params); - if (!isset($ret['ok']) || !$ret['ok']) { + if (!$this->isResultOk($ret)) { throw new \RuntimeException('Unable to set the refresh interval to 1 s. .'); } } diff --git a/lib/classes/record/adapter.php b/lib/classes/record/adapter.php index 96643cf109..53eab6893b 100644 --- a/lib/classes/record/adapter.php +++ b/lib/classes/record/adapter.php @@ -165,7 +165,6 @@ class record_adapter implements record_Interface, cache_cacheableInterface $this->record_id = (int) $record_id; return $this->load(); - ; } protected function load()