diff --git a/lib/Alchemy/Phrasea/Controller/Client/Root.php b/lib/Alchemy/Phrasea/Controller/Client/Root.php index 2f398b7952..125a504998 100644 --- a/lib/Alchemy/Phrasea/Controller/Client/Root.php +++ b/lib/Alchemy/Phrasea/Controller/Client/Root.php @@ -78,7 +78,6 @@ class Root implements ControllerProviderInterface $perPage = $modCol * $modRow; $options = SearchEngineOptions::fromRequest($app, $request); - $app['phraseanet.SE']->setOptions($options); $currentPage = (int) $request->request->get('pag', 0); @@ -87,7 +86,7 @@ class Root implements ControllerProviderInterface $currentPage = 1; } - $result = $app['phraseanet.SE']->query($query, ($currentPage - 1) * $perPage, $perPage); + $result = $app['phraseanet.SE']->query($query, ($currentPage - 1) * $perPage, $perPage, $options); $userQuery = new UserQuery(); $userQuery->setUsrId($app['authentication']->getUser()->get_id()); diff --git a/lib/Alchemy/Phrasea/Controller/Prod/Query.php b/lib/Alchemy/Phrasea/Controller/Prod/Query.php index d15e2555b4..39102bd76a 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/Query.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/Query.php @@ -64,8 +64,6 @@ class Query implements ControllerProviderInterface $perPage = (int) $app['authentication']->getUser()->getPrefs('images_per_page'); - $app['phraseanet.SE']->setOptions($options); - $page = (int) $request->request->get('pag'); $firstPage = $page < 1; @@ -74,7 +72,7 @@ class Query implements ControllerProviderInterface $page = 1; } - $result = $app['phraseanet.SE']->query($query, (($page - 1) * $perPage), $perPage); + $result = $app['phraseanet.SE']->query($query, (($page - 1) * $perPage), $perPage, $options); $userQuery = new UserQuery(); $userQuery->setUsrId($app['authentication']->getUser()->get_id()); @@ -195,6 +193,7 @@ class Query implements ControllerProviderInterface 'results' => $result, 'highlight' => $result->getQuery(), 'searchEngine' => $app['phraseanet.SE'], + 'searchOptions' => $options, 'suggestions' => $prop ] ); @@ -224,7 +223,6 @@ class Query implements ControllerProviderInterface try { $options = SearchEngineOptions::hydrate($app, $optionsSerial); - $app['phraseanet.SE']->setOptions($options); } catch (\Exception $e) { $app->abort(400, 'Provided search engine options are not valid'); } @@ -232,7 +230,7 @@ class Query implements ControllerProviderInterface $pos = (int) $request->request->get('pos', 0); $query = $request->request->get('query', ''); - $record = new \record_preview($app, 'RESULT', $pos, '', $app['phraseanet.SE'], $query); + $record = new \record_preview($app, 'RESULT', $pos, '', $app['phraseanet.SE'], $query, $options); return $app->json([ 'current' => $app['twig']->render('prod/preview/result_train.html.twig', [ diff --git a/lib/Alchemy/Phrasea/Controller/Prod/Records.php b/lib/Alchemy/Phrasea/Controller/Prod/Records.php index 25d2acff5f..7da40451c2 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/Records.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/Records.php @@ -63,7 +63,7 @@ class Records implements ControllerProviderInterface $app->abort(400); } - $searchEngine = null; + $searchEngine = $options = null; $train = ''; if ('' === $env = strtoupper($request->get('env', ''))) { @@ -75,7 +75,6 @@ class Records implements ControllerProviderInterface try { $options = SearchEngineOptions::hydrate($app, $request->get('options_serial')); $searchEngine = $app['phraseanet.SE']; - $searchEngine->setOptions($options); } catch (\Exception $e) { $app->abort(400, 'Search-engine options are not valid or missing'); } @@ -91,7 +90,8 @@ class Records implements ControllerProviderInterface $pos < 0 ? 0 : $pos, $request->get('cont', ''), $searchEngine, - $query + $query, + $options ); if ($record->is_from_reg()) { @@ -116,7 +116,8 @@ class Records implements ControllerProviderInterface "desc" => $app['twig']->render('prod/preview/caption.html.twig', [ 'record' => $record, 'highlight' => $query, - 'searchEngine' => $searchEngine + 'searchEngine' => $searchEngine, + 'searchOptions' => $options, ]), "html_preview" => $app['twig']->render('common/preview.html.twig', [ 'record' => $record diff --git a/lib/Alchemy/Phrasea/Controller/Prod/Tooltip.php b/lib/Alchemy/Phrasea/Controller/Prod/Tooltip.php index ecf4bcc904..11b8e41161 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/Tooltip.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/Tooltip.php @@ -115,11 +115,11 @@ class Tooltip implements ControllerProviderInterface $record = new \record_adapter($app, $sbas_id, $record_id, $number); $search_engine = $app['phraseanet.SE']; + $search_engine_options = null; if ($context == 'answer') { try { $search_engine_options = SearchEngineOptions::hydrate($app, $app['request']->request->get('options_serial')); - $search_engine->setOptions($search_engine_options); } catch (\Exception $e) { } @@ -128,10 +128,11 @@ class Tooltip implements ControllerProviderInterface return $app['twig']->render( 'prod/Tooltip/Caption.html.twig' , [ - 'record' => $record, - 'view' => $context, - 'highlight' => $app['request']->request->get('query'), - 'searchEngine' => $search_engine, + 'record' => $record, + 'view' => $context, + 'highlight' => $app['request']->request->get('query'), + 'searchEngine' => $search_engine, + 'searchOptions' => $search_engine_options, ]); } diff --git a/lib/Alchemy/Phrasea/SearchEngine/Phrasea/PhraseaEngine.php b/lib/Alchemy/Phrasea/SearchEngine/Phrasea/PhraseaEngine.php index a01cdf7fb7..fd4fc71cc2 100644 --- a/lib/Alchemy/Phrasea/SearchEngine/Phrasea/PhraseaEngine.php +++ b/lib/Alchemy/Phrasea/SearchEngine/Phrasea/PhraseaEngine.php @@ -25,11 +25,6 @@ class PhraseaEngine implements SearchEngineInterface { private $initialized; - /** - * - * @var SearchEngineOptions - */ - private $options; private $app; private $dateFields; private $configuration; @@ -47,7 +42,6 @@ class PhraseaEngine implements SearchEngineInterface public function __construct(Application $app) { $this->app = $app; - $this->options = new SearchEngineOptions(); } /** @@ -339,28 +333,12 @@ class PhraseaEngine implements SearchEngineInterface /** * {@inheritdoc} */ - public function setOptions(SearchEngineOptions $options) + public function query($query, $offset, $perPage, SearchEngineOptions $options = null) { - $this->options = $options; + if (null === $options) { + $options = new SearchEngineOptions(); + } - return $this; - } - - /** - * {@inheritdoc} - */ - public function resetOptions() - { - $this->options = new SearchEngineOptions(); - - return $this; - } - - /** - * {@inheritdoc} - */ - public function query($query, $offset, $perPage) - { $this->initialize(); $this->checkSession(); @@ -372,8 +350,8 @@ class PhraseaEngine implements SearchEngineInterface $query = "all"; } - if ($this->options->getRecordType()) { - $query .= ' AND recordtype=' . $this->options->getRecordType(); + if ($options->getRecordType()) { + $query .= ' AND recordtype=' . $options->getRecordType(); } $sql = 'SELECT query, query_time, duration, total FROM cache WHERE session_id = :ses_id'; @@ -394,8 +372,8 @@ class PhraseaEngine implements SearchEngineInterface if ($this->resetCacheNextQuery === true) { phrasea_clear_cache($this->app['session']->get('phrasea_session_id')); - $this->addQuery($query); - $this->executeQuery($query); + $this->addQuery($query, $options); + $this->executeQuery($query, $options); $sql = 'SELECT query, query_time, duration, total FROM cache WHERE session_id = :ses_id'; $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); @@ -534,13 +512,13 @@ class PhraseaEngine implements SearchEngineInterface * @param string $query * @return PhraseaEngine */ - private function executeQuery($query) + private function executeQuery($query, SearchEngineOptions $options) { $nbanswers = $total_time = 0; $sort = ''; - if ($this->options->getSortBy()) { - switch ($this->options->getSortOrder()) { + if ($options->getSortBy()) { + switch ($options->getSortOrder()) { case SearchEngineOptions::SORT_MODE_ASC: $sort = '+'; break; @@ -549,13 +527,13 @@ class PhraseaEngine implements SearchEngineInterface $sort = '-'; break; } - $sort .= '0' . $this->options->getSortBy(); + $sort .= '0' . $options->getSortBy(); } foreach ($this->queries as $sbas_id => $qry) { $BF = []; - foreach ($this->options->getBusinessFieldsOn() as $collection) { + foreach ($options->getBusinessFieldsOn() as $collection) { // limit business field query to databox local collection if ($sbas_id === $collection->get_sbas_id()) { $BF[] = $collection->get_base_id(); @@ -570,10 +548,10 @@ class PhraseaEngine implements SearchEngineInterface , $this->app['conf']->get(['main', 'key']) , $this->app['session']->get('usr_id') , false - , $this->options->getSearchType() == SearchEngineOptions::RECORD_GROUPING ? PHRASEA_MULTIDOC_REGONLY : PHRASEA_MULTIDOC_DOCONLY + , $options->getSearchType() == SearchEngineOptions::RECORD_GROUPING ? PHRASEA_MULTIDOC_REGONLY : PHRASEA_MULTIDOC_DOCONLY , $sort , $BF - , $this->options->isStemmed() ? $this->options->getLocale() : null + , $options->isStemmed() ? $options->getLocale() : null ); if ($results) { @@ -603,7 +581,7 @@ class PhraseaEngine implements SearchEngineInterface /** * {@inheritdoc} */ - public function autocomplete($query) + public function autocomplete($query, SearchEngineOptions $options) { return new ArrayCollection(); } @@ -611,8 +589,12 @@ class PhraseaEngine implements SearchEngineInterface /** * {@inheritdoc} */ - public function excerpt($query, $fields, \record_adapter $record) + public function excerpt($query, $fields, \record_adapter $record, SearchEngineOptions $options = null) { + if (null === $options) { + $options = new SearchEngineOptions(); + } + $ret = []; $this->initialize(); @@ -670,13 +652,13 @@ class PhraseaEngine implements SearchEngineInterface * @param string $query * @return PhraseaEngine */ - private function addQuery($query) + private function addQuery($query, SearchEngineOptions $options) { - foreach ($this->options->getDataboxes() as $databox) { + foreach ($options->getDataboxes() as $databox) { $this->queries[$databox->get_sbas_id()] = $query; } - $status = $this->options->getStatus(); + $status = $options->getStatus(); foreach ($this->queries as $sbas => $qs) { if ($status) { @@ -704,32 +686,32 @@ class PhraseaEngine implements SearchEngineInterface $this->queries[$sbas] .= ' AND (recordstatus=' . $requestStat . ')'; } } - if ($this->options->getFields()) { + if ($options->getFields()) { $this->queries[$sbas] .= ' IN (' . implode(' OR ', array_map(function (\databox_field $field) { return $field->get_name(); - }, $this->options->getFields())) . ')'; + }, $options->getFields())) . ')'; } - if (($this->options->getMinDate() || $this->options->getMaxDate()) && $this->options->getDateFields()) { - if ($this->options->getMinDate()) { - $this->queries[$sbas] .= ' AND ( ' . implode(' >= ' . $this->options->getMinDate()->format('Y-m-d') . ' OR ', array_map(function (\databox_field $field) { return $field->get_name(); }, $this->options->getDateFields())) . ' >= ' . $this->options->getMinDate()->format('Y-m-d') . ' ) '; + if (($options->getMinDate() || $options->getMaxDate()) && $options->getDateFields()) { + if ($options->getMinDate()) { + $this->queries[$sbas] .= ' AND ( ' . implode(' >= ' . $options->getMinDate()->format('Y-m-d') . ' OR ', array_map(function (\databox_field $field) { return $field->get_name(); }, $options->getDateFields())) . ' >= ' . $options->getMinDate()->format('Y-m-d') . ' ) '; } - if ($this->options->getMaxDate()) { - $this->queries[$sbas] .= ' AND ( ' . implode(' <= ' . $this->options->getMaxDate()->format('Y-m-d') . ' OR ', array_map(function (\databox_field $field) { return $field->get_name(); }, $this->options->getDateFields())) . ' <= ' . $this->options->getMaxDate()->format('Y-m-d') . ' ) '; + if ($options->getMaxDate()) { + $this->queries[$sbas] .= ' AND ( ' . implode(' <= ' . $options->getMaxDate()->format('Y-m-d') . ' OR ', array_map(function (\databox_field $field) { return $field->get_name(); }, $options->getDateFields())) . ' <= ' . $options->getMaxDate()->format('Y-m-d') . ' ) '; } } } - $this->singleParse('main', $query); + $this->singleParse('main', $query, $options); foreach ($this->queries as $sbas => $db_query) { - $this->singleParse($sbas, $this->queries[$sbas]); + $this->singleParse($sbas, $this->queries[$sbas], $options); } $base_ids = array_map(function (\collection $collection) { return $collection->get_base_id(); - }, $this->options->getCollections()); + }, $options->getCollections()); - foreach ($this->options->getDataboxes() as $databox) { + foreach ($options->getDataboxes() as $databox) { $sbas_id = $databox->get_sbas_id(); $this->colls[$sbas_id] = []; @@ -771,9 +753,9 @@ class PhraseaEngine implements SearchEngineInterface * @param string $query * @return PhraseaEngine */ - private function singleParse($sbas, $query) + private function singleParse($sbas, $query, SearchEngineOptions $options) { - $this->qp[$sbas] = new PhraseaEngineQueryParser($this->app, $this->options->getLocale()); + $this->qp[$sbas] = new PhraseaEngineQueryParser($this->app, $options->getLocale()); $this->qp[$sbas]->debug = false; $simple_treeq = $this->qp[$sbas]->parsequery($query); diff --git a/lib/Alchemy/Phrasea/SearchEngine/SearchEngineInterface.php b/lib/Alchemy/Phrasea/SearchEngine/SearchEngineInterface.php index 1af71452bd..1e010b3702 100644 --- a/lib/Alchemy/Phrasea/SearchEngine/SearchEngineInterface.php +++ b/lib/Alchemy/Phrasea/SearchEngine/SearchEngineInterface.php @@ -162,32 +162,16 @@ interface SearchEngineInterface */ public function updateFeedEntry(FeedEntry $entry); - /** - * Set options to search-engine - * - * @param SearchEngineOptions $options - * @return SearchEngineInterface - * @throws RuntimeException - */ - public function setOptions(SearchEngineOptions $options); - - /** - * Reset search-engine options - * - * @return SearchEngineInterface - * @throws RuntimeException - */ - public function resetOptions(); - /** * * @param string $query * @param integer $offset * @param integer $perPage + * @param SearchEngineOptions $options * * @return SearchEngineResult */ - public function query($query, $offset, $perPage); + public function query($query, $offset, $perPage, SearchEngineOptions $options = null); /** * Return an array of suggestions corresponding to the last word of the @@ -197,7 +181,7 @@ interface SearchEngineInterface * * @return ArrayCollection A collection of SearchEngineSuggestion */ - public function autocomplete($query); + public function autocomplete($query, SearchEngineOptions $options); /** * Highlight the fields of a record @@ -208,7 +192,7 @@ interface SearchEngineInterface * * @return array The array of highlighted fields */ - public function excerpt($query, $fields, \record_adapter $record); + public function excerpt($query, $fields, \record_adapter $record, SearchEngineOptions $options = null); /** * Reset the cache of the SE (if applicable) diff --git a/lib/Alchemy/Phrasea/SearchEngine/SphinxSearch/SphinxSearchEngine.php b/lib/Alchemy/Phrasea/SearchEngine/SphinxSearch/SphinxSearchEngine.php index ad594ea999..79f0b50500 100644 --- a/lib/Alchemy/Phrasea/SearchEngine/SphinxSearch/SphinxSearchEngine.php +++ b/lib/Alchemy/Phrasea/SearchEngine/SphinxSearch/SphinxSearchEngine.php @@ -44,13 +44,11 @@ class SphinxSearchEngine implements SearchEngineInterface private $dateFields; protected $configuration; protected $configurationPanel; - protected $options; protected $app; public function __construct(Application $app, $host, $port, $rt_host, $rt_port) { $this->app = $app; - $this->options = new SearchEngineOptions(); $this->sphinx = new \SphinxClient(); $this->sphinx->SetServer($host, $port); @@ -417,28 +415,6 @@ class SphinxSearchEngine implements SearchEngineInterface throw new RuntimeException('Feed Entry indexing not supported by Sphinx Search Engine'); } - /** - * {@inheritdoc} - */ - public function setOptions(SearchEngineOptions $options) - { - $this->options = $options; - $this->applyOptions($options); - - return $this; - } - - /** - * {@inheritdoc} - */ - public function resetOptions() - { - $this->options = new SearchEngineOptions(); - $this->resetSphinx(); - - return $this; - } - private function resetSphinx() { $this->sphinx->ResetGroupBy(); @@ -450,8 +426,14 @@ class SphinxSearchEngine implements SearchEngineInterface /** * {@inheritdoc} */ - public function query($query, $offset, $perPage) + public function query($query, $offset, $perPage, SearchEngineOptions $options = null) { + if (null === $options) { + $options = new SearchEngineOptions(); + } + + $this->applyOptions($options); + assert(is_int($offset)); assert($offset >= 0); assert(is_int($perPage)); @@ -468,7 +450,7 @@ class SphinxSearchEngine implements SearchEngineInterface $this->sphinx->SetLimits($offset, $perPage); $this->sphinx->SetMatchMode(SPH_MATCH_EXTENDED2); - $index = $this->getQueryIndex($query); + $index = $this->getQueryIndex($query, $options); $res = $this->sphinx->Query($query, $index); $results = new ArrayCollection(); @@ -513,7 +495,7 @@ class SphinxSearchEngine implements SearchEngineInterface } } - $suggestions = $this->getSuggestions($query); + $suggestions = $this->getSuggestions($query, $options); $propositions = ''; } @@ -523,29 +505,37 @@ class SphinxSearchEngine implements SearchEngineInterface /** * {@inheritdoc} */ - public function autocomplete($query) + public function autocomplete($query, SearchEngineOptions $options) { + $this->applyOptions($options); + $words = explode(" ", $this->cleanupQuery($query)); - return $this->getSuggestions(array_pop($words)); + return $this->getSuggestions(array_pop($words), $options); } /** * {@inheritdoc} */ - public function excerpt($query, $fields, \record_adapter $record) + public function excerpt($query, $fields, \record_adapter $record, SearchEngineOptions $options = null) { + if (null === $options) { + $options = new SearchEngineOptions(); + } + + $this->applyOptions($options); + $index = ''; // in this case search is done on metas - if ($this->options->getFields() || $this->options->getBusinessFieldsOn()) { - if ($this->options->isStemmed() && $this->options->getLocale()) { - $index = 'metadatas' . $this->CRCdatabox($record->get_databox()) . '_stemmed_' . $this->options->getLocale(); + if ($options->getFields() || $options->getBusinessFieldsOn()) { + if ($options->isStemmed() && $options->getLocale()) { + $index = 'metadatas' . $this->CRCdatabox($record->get_databox()) . '_stemmed_' . $options->getLocale(); } else { $index = 'metadatas' . $this->CRCdatabox($record->get_databox()); } } else { - if ($this->options->isStemmed() && $this->options->getLocale()) { - $index = 'documents' . $this->CRCdatabox($record->get_databox()) . '_stemmed_' . $this->options->getLocale(); + if ($options->isStemmed() && $options->getLocale()) { + $index = 'documents' . $this->CRCdatabox($record->get_databox()) . '_stemmed_' . $options->getLocale(); } else { $index = 'documents' . $this->CRCdatabox($record->get_databox()); } @@ -775,7 +765,7 @@ class SphinxSearchEngine implements SearchEngineInterface * @param string $query * @return ArrayCollection An array collection of SearchEngineSuggestion */ - private function getSuggestions($query) + private function getSuggestions($query, SearchEngineOptions $options) { // First we split the query into simple words $words = explode(" ", $this->cleanupQuery(mb_strtolower($query))); @@ -798,10 +788,10 @@ class SphinxSearchEngine implements SearchEngineInterface } // As we got words, we look for alternate word for each of them - if (function_exists('enchant_broker_init') && $this->options->getLocale()) { + if (function_exists('enchant_broker_init') && $options->getLocale()) { $broker = enchant_broker_init(); - if (enchant_broker_dict_exists($broker, $this->options->getLocale())) { - $dictionnary = enchant_broker_request_dict($broker, $this->options->getLocale()); + if (enchant_broker_dict_exists($broker, $options->getLocale())) { + $dictionnary = enchant_broker_request_dict($broker, $options->getLocale()); foreach ($words as $word) { @@ -820,7 +810,7 @@ class SphinxSearchEngine implements SearchEngineInterface * @todo enhance the trigramm query, as it could be sent in one batch */ foreach ($altVersions as $word => $versions) { - $altVersions[$word] = array_unique(array_merge($versions, $this->get_sugg_trigrams($word))); + $altVersions[$word] = array_unique(array_merge($versions, $this->get_sugg_trigrams($word, $options))); } // We now build an array of all possibilities based on the original query @@ -842,7 +832,7 @@ class SphinxSearchEngine implements SearchEngineInterface $max_results = 0; foreach ($queries as $alt_query) { - $results = $this->sphinx->Query($alt_query, $this->getQueryIndex($alt_query)); + $results = $this->sphinx->Query($alt_query, $this->getQueryIndex($alt_query, $options)); if ($results !== false && isset($results['total_found'])) { if ($results['total_found'] > 0) { @@ -886,7 +876,7 @@ class SphinxSearchEngine implements SearchEngineInterface return $trigrams; } - private function get_sugg_trigrams($word) + private function get_sugg_trigrams($word, SearchEngineOptions $options) { $trigrams = $this->BuildTrigrams($word); $query = "\"$trigrams\"/1"; @@ -903,7 +893,7 @@ class SphinxSearchEngine implements SearchEngineInterface $indexes = []; - foreach ($this->options->getDataboxes() as $databox) { + foreach ($options->getDataboxes() as $databox) { $indexes[] = 'suggest' . $this->CRCdatabox($databox); } @@ -926,29 +916,29 @@ class SphinxSearchEngine implements SearchEngineInterface return $words; } - private function getQueryIndex($query) + private function getQueryIndex($query, SearchEngineOptions $options) { $index = '*'; $index_keys = []; - foreach ($this->options->getDataboxes() as $databox) { + foreach ($options->getDataboxes() as $databox) { $index_keys[] = $this->CRCdatabox($databox); } if (count($index_keys) > 0) { - if ($this->options->getFields() || $this->options->getBusinessFieldsOn()) { - if ($query !== '' && $this->options->isStemmed() && $this->options->getLocale()) { - $index = 'metadatas' . implode('_stemmed_' . $this->options->getLocale() . ', metadatas', $index_keys) . '_stemmed_' . $this->options->getLocale(); - $index .= ', metas_realtime_stemmed_' . $this->options->getLocale() . '_' . implode(', metas_realtime_stemmed_' . $this->options->getLocale() . '_', $index_keys); + if ($options->getFields() || $options->getBusinessFieldsOn()) { + if ($query !== '' && $options->isStemmed() && $options->getLocale()) { + $index = 'metadatas' . implode('_stemmed_' . $options->getLocale() . ', metadatas', $index_keys) . '_stemmed_' . $options->getLocale(); + $index .= ', metas_realtime_stemmed_' . $options->getLocale() . '_' . implode(', metas_realtime_stemmed_' . $options->getLocale() . '_', $index_keys); } else { $index = 'metadatas' . implode(',metadatas', $index_keys); $index .= ', metas_realtime' . implode(', metas_realtime', $index_keys); } } else { - if ($query !== '' && $this->options->isStemmed() && $this->options->getLocale()) { - $index = 'documents' . implode('_stemmed_' . $this->options->getLocale() . ', documents', $index_keys) . '_stemmed_' . $this->options->getLocale(); - $index .= ', docs_realtime_stemmed_' . $this->options->getLocale() . '_' . implode(', docs_realtime_stemmed_' . $this->options->getLocale() . '_', $index_keys); + if ($query !== '' && $options->isStemmed() && $options->getLocale()) { + $index = 'documents' . implode('_stemmed_' . $options->getLocale() . ', documents', $index_keys) . '_stemmed_' . $options->getLocale(); + $index .= ', docs_realtime_stemmed_' . $options->getLocale() . '_' . implode(', docs_realtime_stemmed_' . $options->getLocale() . '_', $index_keys); } else { $index = 'documents' . implode(', documents', $index_keys); $index .= ', docs_realtime' . implode(', docs_realtime', $index_keys); @@ -1079,5 +1069,4 @@ class SphinxSearchEngine implements SearchEngineInterface { return $this; } - } diff --git a/lib/classes/API/V1/adapter.php b/lib/classes/API/V1/adapter.php index b781e30b42..8fa6aefe6c 100644 --- a/lib/classes/API/V1/adapter.php +++ b/lib/classes/API/V1/adapter.php @@ -870,11 +870,9 @@ class API_V1_adapter extends API_V1_Abstract $perPage = (int) $request->get('per_page') ? : 10; $query = (string) $request->get('query'); - - $this->app['phraseanet.SE']->setOptions($options); $this->app['phraseanet.SE']->resetCache(); - $search_result = $this->app['phraseanet.SE']->query($query, $offsetStart, $perPage); + $search_result = $this->app['phraseanet.SE']->query($query, $offsetStart, $perPage, $options); $userQuery = new UserQuery(); $userQuery->setUsrId($this->app['authentication']->getUser()->get_id()); diff --git a/lib/classes/caption/interface.php b/lib/classes/caption/interface.php index 532b4ec25a..c523b22f54 100644 --- a/lib/classes/caption/interface.php +++ b/lib/classes/caption/interface.php @@ -11,11 +11,12 @@ use Alchemy\Phrasea\Application; use Alchemy\Phrasea\SearchEngine\SearchEngineInterface; +use Alchemy\Phrasea\SearchEngine\SearchEngineOptions; interface caption_interface { public function __construct(Application $app, record_Interface $record, databox $databox); - public function get_highlight_fields($highlight = '', Array $grep_fields = null, SearchEngineInterface $searchEngine = null); + public function get_highlight_fields($highlight = '', Array $grep_fields = null, SearchEngineInterface $searchEngine = null, $includeBusiness = false, SearchEngineOptions $options = null); } diff --git a/lib/classes/caption/record.php b/lib/classes/caption/record.php index 04c29c50fc..5c352efca7 100644 --- a/lib/classes/caption/record.php +++ b/lib/classes/caption/record.php @@ -11,6 +11,7 @@ use Alchemy\Phrasea\Application; use Alchemy\Phrasea\SearchEngine\SearchEngineInterface; +use Alchemy\Phrasea\SearchEngine\SearchEngineOptions; use Symfony\Component\Yaml\Dumper as YamlDumper; class caption_record implements caption_interface, cache_cacheableInterface @@ -284,9 +285,9 @@ class caption_record implements caption_interface, cache_cacheableInterface * * @return array */ - public function get_highlight_fields($highlight = '', Array $grep_fields = null, SearchEngineInterface $searchEngine = null, $includeBusiness = false) + public function get_highlight_fields($highlight = '', Array $grep_fields = null, SearchEngineInterface $searchEngine = null, $includeBusiness = false, SearchEngineOptions $options = null) { - return $this->highlight_fields($highlight, $grep_fields, $searchEngine, $includeBusiness); + return $this->highlight_fields($highlight, $grep_fields, $searchEngine, $includeBusiness, $options); } /** @@ -296,7 +297,7 @@ class caption_record implements caption_interface, cache_cacheableInterface * @param SearchEngineInterface $searchEngine * @return array */ - protected function highlight_fields($highlight, Array $grep_fields = null, SearchEngineInterface $searchEngine = null, $includeBusiness = false) + protected function highlight_fields($highlight, Array $grep_fields = null, SearchEngineInterface $searchEngine = null, $includeBusiness = false, SearchEngineOptions $options = null) { $fields = []; @@ -317,7 +318,7 @@ class caption_record implements caption_interface, cache_cacheableInterface } if ($searchEngine instanceof SearchEngineInterface) { - $ret = $searchEngine->excerpt($highlight, $fields, $this->record); + $ret = $searchEngine->excerpt($highlight, $fields, $this->record, $options); if ($ret) { $n = -1; diff --git a/lib/classes/record/adapter.php b/lib/classes/record/adapter.php index 9fe4dc8175..32aff6ed1d 100644 --- a/lib/classes/record/adapter.php +++ b/lib/classes/record/adapter.php @@ -14,6 +14,7 @@ use Alchemy\Phrasea\Border\File; use Alchemy\Phrasea\Metadata\Tag\TfFilename; use Alchemy\Phrasea\Metadata\Tag\TfBasename; use Alchemy\Phrasea\SearchEngine\SearchEngineInterface; +use Alchemy\Phrasea\SearchEngine\SearchEngineOptions; use Doctrine\ORM\EntityManager; use MediaAlchemyst\Specification\SpecificationInterface; use MediaVorus\Media\MediaInterface; @@ -871,7 +872,7 @@ class record_adapter implements record_Interface, cache_cacheableInterface * * @return string */ - public function get_title($highlight = false, SearchEngineInterface $searchEngine = null, $removeExtension = null) + public function get_title($highlight = false, SearchEngineInterface $searchEngine = null, $removeExtension = null, SearchEngineOptions $options = null) { $cache = !$highlight && !$searchEngine && !$removeExtension; @@ -896,7 +897,7 @@ class record_adapter implements record_Interface, cache_cacheableInterface } if (count($fields_to_retrieve) > 0) { - $retrieved_fields = $this->get_caption()->get_highlight_fields($highlight, $fields_to_retrieve, $searchEngine); + $retrieved_fields = $this->get_caption()->get_highlight_fields($highlight, $fields_to_retrieve, $searchEngine, false, $options); $titles = []; foreach ($retrieved_fields as $key => $value) { if (trim($value['value'] === '')) diff --git a/lib/classes/record/preview.php b/lib/classes/record/preview.php index edebf8aad0..2b7d6d2edd 100644 --- a/lib/classes/record/preview.php +++ b/lib/classes/record/preview.php @@ -13,6 +13,7 @@ use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Model\Entities\Basket; use Alchemy\Phrasea\Model\Entities\BasketElement; use Alchemy\Phrasea\SearchEngine\SearchEngineInterface; +use Alchemy\Phrasea\SearchEngine\SearchEngineOptions; class record_preview extends record_adapter { @@ -89,7 +90,7 @@ class record_preview extends record_adapter * * @return record_preview */ - public function __construct(Application $app, $env, $pos, $contId, SearchEngineInterface $search_engine = null, $query = '') + public function __construct(Application $app, $env, $pos, $contId, SearchEngineInterface $search_engine = null, $query = '', SearchEngineOptions $options = null) { $number = null; $this->env = $env; @@ -101,7 +102,7 @@ class record_preview extends record_adapter throw new \LogicException('Search Engine should be provided'); } - $results = $search_engine->query($query, (int) ($pos), 1); + $results = $search_engine->query($query, (int) ($pos), 1, $options); if ($results->getResults()->isEmpty()) { throw new Exception('Record introuvable'); diff --git a/templates/web/common/caption.html.twig b/templates/web/common/caption.html.twig index f46684dee5..3a04574111 100644 --- a/templates/web/common/caption.html.twig +++ b/templates/web/common/caption.html.twig @@ -12,15 +12,15 @@ {% endif %} {% if view == 'answer' %} - {{cap_ans.format_caption(record, highlight|default(''), searchEngine|default(null), business)}} + {{cap_ans.format_caption(record, highlight|default(''), searchEngine|default(null), searchOptions|default(null), business)}} {% elseif view == 'lazaret' %} - {{cap_laz.format_caption(record, highlight|default(''), searchEngine|default(null), business)}} + {{cap_laz.format_caption(record, highlight|default(''), searchEngine|default(null), searchOptions|default(null), business)}} {% elseif view == 'preview' %} - {{cap_prev.format_caption(record, highlight|default(''), searchEngine|default(null), business)}} + {{cap_prev.format_caption(record, highlight|default(''), searchEngine|default(null), searchOptions|default(null), business)}} {% elseif view == 'basket' %} - {{cap_bas.format_caption(record, highlight|default(''), searchEngine|default(null), business)}} + {{cap_bas.format_caption(record, highlight|default(''), searchEngine|default(null), searchOptions|default(null), business)}} {% elseif view == 'overview' %} - {{cap_ovr.format_caption(record, highlight|default(''), searchEngine|default(null), business)}} + {{cap_ovr.format_caption(record, highlight|default(''), searchEngine|default(null), searchOptions|default(null), business)}} {% elseif view == 'publi' %} - {{cap_pub.format_caption(record, '', null, business)}} -{% endif %} \ No newline at end of file + {{cap_pub.format_caption(record, '', null, null, business)}} +{% endif %} diff --git a/templates/web/common/caption_templates/answer.html.twig b/templates/web/common/caption_templates/answer.html.twig index ebb65f00bf..ac7ed04d5e 100644 --- a/templates/web/common/caption_templates/answer.html.twig +++ b/templates/web/common/caption_templates/answer.html.twig @@ -1,5 +1,5 @@ -{% macro format_caption(record, highlight, searchEngine, includeBusiness) %} - {% for value in record.get_caption().get_highlight_fields(highlight, null, searchEngine, includeBusiness) %} +{% macro format_caption(record, highlight, searchEngine, options, includeBusiness) %} + {% for value in record.get_caption().get_highlight_fields(highlight, null, searchEngine, includeBusiness, options) %}