mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-18 15:33:15 +00:00
[SearchEngine] Fix tests
This commit is contained in:
@@ -42,17 +42,14 @@ class PhraseaEngine implements SearchEngineInterface
|
|||||||
{
|
{
|
||||||
$this->app = $app;
|
$this->app = $app;
|
||||||
$this->options = new SearchEngineOptions();
|
$this->options = new SearchEngineOptions();
|
||||||
|
|
||||||
$this->initialize();
|
|
||||||
$this->checkSession();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function checkSession()
|
private function checkSession()
|
||||||
{
|
{
|
||||||
if (!$this->app['phraseanet.user']) {
|
if (!$this->app['phraseanet.user']) {
|
||||||
throw new \RuntimeException('Phrasea currently support only authenticated queries');
|
throw new \RuntimeException('Phrasea currently support only authenticated queries');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!phrasea_open_session($this->app['session']->get('phrasea_session_id'), $this->app['phraseanet.user']->get_id())) {
|
if (!phrasea_open_session($this->app['session']->get('phrasea_session_id'), $this->app['phraseanet.user']->get_id())) {
|
||||||
if (!$ses_id = phrasea_create_session((string) $this->app['phraseanet.user']->get_id())) {
|
if (!$ses_id = phrasea_create_session((string) $this->app['phraseanet.user']->get_id())) {
|
||||||
throw new \Exception_InternalServerError('Unable to create phrasea session');
|
throw new \Exception_InternalServerError('Unable to create phrasea session');
|
||||||
@@ -60,13 +57,13 @@ class PhraseaEngine implements SearchEngineInterface
|
|||||||
$this->app['session']->set('phrasea_session_id', $ses_id);
|
$this->app['session']->set('phrasea_session_id', $ses_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function initialize()
|
private function initialize()
|
||||||
{
|
{
|
||||||
if(!self::$initialized) {
|
if(!self::$initialized) {
|
||||||
|
|
||||||
\phrasea::start($this->app['phraseanet.configuration']);
|
\phrasea::start($this->app['phraseanet.configuration']);
|
||||||
|
|
||||||
self::$initialized = true;
|
self::$initialized = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -216,6 +213,9 @@ class PhraseaEngine implements SearchEngineInterface
|
|||||||
*/
|
*/
|
||||||
public function query($query, $offset, $perPage)
|
public function query($query, $offset, $perPage)
|
||||||
{
|
{
|
||||||
|
$this->initialize();
|
||||||
|
$this->checkSession();
|
||||||
|
|
||||||
assert(is_int($offset));
|
assert(is_int($offset));
|
||||||
assert($offset >= 0);
|
assert($offset >= 0);
|
||||||
assert(is_int($perPage));
|
assert(is_int($perPage));
|
||||||
@@ -260,7 +260,7 @@ class PhraseaEngine implements SearchEngineInterface
|
|||||||
*/
|
*/
|
||||||
$this->total_available = $this->total_results = $this->app['session']->get('phrasea_engine_n_results');
|
$this->total_available = $this->total_results = $this->app['session']->get('phrasea_engine_n_results');
|
||||||
}
|
}
|
||||||
|
|
||||||
$res = phrasea_fetch_results(
|
$res = phrasea_fetch_results(
|
||||||
$this->app['session']->get('phrasea_session_id'), $offset + 1, $perPage, false
|
$this->app['session']->get('phrasea_session_id'), $offset + 1, $perPage, false
|
||||||
);
|
);
|
||||||
@@ -279,7 +279,7 @@ class PhraseaEngine implements SearchEngineInterface
|
|||||||
foreach ($rs as $data) {
|
foreach ($rs as $data) {
|
||||||
try {
|
try {
|
||||||
$records->add(new \record_adapter(
|
$records->add(new \record_adapter(
|
||||||
$this->app,
|
$this->app,
|
||||||
\phrasea::sbasFromBas($this->app, $data['base_id']),
|
\phrasea::sbasFromBas($this->app, $data['base_id']),
|
||||||
$data['record_id'],
|
$data['record_id'],
|
||||||
$resultNumber
|
$resultNumber
|
||||||
@@ -293,7 +293,7 @@ class PhraseaEngine implements SearchEngineInterface
|
|||||||
|
|
||||||
return new SearchEngineResult($records, $query, $row['duration'], $offset, $row['total'], $row['total'], $error, '', new ArrayCollection(), new ArrayCollection(), '');
|
return new SearchEngineResult($records, $query, $row['duration'], $offset, $row['total'], $row['total'], $error, '', new ArrayCollection(), new ArrayCollection(), '');
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function create(Application $app)
|
public static function create(Application $app)
|
||||||
{
|
{
|
||||||
return new static($app);
|
return new static($app);
|
||||||
@@ -386,7 +386,7 @@ class PhraseaEngine implements SearchEngineInterface
|
|||||||
if ($this->app['phraseanet.user']) {
|
if ($this->app['phraseanet.user']) {
|
||||||
\User_Adapter::saveQuery($this->app, $query);
|
\User_Adapter::saveQuery($this->app, $query);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user