/**
  * @param MetaInformationInterface $meta
  *
  * @return Document
  */
 public function createDocument(MetaInformationInterface $meta)
 {
     $document = new Document();
     $document->setKey(MetaInformationInterface::DOCUMENT_KEY_FIELD_NAME, $meta->getDocumentKey());
     $document->setBoost($meta->getBoost());
     return $document;
 }
예제 #2
0
 /**
  * {@inheritdoc}
  */
 public function hydrate($document, MetaInformationInterface $metaInformation)
 {
     $sourceTargetEntity = $metaInformation->getEntity();
     $targetEntity = clone $sourceTargetEntity;
     $metaInformation->setEntity($targetEntity);
     return $this->valueHydrator->hydrate($document, $metaInformation);
 }
예제 #3
0
 /**
  * {@inheritdoc}
  */
 public function hydrate($document, MetaInformationInterface $metaInformation)
 {
     $targetEntity = $metaInformation->getEntity();
     $reflectionClass = new \ReflectionClass($targetEntity);
     foreach ($document as $property => $value) {
         if ($property === MetaInformationInterface::DOCUMENT_KEY_FIELD_NAME) {
             $value = $this->removePrefixedKeyFieldName($value);
         }
         // skip field if value is array or "flat" object
         // hydrated object should contain a list of real entities / entity
         if ($this->mapValue($property, $value, $metaInformation) == false) {
             continue;
         }
         try {
             $classProperty = $reflectionClass->getProperty($this->removeFieldSuffix($property));
         } catch (\ReflectionException $e) {
             try {
                 $classProperty = $reflectionClass->getProperty($this->toCamelCase($this->removeFieldSuffix($property)));
             } catch (\ReflectionException $e) {
                 continue;
             }
         }
         $classProperty->setAccessible(true);
         $classProperty->setValue($targetEntity, $value);
     }
     return $targetEntity;
 }
예제 #4
0
 /**
  * @param MetaInformationInterface $meta
  *
  * @return Document
  */
 public function createDocument(MetaInformationInterface $meta)
 {
     $document = new Document();
     $document->addField('id', $meta->getEntityId());
     $document->addField('document_name_s', $meta->getDocumentName());
     $document->setBoost($meta->getBoost());
     return $document;
 }
예제 #5
0
 /**
  * {@inheritdoc}
  */
 public function hydrate($document, MetaInformationInterface $metaInformation)
 {
     $entityId = $metaInformation->getEntityId();
     $doctrineEntity = $this->doctrine->getManager()->getRepository($metaInformation->getClassName())->find($entityId);
     if ($doctrineEntity !== null) {
         $metaInformation->setEntity($doctrineEntity);
     }
     return $this->valueHydrator->hydrate($document, $metaInformation);
 }
예제 #6
0
 /**
  * @param MetaInformationInterface $meta
  *
  * @return null|\Solarium\QueryType\Update\Query\Document\Document
  */
 public function createDocument(MetaInformationInterface $meta)
 {
     $fields = $meta->getFields();
     if (count($fields) == 0) {
         return null;
     }
     $document = parent::createDocument($meta);
     foreach ($fields as $field) {
         if (!$field instanceof Field) {
             continue;
         }
         $document->addField($field->getNameWithAlias(), $field->getValue(), $field->getBoost());
     }
     return $document;
 }
 /**
  * {@inheritdoc}
  */
 public function mapValue($fieldName, $value, MetaInformationInterface $metaInformation)
 {
     if (is_array($value)) {
         return false;
     }
     if ($metaInformation->getField($fieldName) && $metaInformation->getField($fieldName)->getter) {
         return false;
     }
     $fieldSuffix = $this->removePrefixedKeyFieldName($fieldName);
     if ($fieldSuffix === false) {
         return false;
     }
     if (array_key_exists($fieldSuffix, Field::getComplexFieldMapping())) {
         return false;
     }
     return true;
 }
예제 #8
0
 /**
  * {@inheritdoc}
  */
 public function hydrate($document, MetaInformationInterface $metaInformation)
 {
     $targetEntity = $metaInformation->getEntity();
     $reflectionClass = new \ReflectionClass($targetEntity);
     foreach ($document as $property => $value) {
         try {
             $classProperty = $reflectionClass->getProperty($this->removeFieldSuffix($property));
         } catch (\ReflectionException $e) {
             try {
                 $classProperty = $reflectionClass->getProperty($this->toCamelCase($this->removeFieldSuffix($property)));
             } catch (\ReflectionException $e) {
                 continue;
             }
         }
         $classProperty->setAccessible(true);
         $classProperty->setValue($targetEntity, $value);
     }
     return $targetEntity;
 }
예제 #9
0
 /**
  * @param MetaInformationInterface $meta
  *
  * @return null|\Solarium\QueryType\Update\Query\Document\Document
  */
 public function createDocument(MetaInformationInterface $meta)
 {
     $fields = $meta->getFields();
     if (count($fields) == 0) {
         return null;
     }
     $document = parent::createDocument($meta);
     foreach ($fields as $field) {
         if (!$field instanceof Field) {
             continue;
         }
         $value = $field->getValue();
         if ($value instanceof Collection) {
             $document->addField($field->getNameWithAlias(), $this->mapCollection($field), $field->getBoost());
         } elseif (is_object($value)) {
             $document->addField($field->getNameWithAlias(), $this->mapObject($field), $field->getBoost());
         } else {
             $document->addField($field->getNameWithAlias(), $field->getValue(), $field->getBoost());
         }
     }
     return $document;
 }
예제 #10
0
 /**
  * @param MetaInformationInterface $metaInformation
  */
 public function setMetaInformation($metaInformation)
 {
     $this->metaInformation = $metaInformation;
     $this->entity = $metaInformation->getEntity();
     $this->index = $metaInformation->getIndex();
 }
예제 #11
0
파일: Solr.php 프로젝트: royopa/SolrBundle
 /**
  * @param object                   $doc
  * @param MetaInformationInterface $metaInformation
  * @param Event                    $event
  */
 private function addDocumentToIndex($doc, MetaInformationInterface $metaInformation, Event $event)
 {
     try {
         $indexName = $metaInformation->getIndex();
         $client = new \FS\SolrBundle\Client\Client($this->solrClientCore);
         $client->update($doc, $indexName);
     } catch (\Exception $e) {
         $errorEvent = new ErrorEvent(null, $metaInformation, json_encode($this->solrClientCore->getOptions()), $event);
         $errorEvent->setException($e);
         $this->eventManager->dispatch(Events::ERROR, $errorEvent);
     }
 }
예제 #12
0
 /**
  * @param MetaInformationInterface $metaInformation
  *
  * @return string
  */
 protected function createFieldList(MetaInformationInterface $metaInformation)
 {
     return implode(', ', $metaInformation->getFields());
 }