mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-17 06:53:15 +00:00
Refactor thesaurus query build
- Look for text nodes and infer the concepts behind term using thesaurus - Use value objects for thesaurus terms and concepts - Pass a QueryContext holding allowed fields and locales informations when building the Elasticsearch query - Change type hinting and name of query building method on nodes - Remove unused method Node#isFullTextOnly() - Move getFieldsStructure from RecordIndexer to RecordHelper for reusing field structure in SearchEngine
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace Alchemy\Phrasea\SearchEngine\Elastic\Search;
|
||||
|
||||
class QueryContext
|
||||
{
|
||||
private $fields;
|
||||
private $locales;
|
||||
private $queryLocale;
|
||||
|
||||
public function __construct(array $fields, array $locales, $queryLocale)
|
||||
{
|
||||
$this->fields = $fields;
|
||||
$this->locales = $locales;
|
||||
$this->queryLocale = $queryLocale;
|
||||
}
|
||||
|
||||
public function narrowToFields(array $fields)
|
||||
{
|
||||
// Ensure we are not escaping from original fields restrictions
|
||||
$fields = array_intersect($this->fields, $fields);
|
||||
|
||||
return new static($fields, $this->locales, $this->queryLocale);
|
||||
}
|
||||
|
||||
public function getLocalizedFields()
|
||||
{
|
||||
$fields = array();
|
||||
foreach ($this->fields as $field) {
|
||||
foreach ($this->locales as $locale) {
|
||||
$boost = ($locale === $this->queryLocale) ? '^5' : '';
|
||||
$fields[] = sprintf('caption.%s.%s%s', $field, $locale, $boost);
|
||||
}
|
||||
// TODO Put generic analyzers on main field instead of "light" sub-field
|
||||
$fields[] = sprintf('caption.%s.%s', $field, 'light^10');
|
||||
}
|
||||
|
||||
return $fields;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user