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:
Mathieu Darse
2015-01-15 20:04:46 +01:00
parent f283bf01d1
commit dc2c9f8c7f
21 changed files with 391 additions and 267 deletions

View File

@@ -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;
}
}