Browse Source

Docs for Sphinx extension updated.

tags/2.0.0-beta
Paul Klimov 11 years ago
parent
commit
400b5310ca
  1. 2
      extensions/sphinx/ActiveRecord.php
  2. 49
      extensions/sphinx/README.md
  3. 24
      tests/unit/extensions/sphinx/ActiveDataProviderTest.php

2
extensions/sphinx/ActiveRecord.php

@ -35,7 +35,7 @@ use Yii;
* @author Paul Klimov <klimov.paul@gmail.com> * @author Paul Klimov <klimov.paul@gmail.com>
* @since 2.0 * @since 2.0
*/ */
class ActiveRecord extends Model abstract class ActiveRecord extends Model
{ {
/** /**
* @event Event an event that is triggered when the record is initialized via [[init()]]. * @event Event an event that is triggered when the record is initialized via [[init()]].

49
extensions/sphinx/README.md

@ -66,4 +66,53 @@ return [
], ],
], ],
]; ];
```
This extension provides ActiveRecord solution similar ot the [[\yii\db\ActiveRecord]].
To declare an ActiveRecord class you need to extend [[\yii\sphinx\ActiveRecord]] and
implement the `indexName` method:
```php
use yii\sphinx\ActiveRecord;
class Article extends ActiveRecord
{
/**
* @return string the name of the index associated with this ActiveRecord class.
*/
public static function indexName()
{
return 'idx_article';
}
}
```
You can use [[\yii\data\ActiveDataProvider]] with the [[\yii\sphinx\Query]] and [[\yii\sphinx\ActiveQuery]]:
```php
use yii\data\ActiveDataProvider;
use yii\sphinx\Query;
$query = new Query;
$query->from('yii2_test_article_index')->match('development');
$provider = new ActiveDataProvider([
'query' => $query,
'pagination' => [
'pageSize' => 10,
]
]);
$models = $provider->getModels();
```
```php
use yii\data\ActiveDataProvider;
use app\models\Article;
$provider = new ActiveDataProvider([
'query' => Article::find(),
'pagination' => [
'pageSize' => 10,
]
]);
$models = $provider->getModels();
``` ```

24
tests/unit/extensions/sphinx/ActiveDataProviderTest.php

@ -3,6 +3,7 @@
namespace yiiunit\extensions\sphinx; namespace yiiunit\extensions\sphinx;
use yii\data\ActiveDataProvider; use yii\data\ActiveDataProvider;
use yii\sphinx\Query;
use yiiunit\data\sphinx\ar\ActiveRecord; use yiiunit\data\sphinx\ar\ActiveRecord;
use yiiunit\data\sphinx\ar\ArticleIndex; use yiiunit\data\sphinx\ar\ArticleIndex;
@ -19,6 +20,29 @@ class ActiveDataProviderTest extends SphinxTestCase
// Tests : // Tests :
public function testQuery()
{
$query = new Query;
$query->from('yii2_test_article_index');
$provider = new ActiveDataProvider([
'query' => $query,
'db' => $this->getConnection(),
]);
$models = $provider->getModels();
$this->assertEquals(2, count($models));
$provider = new ActiveDataProvider([
'query' => $query,
'db' => $this->getConnection(),
'pagination' => [
'pageSize' => 1,
]
]);
$models = $provider->getModels();
$this->assertEquals(1, count($models));
}
public function testActiveQuery() public function testActiveQuery()
{ {
$provider = new ActiveDataProvider([ $provider = new ActiveDataProvider([

Loading…
Cancel
Save