/**
  * Gets the solr connection
  * @return ASolrConnection the connection to use for this test
  */
 protected function getConnection()
 {
     static $connection;
     if ($connection === null) {
         $connection = new ASolrConnection();
         $connection->clientOptions->hostname = SOLR_HOSTNAME;
         $connection->clientOptions->port = SOLR_PORT;
         $connection->clientOptions->path = SOLR_PATH;
         ASolrDocument::$solr = $connection;
     }
     return $connection;
 }
Beispiel #2
0
 /**
  * Returns the solr connection used by solr document.
  * By default, the "solr" application component is used as the solr connection.
  * You may override this method if you want to use a different solr connection.
  * @return ASolrConnection the solr connection used by solr document.
  */
 public function getSolrConnection()
 {
     if ($this->_connection !== null) {
         return $this->_connection;
     } elseif (self::$solr !== null) {
         return self::$solr;
     } else {
         self::$solr = Yii::app()->solr;
         if (self::$solr instanceof IASolrConnection) {
             return self::$solr;
         } else {
             throw new CException(Yii::t('yii', 'Solr Document requires a "solr" ASolrConnection application component.'));
         }
     }
 }
Beispiel #3
0
 /**
  * Tests the delete method
  */
 public function testDelete()
 {
     $connection = new ASolrConnection();
     $connection->clientOptions->hostname = SOLR_HOSTNAME;
     $connection->clientOptions->port = SOLR_PORT;
     $connection->clientOptions->path = SOLR_PATH;
     ASolrDocument::$solr = $connection;
     foreach ($this->fixtureData() as $attributes) {
         $doc = ASolrDocument::model()->findByPk($attributes['id']);
         $this->assertTrue(is_object($doc));
         $this->assertTrue($doc->delete());
     }
     $connection->commit();
     // now check if they were really deleted
     foreach ($this->fixtureData() as $attributes) {
         $doc = ASolrDocument::model()->findByPk($attributes['id']);
         $this->assertFalse(is_object($doc));
     }
 }