diff --git a/lib/Alchemy/Phrasea/SearchEngine/Elastic/ElasticSearchEngine.php b/lib/Alchemy/Phrasea/SearchEngine/Elastic/ElasticSearchEngine.php index 529237b787..e3f95cdfa5 100644 --- a/lib/Alchemy/Phrasea/SearchEngine/Elastic/ElasticSearchEngine.php +++ b/lib/Alchemy/Phrasea/SearchEngine/Elastic/ElasticSearchEngine.php @@ -11,29 +11,27 @@ namespace Alchemy\Phrasea\SearchEngine\Elastic; -use Alchemy\Phrasea\Collection\Reference\CollectionReference; +use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Exception\LogicException; +use Alchemy\Phrasea\Exception\RuntimeException; +use Alchemy\Phrasea\Model\Entities\FeedEntry; use Alchemy\Phrasea\SearchEngine\Elastic\Indexer\RecordIndexer; use Alchemy\Phrasea\SearchEngine\Elastic\Search\AggregationHelper; use Alchemy\Phrasea\SearchEngine\Elastic\Search\FacetsResponse; use Alchemy\Phrasea\SearchEngine\Elastic\Search\QueryCompiler; use Alchemy\Phrasea\SearchEngine\Elastic\Search\QueryContext; use Alchemy\Phrasea\SearchEngine\Elastic\Search\QueryContextFactory; -use Alchemy\Phrasea\SearchEngine\Elastic\Structure\Field AS ESField; +use Alchemy\Phrasea\SearchEngine\Elastic\Structure\Field as ESField; use Alchemy\Phrasea\SearchEngine\Elastic\Structure\Flag; use Alchemy\Phrasea\SearchEngine\Elastic\Structure\GlobalStructure; use Alchemy\Phrasea\SearchEngine\Elastic\Structure\Structure; use Alchemy\Phrasea\SearchEngine\SearchEngineInterface; use Alchemy\Phrasea\SearchEngine\SearchEngineOptions; use Alchemy\Phrasea\SearchEngine\SearchEngineResult; -use Alchemy\Phrasea\Exception\RuntimeException; -use Alchemy\Phrasea\SearchEngine\SearchEngineStructure; use Alchemy\Phrasea\Utilities\Stopwatch; use Closure; -use Doctrine\Common\Collections\ArrayCollection; -use Alchemy\Phrasea\Model\Entities\FeedEntry; -use Alchemy\Phrasea\Application; use databox_field; +use Doctrine\Common\Collections\ArrayCollection; use Elasticsearch\Client; class ElasticSearchEngine implements SearchEngineInterface @@ -284,9 +282,8 @@ class ElasticSearchEngine implements SearchEngineInterface /** * {@inheritdoc} */ - public function query($queryText, SearchEngineOptions $options = null) + public function query($queryText, SearchEngineOptions $options) { - $options = $options ?: new SearchEngineOptions(); $context = $this->context_factory->createContext($options); /** @var QueryCompiler $query_compiler */ diff --git a/lib/Alchemy/Phrasea/SearchEngine/SearchEngineInterface.php b/lib/Alchemy/Phrasea/SearchEngine/SearchEngineInterface.php index e0f993d70b..ba654b0589 100644 --- a/lib/Alchemy/Phrasea/SearchEngine/SearchEngineInterface.php +++ b/lib/Alchemy/Phrasea/SearchEngine/SearchEngineInterface.php @@ -167,7 +167,7 @@ interface SearchEngineInterface * * @return SearchEngineResult */ - public function query($query, SearchEngineOptions $options = null); + public function query($query, SearchEngineOptions $options); /** * Return an array of suggestions corresponding to the last word of the diff --git a/lib/Alchemy/Phrasea/SearchEngine/SearchEngineOptions.php b/lib/Alchemy/Phrasea/SearchEngine/SearchEngineOptions.php index 5e942b1adf..1e2c74cea5 100644 --- a/lib/Alchemy/Phrasea/SearchEngine/SearchEngineOptions.php +++ b/lib/Alchemy/Phrasea/SearchEngine/SearchEngineOptions.php @@ -14,13 +14,12 @@ namespace Alchemy\Phrasea\SearchEngine; use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Authentication\ACLProvider; use Alchemy\Phrasea\Authentication\Authenticator; -use Alchemy\Phrasea\Collection\CollectionRepository; use Alchemy\Phrasea\Collection\Reference\CollectionReference; -use Alchemy\Phrasea\Collection\Reference\DbalCollectionReferenceRepository; +use Alchemy\Phrasea\Collection\Reference\CollectionReferenceRepository; use Assert\Assertion; +use databox_descriptionStructure; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; -use databox_descriptionStructure; class SearchEngineOptions { @@ -41,7 +40,7 @@ class SearchEngineOptions const SORT_MODE_ASC = 'asc'; const SORT_MODE_DESC = 'desc'; - /** @var DbalCollectionReferenceRepository $dbalCollectionReferenceRepository */ + /** @var CollectionReferenceRepository */ private $collectionReferenceRepository; /** @var string */ @@ -455,6 +454,11 @@ class SearchEngineOptions return $this->date_fields; } + public function __construct(CollectionReferenceRepository $collectionReferenceRepository) + { + $this->collectionReferenceRepository = $collectionReferenceRepository; + } + /** * Creates options based on a Symfony Request object * @@ -469,9 +473,7 @@ class SearchEngineOptions $authenticator = $app->getAuthenticator(); $isAuthenticated = $authenticator->isAuthenticated(); - $options = new static(); - - $options->collectionReferenceRepository = $app['repo.collection-references']; + $options = new static($app['repo.collection-references']); $options->disallowBusinessFields(); $options->setLocale($app['locale']); @@ -713,7 +715,7 @@ class SearchEngineOptions throw new \InvalidArgumentException('SearchEngineOptions data are corrupted'); } - $options = new static(); + $options = new static($app['repo.collection-references']); $options->disallowBusinessFields(); $methods = self::getHydrateMethods($app); diff --git a/lib/classes/record/preview.php b/lib/classes/record/preview.php index c02332a4b6..379002b123 100644 --- a/lib/classes/record/preview.php +++ b/lib/classes/record/preview.php @@ -93,7 +93,7 @@ class record_preview extends record_adapter throw new \LogicException('Search Engine should be provided'); } if (!$options) { - $options = new SearchEngineOptions(); + $options = new SearchEngineOptions($app['repo.collection-references']); } $options->setFirstResult($pos); $options->setMaxResults(1); @@ -197,7 +197,7 @@ class record_preview extends record_adapter switch ($this->env) { case 'RESULT': - $options = $this->options ?: new SearchEngineOptions(); + $options = $this->options ?: new SearchEngineOptions($this->app['repo.collection-references']); $options->setFirstResult(($this->pos - 3) < 0 ? 0 : ($this->pos - 3)); $options->setMaxResults(56);