コード例 #1
0
ファイル: Repository.php プロジェクト: royopa/SolrBundle
 /**
  * {@inheritdoc}
  */
 public function findBy(array $args)
 {
     $query = $this->solr->createQuery($this->entity);
     foreach ($args as $fieldName => $fieldValue) {
         $query->addSearchTerm($fieldName, $fieldValue);
     }
     return $this->solr->query($query);
 }
コード例 #2
0
 /**
  * @param LifecycleEventArgs $args
  */
 public function postUpdate(LifecycleEventArgs $args)
 {
     $entity = $args->getEntity();
     try {
         $this->solr->updateDocument($entity);
     } catch (\RuntimeException $e) {
     }
 }
コード例 #3
0
 /**
  * @param LifecycleEventArgs $args
  */
 public function postPersist(LifecycleEventArgs $args)
 {
     $entity = $args->getDocument();
     try {
         $this->solr->addDocument($entity);
     } catch (\RuntimeException $e) {
     }
 }
コード例 #4
0
 /**
  * @param LifecycleEventArgs $args
  */
 public function preRemove(LifecycleEventArgs $args)
 {
     $entity = $args->getDocument();
     try {
         $this->solr->removeDocument($entity);
     } catch (\RuntimeException $e) {
     }
 }
コード例 #5
0
 /**
  * @param LifecycleEventArgs $args
  */
 public function postUpdate(LifecycleEventArgs $args)
 {
     try {
         $entity = $args->getEntity();
         $metaInformation = $this->solr->getMetaFactory()->loadInformation($entity);
         $entity = EntityHelper::customizeEntity($entity, $metaInformation);
         $this->solr->updateDocument($entity);
         EntityHelper::normalizationEntity($entity, $metaInformation);
     } catch (\RuntimeException $e) {
     }
 }
コード例 #6
0
 /**
  * @test
  */
 public function removeDocumentFromAllCores()
 {
     $metaInformation = MetaTestInformationFactory::getMetaInformation();
     $metaInformation->setIndex('*');
     $this->setupMetaFactoryLoadOneCompleteInformation($metaInformation);
     $this->mapper->expects($this->once())->method('toDocument')->will($this->returnValue(new DocumentStub()));
     $this->solrClientFake->expects($this->once())->method('getEndpoints')->will($this->returnValue(array('core0' => array(), 'core1' => array())));
     $deleteQuery = $this->getMock('Solarium\\QueryType\\Update\\Query\\Query', array(), array(), '', false);
     $deleteQuery->expects($this->once())->method('addDeleteQuery')->with($this->isType('string'));
     $deleteQuery->expects($this->once())->method('addCommit');
     $this->solrClientFake->expects($this->once())->method('createUpdate')->will($this->returnValue($deleteQuery));
     $this->solrClientFake->expects($this->exactly(2))->method('update');
     $solr = new Solr($this->solrClientFake, $this->commandFactory, $this->eventDispatcher, $this->metaFactory, $this->mapper);
     $solr->removeDocument(new ValidTestEntity());
 }
コード例 #7
0
 /**
  * @param string $searchQuery
  * @param array $sort
  * @param int $offset
  * @param int $limit
  * @return array
  */
 public function findInIndex($searchQuery = "", $sort = [], $offset = 0, $limit = 0)
 {
     $client = $this->solr_client->getClient();
     $query = $client->createSelect();
     $query->setQuery($searchQuery);
     if (!empty($sort)) {
         foreach ($sort as $key => $value) {
             $query->addSort($key, $value);
         }
     }
     if (!empty($limit)) {
         $query->setRows($limit);
     }
     if (!empty($offset)) {
         $query->setStart($offset);
     }
     $resultset = $client->select($query);
     $result = [];
     /** @var Document $document */
     foreach ($resultset as $document) {
         $result[] = ArrayHelper::createArrayFromDocument($document);
     }
     return $result;
 }
コード例 #8
0
ファイル: Repository.php プロジェクト: zquintana/SolrBundle
 /**
  * {@inheritdoc}
  */
 public function findOneBy(array $args)
 {
     $metaInformation = $this->solr->getMetaFactory()->loadInformation($this->entity);
     $query = $this->solr->createQuery($this->entity);
     $query->setHydrationMode($this->hydrationMode);
     $query->setRows(1);
     $query->setUseAndOperator(true);
     $query->addSearchTerm('id', $metaInformation->getDocumentName() . '_*');
     $query->setQueryDefaultField('id');
     $helper = $query->getHelper();
     foreach ($args as $fieldName => $fieldValue) {
         $fieldValue = $helper->escapeTerm($fieldValue);
         $query->addSearchTerm($fieldName, $fieldValue);
     }
     $found = $this->solr->query($query);
     return array_pop($found);
 }
コード例 #9
0
 /**
  * @When /^I add these entities to Solr$/
  */
 public function iAddThisEntityToSolr()
 {
     foreach ($this->entities as $entity) {
         $this->solr->addDocument($entity);
     }
 }
コード例 #10
0
 /**
  * @When /^I delete the entity$/
  */
 public function iDeleteTheEntity()
 {
     $this->solr->removeDocument($this->entity);
 }
コード例 #11
0
ファイル: SolrTest.php プロジェクト: wizbit/SolrBundle
 /**
  * @expectedException \BadMethodCallException
  */
 public function testAddEntity_FilteredEntityWithUnknownCallback()
 {
     $this->assertUpdateQueryWasNotExecuted();
     $this->eventDispatcher->expects($this->never())->method('dispatch');
     $information = MetaTestInformationFactory::getMetaInformation();
     $information->setSynchronizationCallback('shouldBeIndex');
     $this->setupMetaFactoryLoadOneCompleteInformation($information);
     $solr = new Solr($this->solrClientFake, $this->commandFactory, $this->eventDispatcher, $this->metaFactory, $this->mapper);
     $solr->addDocument(new InvalidTestEntityFiltered());
 }
コード例 #12
0
 /**
  * @inheritdoc
  */
 public function remove($entity)
 {
     $repo = $this->modelManager->get($this->getModel());
     $solrRepo = $this->solr->getRepository($repo->getClassName());
     $solrRepo->delete($entity);
 }