コード例 #1
0
 /**
  * @param object $entity
  * @return \SolrDocument
  */
 public function createDocument(MetaInformation $meta)
 {
     $document = new \SolrInputDocument();
     $document->addField('id', $meta->getEntityId());
     $document->addField('document_name_s', $meta->getDocumentName());
     $document->setBoost($meta->getBoost());
     return $document;
 }
コード例 #2
0
 /**
  * @test
  */
 public function resultFromSuccessEventContainsNoMessage()
 {
     $entity = new ValidTestEntity();
     $entity->setId(1);
     $metaInformation = new MetaInformation();
     $metaInformation->setClassName('an entity');
     $metaInformation->setEntity($entity);
     $event = new Event(null, $metaInformation, '');
     $factory = new ConsoleResultFactory();
     $result = $factory->fromEvent($event);
     $this->assertEquals(1, $result->getResultId());
     $this->assertEquals('an entity', $result->getEntityClassname());
     $this->assertEquals('', $result->getErrorMessage());
 }
コード例 #3
0
 /**
  * (non-PHPdoc)
  * @see FS\SolrBundle\Doctrine\Mapper\Mapping.AbstractDocumentCommand::createDocument()
  */
 public function createDocument(MetaInformation $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;
 }
コード例 #4
0
 /**
  * @return MetaInformation
  */
 public static function getMetaInformation()
 {
     $entity = new ValidTestEntity();
     $entity->setId(2);
     $metaInformation = new MetaInformation();
     $title = new Field(array('name' => 'title', 'type' => 'string', 'boost' => '1.8', 'value' => 'A title'));
     $text = new Field(array('name' => 'text', 'type' => 'text', 'value' => 'A text'));
     $createdAt = new Field(array('name' => 'created_at', 'type' => 'date', 'boost' => '1', 'value' => 'A created at'));
     $metaInformation->setFields(array($title, $text, $createdAt));
     $fieldMapping = array('id' => 'id', 'title_s' => 'title', 'text_t' => 'text', 'created_at_dt' => 'created_at');
     $metaInformation->setBoost(1);
     $metaInformation->setFieldMapping($fieldMapping);
     $metaInformation->setEntity($entity);
     $metaInformation->setDocumentName('validtestentity');
     $metaInformation->setClassName(get_class($entity));
     $metaInformation->setIndex(null);
     return $metaInformation;
 }
コード例 #5
0
 public function testAddEntity_FilteredEntityWithUnknownCallback()
 {
     $this->eventManager->expects($this->never())->method('handle');
     $information = new MetaInformation();
     $information->setSynchronizationCallback('shouldBeIndex');
     $this->setupMetaFactoryLoadOneCompleteInformation($information);
     $solr = new SolrFacade($this->connectionFactory, $this->commandFactory, $this->eventManager, $this->metaFactory);
     try {
         $solr->addDocument(new InvalidTestEntityFiltered());
         $this->fail('BadMethodCallException expected');
     } catch (\BadMethodCallException $e) {
         $this->assertTrue(true);
     }
 }
コード例 #6
0
 /**
  * @param MetaInformation $metainformations
  * @param object          $fetchedFromDoctrine
  * @param object          $hydratedDocument
  */
 private function assertEntityFromDBReplcesTargetEntity($metainformations, $fetchedFromDoctrine, $hydratedDocument)
 {
     $this->assertEquals($metainformations->getEntity(), $fetchedFromDoctrine);
     $this->assertEquals($fetchedFromDoctrine, $hydratedDocument);
 }
コード例 #7
0
 /**
  * @param string|object entityAlias
  * @return MetaInformation
  */
 public function loadInformation($entity)
 {
     $className = $this->getClass($entity);
     if (!is_object($entity)) {
         $entity = new $className();
     }
     if (!$this->annotationReader->hasDocumentDeclaration($entity)) {
         throw new \RuntimeException(sprintf('no declaration for document found in entity %s', $className));
     }
     $metaInformation = new MetaInformation();
     $metaInformation->setEntity($entity);
     $metaInformation->setClassName($className);
     $metaInformation->setDocumentName($this->getDocumentName($className));
     $metaInformation->setFieldMapping($this->annotationReader->getFieldMapping($entity));
     $metaInformation->setFields($this->annotationReader->getFields($entity));
     $metaInformation->setRepository($this->annotationReader->getRepository($entity));
     $metaInformation->setIdentifier($this->annotationReader->getIdentifier($entity));
     $metaInformation->setBoost($this->annotationReader->getEntityBoost($entity));
     $metaInformation->setSynchronizationCallback($this->annotationReader->getSynchronizationCallback($entity));
     return $metaInformation;
 }
コード例 #8
0
ファイル: SolrFacade.php プロジェクト: rmzamora/SolrBundle
 /**
  * @param MetaInformation $metaInformation
  * @param object $entity
  * @throws \BadMethodCallException if callback method not exists
  * @return boolean
  */
 private function addToIndex(MetaInformation $metaInformation, $entity)
 {
     if (!$metaInformation->hasSynchronizationFilter()) {
         return true;
     }
     $callback = $metaInformation->getSynchronizationCallback();
     if (!method_exists($entity, $callback)) {
         throw new \BadMethodCallException(sprintf('unknown method %s in entity %s', $callback, get_class($entity)));
     }
     return $entity->{$callback}();
 }
コード例 #9
0
 public function testHasCallback_NoCallbackSet()
 {
     $information = new MetaInformation();
     $this->assertFalse($information->hasSynchronizationFilter(), 'has no callback');
 }
コード例 #10
0
 /**
  * @param MetaInformation $metaInformation
  * @return string
  */
 protected function createFieldList(MetaInformation $metaInformation)
 {
     return implode(', ', $metaInformation->getFields());
 }
コード例 #11
0
 /**
  * @param object $entity
  *
  * @return MetaInformation
  *
  * @throws \RuntimeException if no declaration for document found in $entity
  */
 public function loadInformation($entity)
 {
     $className = $this->getClass($entity);
     if (!is_object($entity)) {
         $reflectionClass = new \ReflectionClass($className);
         if (!$reflectionClass->isInstantiable()) {
             throw new \RuntimeException(sprintf('cannot instantiate entity %s', $className));
         }
         $entity = $reflectionClass->newInstanceWithoutConstructor();
     }
     if (!$this->annotationReader->hasDocumentDeclaration($entity)) {
         throw new \RuntimeException(sprintf('no declaration for document found in entity %s', $className));
     }
     $metaInformation = new MetaInformation();
     $metaInformation->setEntity($entity);
     $metaInformation->setClassName($className);
     $metaInformation->setDocumentName($this->getDocumentName($className));
     $metaInformation->setFieldMapping($this->annotationReader->getFieldMapping($entity));
     $metaInformation->setFields($this->annotationReader->getFields($entity));
     $metaInformation->setRepository($this->annotationReader->getRepository($entity));
     $metaInformation->setIdentifier($this->annotationReader->getIdentifier($entity));
     $metaInformation->setBoost($this->annotationReader->getEntityBoost($entity));
     $metaInformation->setSynchronizationCallback($this->annotationReader->getSynchronizationCallback($entity));
     $metaInformation->setIndex($this->annotationReader->getDocumentIndex($entity));
     $metaInformation->setIsDoctrineEntity($this->annotationReader->isDoctrineEntity($entity));
     return $metaInformation;
 }
コード例 #12
0
ファイル: SolrTest.php プロジェクト: wizbit/SolrBundle
 public function testAddEntity_ShouldNotIndexEntity()
 {
     $this->assertUpdateQueryWasNotExecuted();
     $this->eventDispatcher->expects($this->never())->method('dispatch');
     $entity = new ValidTestEntityFiltered();
     $information = new MetaInformation();
     $information->setSynchronizationCallback('shouldBeIndex');
     $this->setupMetaFactoryLoadOneCompleteInformation($information);
     $solr = new Solr($this->solrClientFake, $this->commandFactory, $this->eventDispatcher, $this->metaFactory, $this->mapper);
     $solr->addDocument($entity);
     $this->assertTrue($entity->getShouldBeIndexedWasCalled(), 'filter method was not called');
 }