This commit is contained in:
Thibaud Fabre
2016-10-17 15:45:59 +02:00
parent 7adec6a300
commit 11d25021cc
6 changed files with 54 additions and 10 deletions

View File

@@ -353,15 +353,16 @@ class RecordIndexer
private function buildCaptionMapping(array $fields, Mapping $root, $section) private function buildCaptionMapping(array $fields, Mapping $root, $section)
{ {
$mapping = new Mapping(); $mapping = new Mapping();
foreach ($fields as $field) { foreach ($fields as $field) {
$this->addFieldToMapping($field, $mapping); $this->addFieldToMapping($field, $mapping);
} }
$root->add($section, $mapping); $root->add($section, $mapping);
$root $root
->add(sprintf('%s_all', $section), 'string') ->add(sprintf('%s_all', $section), 'string')
->addLocalizedSubfields($this->locales) ->addLocalizedSubfields($this->locales)
->addRawVersion() ->addRawVersion();
;
} }
private function addFieldToMapping(Field $field, Mapping $mapping) private function addFieldToMapping(Field $field, Mapping $mapping)
@@ -376,6 +377,7 @@ class RecordIndexer
if ($type === Mapping::TYPE_STRING) { if ($type === Mapping::TYPE_STRING) {
$searchable = $field->isSearchable(); $searchable = $field->isSearchable();
$facet = $field->isFacet(); $facet = $field->isFacet();
if (!$searchable && !$facet) { if (!$searchable && !$facet) {
$mapping->notIndexed(); $mapping->notIndexed();
} else { } else {

View File

@@ -36,6 +36,7 @@ class QueryContext
if (is_array($this->fields)) { if (is_array($this->fields)) {
// Ensure we are not escaping from original fields restrictions // Ensure we are not escaping from original fields restrictions
$fields = array_intersect($this->fields, $fields); $fields = array_intersect($this->fields, $fields);
if (!$fields) { if (!$fields) {
throw new QueryException('Query narrowed to non available fields'); throw new QueryException('Query narrowed to non available fields');
} }
@@ -56,7 +57,8 @@ class QueryContext
return $this->filterFields($this->structure->getPrivateFields()); return $this->filterFields($this->structure->getPrivateFields());
} }
public function getHighlightedFields() { public function getHighlightedFields()
{
return $this->filterFields($this->structure->getAllFields()); return $this->filterFields($this->structure->getAllFields());
} }
@@ -74,6 +76,7 @@ class QueryContext
if ($name instanceof ASTField) { if ($name instanceof ASTField) {
$name = $name->getValue(); $name = $name->getValue();
} }
return $this->structure->get($name); return $this->structure->get($name);
} }
@@ -82,6 +85,7 @@ class QueryContext
if ($name instanceof Flag) { if ($name instanceof Flag) {
$name = $name->getName(); $name = $name->getName();
} }
return $this->structure->getFlagByName($name); return $this->structure->getFlagByName($name);
} }
@@ -96,6 +100,7 @@ class QueryContext
public function localizeField(Field $field) public function localizeField(Field $field)
{ {
$index_field = $field->getIndexField(); $index_field = $field->getIndexField();
if ($field->getType() === Mapping::TYPE_STRING) { if ($field->getType() === Mapping::TYPE_STRING) {
return $this->localizeFieldName($index_field); return $this->localizeFieldName($index_field);
} else { } else {
@@ -110,6 +115,7 @@ class QueryContext
$boost = ($locale === $this->queryLocale) ? '^5' : ''; $boost = ($locale === $this->queryLocale) ? '^5' : '';
$fields[] = sprintf('%s.%s%s', $field, $locale, $boost); $fields[] = sprintf('%s.%s%s', $field, $locale, $boost);
} }
// TODO Put generic analyzers on main field instead of "light" sub-field // TODO Put generic analyzers on main field instead of "light" sub-field
$fields[] = sprintf('%s.light^10', $field); $fields[] = sprintf('%s.light^10', $field);

View File

@@ -36,9 +36,11 @@ class QueryContextFactory
private function getSearchedFields(SearchEngineOptions $options) private function getSearchedFields(SearchEngineOptions $options)
{ {
$fields = []; $fields = [];
foreach ($options->getFields() as $field) { foreach ($options->getFields() as $field) {
$fields[] = $field->get_name(); $fields[] = $field->get_name();
} }
return $fields; return $fields;
} }

View File

@@ -121,6 +121,7 @@ class QueryVisitor implements Visit
private function visitQuery(Element $element) private function visitQuery(Element $element)
{ {
$root = null; $root = null;
foreach ($element->getChildren() as $child) { foreach ($element->getChildren() as $child) {
$root = $child->accept($this); $root = $child->accept($this);
} }
@@ -176,6 +177,7 @@ class QueryVisitor implements Visit
private function handleBinaryExpression(Element $element, \Closure $factory) private function handleBinaryExpression(Element $element, \Closure $factory)
{ {
$this->assertChildrenCount($element, 2); $this->assertChildrenCount($element, 2);
$left = $element->getChild(0)->accept($this); $left = $element->getChild(0)->accept($this);
$right = $element->getChild(1)->accept($this); $right = $element->getChild(1)->accept($this);
@@ -284,6 +286,7 @@ class QueryVisitor implements Visit
private function visitString(TreeNode $node) private function visitString(TreeNode $node)
{ {
$tokens = array(); $tokens = array();
foreach ($node->getChildren() as $child) { foreach ($node->getChildren() as $child) {
$value = $child->getValue(); $value = $child->getValue();
if ($value === null || !isset($value['value'])) { if ($value === null || !isset($value['value'])) {

View File

@@ -14,17 +14,36 @@ use databox_field;
*/ */
class Field implements Typed class Field implements Typed
{ {
private $name;
private $type;
private $is_searchable;
private $is_private;
private $facet; // facet values limit or NULL (zero means no limit)
private $thesaurus_roots;
private $used_by_collections;
const FACET_DISABLED = null; const FACET_DISABLED = null;
const FACET_NO_LIMIT = 0; const FACET_NO_LIMIT = 0;
/**
* @var string
*/
private $name;
/**
* @var string
*/
private $type;
/**
* @var bool
*/
private $is_searchable;
/**
* @var bool
*/
private $is_private;
private $facet; // facet values limit or NULL (zero means no limit)
private $thesaurus_roots;
private $used_by_collections;
public static function createFromLegacyField(databox_field $field) public static function createFromLegacyField(databox_field $field)
{ {
$type = self::getTypeFromLegacy($field); $type = self::getTypeFromLegacy($field);
@@ -83,12 +102,15 @@ class Field implements Typed
Assertion::boolean($this->is_searchable); Assertion::boolean($this->is_searchable);
Assertion::boolean($this->is_private); Assertion::boolean($this->is_private);
if ($this->facet !== self::FACET_DISABLED) { if ($this->facet !== self::FACET_DISABLED) {
Assertion::integer($this->facet); Assertion::integer($this->facet);
} }
if ($this->thesaurus_roots !== null) { if ($this->thesaurus_roots !== null) {
Assertion::allIsInstanceOf($this->thesaurus_roots, Concept::class); Assertion::allIsInstanceOf($this->thesaurus_roots, Concept::class);
} }
Assertion::allScalar($this->used_by_collections); Assertion::allScalar($this->used_by_collections);
} }
@@ -197,6 +219,7 @@ class Field implements Typed
} }
$thesaurus_roots = null; $thesaurus_roots = null;
if ($this->thesaurus_roots !== null || $other->thesaurus_roots !== null) { if ($this->thesaurus_roots !== null || $other->thesaurus_roots !== null) {
$thesaurus_roots = array_merge( $thesaurus_roots = array_merge(
(array) $this->thesaurus_roots, (array) $this->thesaurus_roots,

View File

@@ -51,14 +51,17 @@ final class GlobalStructure implements Structure
{ {
$fields = []; $fields = [];
$flags = []; $flags = [];
foreach ($databoxes as $databox) { foreach ($databoxes as $databox) {
foreach ($databox->get_meta_structure() as $fieldStructure) { foreach ($databox->get_meta_structure() as $fieldStructure) {
$fields[] = Field::createFromLegacyField($fieldStructure); $fields[] = Field::createFromLegacyField($fieldStructure);
} }
foreach ($databox->getStatusStructure() as $status) { foreach ($databox->getStatusStructure() as $status) {
$flags[] = Flag::createFromLegacyStatus($status); $flags[] = Flag::createFromLegacyStatus($status);
} }
} }
return new self($fields, $flags, MetadataHelper::createTags()); return new self($fields, $flags, MetadataHelper::createTags());
} }
@@ -87,20 +90,25 @@ final class GlobalStructure implements Structure
public function add(Field $field) public function add(Field $field)
{ {
$name = $field->getName(); $name = $field->getName();
if (isset($this->fields[$name])) { if (isset($this->fields[$name])) {
$field = $this->fields[$name]->mergeWith($field); $field = $this->fields[$name]->mergeWith($field);
} }
$this->fields[$name] = $field; $this->fields[$name] = $field;
if ($field->getType() === Mapping::TYPE_DATE) { if ($field->getType() === Mapping::TYPE_DATE) {
$this->date_fields[$name] = $field; $this->date_fields[$name] = $field;
} }
if ($field->isPrivate()) { if ($field->isPrivate()) {
$this->private[$name] = $field; $this->private[$name] = $field;
} }
if ($field->isFacet() && $field->isSearchable()) { if ($field->isFacet() && $field->isSearchable()) {
$this->facets[$name] = $field; $this->facets[$name] = $field;
} }
if ($field->hasConceptInference()) { if ($field->hasConceptInference()) {
$this->thesaurus_fields[$name] = $field; $this->thesaurus_fields[$name] = $field;
} }