map() abstract public method

Map field value to a proper search engine representation.
abstract public map ( eZ\Publish\SPI\Search\Field $field ) : mixed | null
$field eZ\Publish\SPI\Search\Field
return mixed | null Returns null on empty value
コード例 #1
0
 /**
  * Map search field value to solr value using FieldValueMapper.
  *
  * @param mixed $value
  * @param \eZ\Publish\SPI\Search\FieldType $searchFieldType
  *
  * @return mixed
  */
 protected function mapSearchFieldValue($value, FieldType $searchFieldType = null)
 {
     if (null === $searchFieldType) {
         return $value;
     }
     $searchField = new SearchField('field', $value, $searchFieldType);
     $value = (array) $this->fieldValueMapper->map($searchField);
     return current($value);
 }
コード例 #2
0
 protected function writeField(XmlWriter $xmlWriter, Field $field)
 {
     foreach ((array) $this->fieldValueMapper->map($field) as $value) {
         $xmlWriter->startElement('field');
         $xmlWriter->writeAttribute('name', $this->nameGenerator->getTypedName($field->name, $field->type));
         $xmlWriter->text($value);
         $xmlWriter->endElement();
     }
 }
コード例 #3
0
 /**
  * Converts given $document to a hash format that can be JSON encoded
  * to get a document _source.
  *
  * Implemented in a separate method because of a recursion needed to
  * handle nested documents.
  *
  * @param \eZ\Publish\Core\Search\Elasticsearch\Content\Document $document
  *
  * @return array
  */
 protected function getDocumentHash(Document $document)
 {
     $hash = array();
     foreach ($document->fields as $field) {
         if ($field->type instanceof DocumentField) {
             $documents = $this->fieldValueMapper->map($field);
             $values = array();
             foreach ($documents as $document) {
                 $values[] = $this->getDocumentHash($document);
             }
         } else {
             $values = (array) $this->fieldValueMapper->map($field);
         }
         $name = $this->nameGenerator->getTypedName($field->name, $field->type);
         if (count($values) === 1) {
             $hash[$name] = reset($values);
         } else {
             $hash[$name] = $values;
         }
     }
     return $hash;
 }