fields[$name] = $field; $this->current = $name; return $this; } public function export() { return ['properties' => $this->exportProperties()]; } public function exportProperties() { $properties = array(); foreach ($this->fields as $name => $field) { $properties[$name] = $field; if ($field['type'] === self::TYPE_OBJECT) { $properties[$name]['properties'] = $field['properties']->exportProperties(); } } return $properties; } public function notAnalyzed() { $field = &$this->currentField(); if ($field['type'] !== self::TYPE_STRING) { throw new LogicException('Only string fields can be not analyzed'); } $field['index'] = 'not_analyzed'; return $this; } public function notIndexed() { $field = &$this->currentField(); $field['index'] = 'no'; return $this; } public function addRawVersion() { $field = &$this->currentField(); $field['fields']['raw'] = [ 'type' => $field['type'], 'index' => 'not_analyzed' ]; return $this; } public function addAnalyzedVersion(array $langs) { $field = &$this->currentField(); foreach ($langs as $lang) { $field['fields'][$lang] = [ 'type' => $field['type'], 'analyzer' => sprintf('%s_full', $lang) ]; } $field['fields']['light'] = [ 'type' => $field['type'], 'analyzer' => 'general_light' ]; return $this; } public function format($format) { $field = &$this->currentField(); if ($field['type'] !== self::TYPE_DATE) { throw new LogicException('Only date fields can have a format'); } $field['format'] = $format; return $this; } protected function ¤tField() { if (null === $this->current) { throw new LogicException('You must add a field first'); } return $this->fields[$this->current]; } }