mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-17 23:13:15 +00:00
Pass structure to query visitor & enable range generation for regular fields (equal expression)
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace Alchemy\Phrasea\SearchEngine\Elastic\Search;
|
||||
|
||||
use Alchemy\Phrasea\SearchEngine\Elastic\Structure\LimitedStructure;
|
||||
use Alchemy\Phrasea\SearchEngine\Elastic\Structure\Structure;
|
||||
use Alchemy\Phrasea\SearchEngine\SearchEngineOptions;
|
||||
|
||||
class QueryContextFactory
|
||||
{
|
||||
private $structure;
|
||||
|
||||
public function __construct(Structure $structure, array $locales, $current_locale)
|
||||
{
|
||||
$this->structure = $structure;
|
||||
$this->locales = $locales;
|
||||
$this->current_locale = $current_locale;
|
||||
}
|
||||
|
||||
public function createContext(SearchEngineOptions $options = null)
|
||||
{
|
||||
$structure = $options
|
||||
? $this->getLimitedStructure($options)
|
||||
: $this->structure;
|
||||
|
||||
$context = new QueryContext($structure, $this->locales, $this->current_locale);
|
||||
|
||||
if ($options) {
|
||||
$fields = $this->getSearchedFields($options);
|
||||
$context = $context->narrowToFields($fields);
|
||||
}
|
||||
|
||||
return $context;
|
||||
}
|
||||
|
||||
private function getSearchedFields(SearchEngineOptions $options)
|
||||
{
|
||||
$fields = [];
|
||||
foreach ($options->getFields() as $field) {
|
||||
$fields[] = $field->get_name();
|
||||
}
|
||||
return $fields;
|
||||
}
|
||||
|
||||
public function getLimitedStructure(SearchEngineOptions $options)
|
||||
{
|
||||
return new LimitedStructure($this->structure, $options);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user