Add compatibility with elasticsearch 1

This commit is contained in:
Romain Neutron
2014-03-05 00:40:11 +01:00
parent 024b5353b1
commit 82bd617477
5 changed files with 29 additions and 15 deletions

View File

@@ -15,7 +15,7 @@
"dailymotion/sdk" : "~1.5", "dailymotion/sdk" : "~1.5",
"data-uri/data-uri" : "~0.1.0", "data-uri/data-uri" : "~0.1.0",
"doctrine/orm" : "~2.4.0", "doctrine/orm" : "~2.4.0",
"elasticsearch/elasticsearch" : "~0.4", "elasticsearch/elasticsearch" : "~1.0",
"facebook/php-sdk" : "~3.0", "facebook/php-sdk" : "~3.0",
"gedmo/doctrine-extensions" : "~2.3.0", "gedmo/doctrine-extensions" : "~2.3.0",
"alchemy/google-plus-api-client" : "~0.6.2", "alchemy/google-plus-api-client" : "~0.6.2",

17
composer.lock generated
View File

@@ -3,7 +3,7 @@
"This file locks the dependencies of your project to a known state", "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" "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file"
], ],
"hash": "0d8e038306a0c58deac6187e6a607e71", "hash": "88bbe728663cb23ecfba31d240af17c3",
"packages": [ "packages": [
{ {
"name": "alchemy-fr/tcpdf-clone", "name": "alchemy-fr/tcpdf-clone",
@@ -1150,16 +1150,16 @@
}, },
{ {
"name": "elasticsearch/elasticsearch", "name": "elasticsearch/elasticsearch",
"version": "v0.4.4", "version": "v1.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/elasticsearch/elasticsearch-php.git", "url": "https://github.com/elasticsearch/elasticsearch-php.git",
"reference": "53df7beea2d66b3ec41e023945e97fe0e240f72b" "reference": "09a81a85ab015cd1350c622bebe9111941259782"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/elasticsearch/elasticsearch-php/zipball/53df7beea2d66b3ec41e023945e97fe0e240f72b", "url": "https://api.github.com/repos/elasticsearch/elasticsearch-php/zipball/09a81a85ab015cd1350c622bebe9111941259782",
"reference": "53df7beea2d66b3ec41e023945e97fe0e240f72b", "reference": "09a81a85ab015cd1350c622bebe9111941259782",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@@ -1172,12 +1172,13 @@
}, },
"require-dev": { "require-dev": {
"athletic/athletic": "~0.1", "athletic/athletic": "~0.1",
"elasticsearch/elasticsearch_src": "*", "elasticsearch/elasticsearch_src": "dev-master",
"mikey179/vfsstream": "~1.2", "mikey179/vfsstream": "~1.2",
"mockery/mockery": "dev-master@dev", "mockery/mockery": "dev-master@dev",
"phpunit/phpunit": "3.7.*", "phpunit/phpunit": "3.7.*",
"satooshi/php-coveralls": "dev-master", "satooshi/php-coveralls": "dev-master",
"symfony/yaml": "2.4.*@dev" "symfony/yaml": "2.4.*@dev",
"twig/twig": "1.*"
}, },
"type": "library", "type": "library",
"autoload": { "autoload": {
@@ -1202,7 +1203,7 @@
"elasticsearch", "elasticsearch",
"search" "search"
], ],
"time": "2014-01-07 22:34:33" "time": "2014-02-12 14:57:02"
}, },
{ {
"name": "evenement/evenement", "name": "evenement/evenement",

View File

@@ -286,8 +286,9 @@ class ElasticSearchEngine implements SearchEngineInterface
$n = 0; $n = 0;
foreach ($res['hits']['hits'] as $hit) { foreach ($res['hits']['hits'] as $hit) {
$results[] = new \record_adapter($this->app, $hit['fields']['databox_id'], $hit['fields']['record_id'], $n); $databoxId = is_array($hit['fields']['databox_id']) ? array_pop($hit['fields']['databox_id']) : $hit['fields']['databox_id'];
$n++; $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); 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); $params = $this->createQueryParams($query, $options ?: new SearchEngineOptions(), $record);
$res = $this->doExecute('search', $params); $res = $this->doExecute('search', $params);
$ret = [];
foreach ($fields as $name => $field) { foreach ($fields as $name => $field) {
if (isset($res['hits']['hits'][0]['highlight']['caption.'.$name])) { if (isset($res['hits']['hits'][0]['highlight']['caption.'.$name])) {

View File

@@ -246,11 +246,23 @@ class Indexer
$ret = $this->engine->getClient()->indices()->create($indexParams); $ret = $this->engine->getClient()->indices()->create($indexParams);
if (isset($ret['error']) || !$ret['ok']) { if (!$this->isResultOk($ret)) {
throw new \RuntimeException('Unable to create index'); 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() public function reindexAll()
{ {
$qty = 10; $qty = 10;
@@ -260,7 +272,7 @@ class Indexer
$ret = $this->engine->getClient()->indices()->putSettings($params); $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. .'); $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); $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. .'); throw new \RuntimeException('Unable to set the refresh interval to 1 s. .');
} }
} }

View File

@@ -165,7 +165,6 @@ class record_adapter implements record_Interface, cache_cacheableInterface
$this->record_id = (int) $record_id; $this->record_id = (int) $record_id;
return $this->load(); return $this->load();
;
} }
protected function load() protected function load()