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

@@ -2,23 +2,43 @@
namespace Alchemy\Phrasea\SearchEngine\Elastic\AST;
class TextNode extends Node
use Alchemy\Phrasea\SearchEngine\Elastic\Search\QueryContext;
use Alchemy\Phrasea\SearchEngine\Elastic\Thesaurus\TermInterface;
class TextNode extends Node implements TermInterface
{
protected $text;
protected $concepts = array();
public function __construct($text)
{
$this->text = $text;
}
public function getQuery($fields = ['_all'])
public function setConcepts(array $concepts)
{
return array(
$this->concepts = $concepts;
}
public function buildQuery(QueryContext $context)
{
$query = array(
'multi_match' => array(
'fields' => $fields,
'fields' => $context->getLocalizedFields(),
'query' => $this->text,
)
);
if ($this->concepts) {
$shoulds = array($query);
foreach ($this->concepts as $concept) {
$shoulds[]['term']['concept_paths'] = $concept->getPath();
}
$query = array();
$query['bool']['should'] = $shoulds;
}
return $query;
}
public function getTextNodes()
@@ -31,13 +51,22 @@ class TextNode extends Node
return sprintf('"%s"', $this->text);
}
public function isFullTextOnly()
{
return true;
}
public function getText()
// Implementation of TermInterface
public function getValue()
{
return $this->text;
}
public function hasContext()
{
return false;
}
public function getContext()
{
// TODO Insert context during parsing
return null;
}
}