Refactor merged field structure

Here is the new model:

+-----------------------------+
|          Structure          |
+-----------------------------+
| +createFromDataboxes()      |
| getAllFields()              |
| getUnrestrictedFields()     |
| getPrivateFields()          |
| getFacetsFields()           |
| getThesaurusEnabledFields() |
| getDateFields()             |
|- - - - - - - - - - - - - - -|
| add()                       |
| get()                       |
| typeOf()                    |
| isPrivate()                 |
+-------+-+-+-----------------+
        | | |          +---------------------+
        | | +--------> |        Field        |
        | |            +---------------------+
        | |            | getName()           |
        | |            | getType()           |
        | |            | isXXX()             |
        | |            | getThesaurusRoots() |
        | |            +---------------------+
        | |
        | |            +-------+
        | +----------> | Field |
        |              +-------+
        |
        |              +-------+
        +------------> | Field |
                       +-------+

It was driven by the following use cases:
- Get list of facets (only searchable fields)
- Get list of fields with concept inference
- Get list of all fields
    - Splitted in private / public fields (to define mapping)
- Get all date fields
- Get field type
    - To apply sanitization rules
    - To define mapping
- Check if concept inference enabled
- Check if the field is searchable
- Check if the field is a facet
- Check if the field is private
- Dereference field from label (still to be done)

(The last two UCs are new)

Also removed old code from legacy search engines.

[#PHRAS-500]
This commit is contained in:
Mathieu Darse
2015-05-20 21:10:42 +02:00
parent 06bd5d09bc
commit 421684757a
10 changed files with 367 additions and 241 deletions

View File

@@ -0,0 +1,99 @@
<?php
namespace Alchemy\Phrasea\SearchEngine\Elastic\Structure;
use Alchemy\Phrasea\SearchEngine\Elastic\Mapping;
class Structure
{
private $fields = array();
private $date_fields = array();
private $thesaurus_fields = array();
private $private = array();
private $facets = array();
private $aliases = array();
public static function fromDataboxes(array $databoxes)
{
$structure = new self();
foreach ($databoxes as $databox) {
foreach ($databox->get_meta_structure() as $fieldStructure) {
$field = Field::createFromLegacyField($fieldStructure);
$structure->add($field);
}
}
return $structure;
}
public function add(Field $field)
{
$name = $field->getName();
if (isset($this->fields[$name])) {
$this->fields[$name]->mergeWith($field);
} else {
$this->fields[$name] = $field;
}
if ($field->getType() === Mapping::TYPE_DATE) {
$this->date_fields[$name] = $field;
}
if ($field->isPrivate()) {
$this->private[$name] = $field;
}
if ($field->isFacet()) {
$this->facets[$name] = $field;
}
if ($field->hasConceptInference()) {
$this->thesaurus_fields[$name] = $field;
}
}
public function getAllFields()
{
return $this->fields;
}
public function getUnrestrictedFields()
{
return array_diff_key($this->fields, $this->private);
}
public function getPrivateFields()
{
return $this->private;
}
public function getFacetFields()
{
// TODO should we only return searchable fields?
return $this->facets;
}
public function getThesaurusEnabledFields()
{
return $this->thesaurus_fields;
}
public function getDateFields()
{
return $this->date_fields;
}
public function get($name)
{
return isset($this->fields[$name]) ?
$this->fields[$name] : null;
}
public function typeOf($name)
{
return isset($this->fields[$name]) ?
$this->fields[$name]->getType() : null;
}
public function isPrivate($name)
{
return isset($this->private[$name]) ? true :
isset($this->fields[$name]) ? false : null;
}
}