Skip to content

Commit

Permalink
'Runtime index' fixed to 'Real-tim index' to be consistent with Sphin…
Browse files Browse the repository at this point in the history
…x official docs
  • Loading branch information
klimov-paul committed Jun 2, 2017
1 parent 9328e5f commit b07b7bb
Show file tree
Hide file tree
Showing 17 changed files with 81 additions and 57 deletions.
2 changes: 1 addition & 1 deletion ActiveFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public function getIndexSchema()
if ($this->_index === null) {
throw new InvalidConfigException("Index does not exist: {$indexName}");
}
if (!$this->_index->isRuntime) {
if (!$this->_index->isRt) {
throw new InvalidConfigException("'{$indexName}' is not a runtime index. Only runtime indexes are supported.'");
}

Expand Down
2 changes: 1 addition & 1 deletion ActiveRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ protected function updateInternal($attributes = null)
// Replace is supported only by runtime indexes and necessary only for field update
$useReplace = false;
$indexSchema = $this->getIndexSchema();
if ($this->getIndexSchema()->isRuntime) {
if ($this->getIndexSchema()->isRt) {
foreach ($values as $name => $value) {
$columnSchema = $indexSchema->getColumn($name);
if ($columnSchema->isField) {
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Yii Framework 2 sphinx extension Change Log
2.0.9 under development
-----------------------

- no changes in this release.
- Enh #73: `isRuntime` field of `yii\sphinx\IndexSchema` renamed to `isRt` for consistency with official docs (klimov-paul)


2.0.8 May 15, 2017
Expand Down
1 change: 1 addition & 0 deletions Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
*
* @property string $lastInsertID The row ID of the last row inserted, or the last value retrieved from the
* sequence object. This property is read-only.
* @property Schema $schema The schema information for the Sphinx connection. This property is read-only.
*
* @author Paul Klimov <[email protected]>
* @since 2.0
Expand Down
27 changes: 25 additions & 2 deletions IndexSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* IndexSchema represents the metadata of a Sphinx index.
*
* @property array $columnNames List of column names. This property is read-only.
* @property bool $isRuntime whether this index is a real-time index. This property is deprecated, use [[isRt]] instead.
*
* @author Paul Klimov <[email protected]>
* @since 2.0
Expand All @@ -28,9 +29,9 @@ class IndexSchema extends Object
*/
public $type;
/**
* @var bool whether this index is a runtime index.
* @var bool whether this index is a real-time index.
*/
public $isRuntime;
public $isRt;
/**
* @var string primary key of this index.
*/
Expand Down Expand Up @@ -60,4 +61,26 @@ public function getColumnNames()
{
return array_keys($this->columns);
}

/**
* @deprecated
* This method is deprecated, use [[isRt]] instead.
* @return bool whether this index is a real-time index.
* @since 2.0.9
*/
public function isIsRuntime()
{
return $this->isRt;
}

/**
* @deprecated
* This method is deprecated, use [[isRt]] instead.
* @param bool $isRuntime whether this index is a real-time index.
* @since 2.0.9
*/
public function setIsRuntime($isRuntime)
{
$this->isRt = $isRuntime;
}
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Sphinx Extension for Yii 2
==========================

This extension adds [Sphinx](http://sphinxsearch.com/docs) full text search engine extension for the [Yii framework 2.0](http://www.yiiframework.com).
It supports all Sphinx features including [Runtime Indexes](http://sphinxsearch.com/docs/current.html#rt-indexes).
It supports all Sphinx features including [Real-time Indexes](http://sphinxsearch.com/docs/current.html#rt-indexes).

For license information check the [LICENSE](LICENSE.md)-file.

Expand Down
2 changes: 1 addition & 1 deletion Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ protected function resolveIndexType($index)
{
$indexTypes = $this->getIndexTypes();
$index->type = array_key_exists($index->name, $indexTypes) ? $indexTypes[$index->name] : 'unknown';
$index->isRuntime = ($index->type == 'rt');
$index->isRt = ($index->type == 'rt');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion docs/guide/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Sphinx Extension for Yii 2
==========================

This extension adds [Sphinx](http://sphinxsearch.com/docs) full text search engine extension for the Yii 2 framework.
It supports all Sphinx features including [Runtime Indexes](http://sphinxsearch.com/docs/current.html#rt-indexes).
It supports all Sphinx features including [Real-time Indexes](http://sphinxsearch.com/docs/current.html#rt-indexes).

Getting Started
---------------
Expand Down
8 changes: 4 additions & 4 deletions tests/ActiveFixtureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
use yii\sphinx\ActiveFixture;
use yii\test\FixtureTrait;
use yiiunit\extensions\sphinx\data\ar\ActiveRecord;
use yiiunit\extensions\sphinx\data\ar\RuntimeIndex;
use yiiunit\extensions\sphinx\data\ar\RtIndex;
use yiiunit\extensions\sphinx\data\fixture\MySphinxTestCase;
use yiiunit\extensions\sphinx\data\fixture\RuntimeIndexFixture;
use yiiunit\extensions\sphinx\data\fixture\RtIndexFixture;

class ActiveFixtureTest extends TestCase
{
Expand All @@ -23,7 +23,7 @@ public function testGetData()
$test = new MySphinxTestCase();
$test->setUp();
$fixture = $test->getFixture('runtimeIndex');
$this->assertEquals(RuntimeIndexFixture::className(), get_class($fixture));
$this->assertEquals(RtIndexFixture::className(), get_class($fixture));
$this->assertEquals(2, count($fixture));
$this->assertEquals(1, $fixture['row1']['id']);
$this->assertEquals('title1', $fixture['row1']['title']);
Expand All @@ -37,7 +37,7 @@ public function testGetModel()
$test = new MySphinxTestCase();
$test->setUp();
$fixture = $test->getFixture('runtimeIndex');
$this->assertEquals(RuntimeIndex::className(), get_class($fixture->getModel('row1')));
$this->assertEquals(RtIndex::className(), get_class($fixture->getModel('row1')));
$this->assertEquals(1, $fixture->getModel('row1')->id);
$this->assertEquals(1, $fixture->getModel('row1')->type_id);
$this->assertEquals(2, $fixture->getModel('row2')->id);
Expand Down
36 changes: 18 additions & 18 deletions tests/ActiveRecordTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use yii\sphinx\ActiveQuery;
use yiiunit\extensions\sphinx\data\ar\ActiveRecord;
use yiiunit\extensions\sphinx\data\ar\ArticleIndex;
use yiiunit\extensions\sphinx\data\ar\RuntimeIndex;
use yiiunit\extensions\sphinx\data\ar\RtIndex;

/**
* @group sphinx
Expand All @@ -20,7 +20,7 @@ protected function setUp()

protected function tearDown()
{
$this->truncateRuntimeIndex('yii2_test_rt_index');
$this->truncateIndex('yii2_test_rt_index');
parent::tearDown();
}

Expand Down Expand Up @@ -125,7 +125,7 @@ public function testFindBySql()

public function testInsert()
{
$record = new RuntimeIndex;
$record = new RtIndex;
$record->id = 15;
$record->title = 'test title';
$record->content = 'test content';
Expand All @@ -145,7 +145,7 @@ public function testInsert()
*/
public function testUpdate()
{
$record = new RuntimeIndex;
$record = new RtIndex;
$record->id = 2;
$record->title = 'test title';
$record->content = 'test content';
Expand All @@ -154,33 +154,33 @@ public function testUpdate()
$record->save();

// save
$record = RuntimeIndex::findOne(2);
$this->assertTrue($record instanceof RuntimeIndex);
$record = RtIndex::findOne(2);
$this->assertTrue($record instanceof RtIndex);
$this->assertEquals(7, $record->type_id);
$this->assertFalse($record->isNewRecord);

$record->type_id = 9;
$record->save();
$this->assertEquals(9, $record->type_id);
$this->assertFalse($record->isNewRecord);
$record2 = RuntimeIndex::findOne(['id' => 2]);
$record2 = RtIndex::findOne(['id' => 2]);
$this->assertEquals(9, $record2->type_id);

// replace
$query = 'replace';
$rows = RuntimeIndex::find()->match($query)->all();
$rows = RtIndex::find()->match($query)->all();
$this->assertEmpty($rows);
$record = RuntimeIndex::findOne(2);
$record = RtIndex::findOne(2);
$record->content = 'Test content with ' . $query;
$record->save();
$rows = RuntimeIndex::find()->match($query);
$rows = RtIndex::find()->match($query);
$this->assertNotEmpty($rows);

// updateAll
$pk = ['id' => 2];
$ret = RuntimeIndex::updateAll(['type_id' => 55], $pk);
$ret = RtIndex::updateAll(['type_id' => 55], $pk);
$this->assertEquals(1, $ret);
$record = RuntimeIndex::findOne($pk);
$record = RtIndex::findOne($pk);
$this->assertEquals(55, $record->type_id);
}

Expand All @@ -190,31 +190,31 @@ public function testUpdate()
public function testDelete()
{
// delete
$record = new RuntimeIndex;
$record = new RtIndex;
$record->id = 2;
$record->title = 'test title';
$record->content = 'test content';
$record->type_id = 7;
$record->category = [1, 2];
$record->save();

$record = RuntimeIndex::findOne(2);
$record = RtIndex::findOne(2);
$record->delete();
$record = RuntimeIndex::findOne(2);
$record = RtIndex::findOne(2);
$this->assertNull($record);

// deleteAll
$record = new RuntimeIndex;
$record = new RtIndex;
$record->id = 2;
$record->title = 'test title';
$record->content = 'test content';
$record->type_id = 7;
$record->category = [1, 2];
$record->save();

$ret = RuntimeIndex::deleteAll('id = 2');
$ret = RtIndex::deleteAll('id = 2');
$this->assertEquals(1, $ret);
$records = RuntimeIndex::find()->all();
$records = RtIndex::find()->all();
$this->assertEquals(0, count($records));
}

Expand Down
2 changes: 1 addition & 1 deletion tests/CommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class CommandTest extends TestCase
{
protected function tearDown()
{
$this->truncateRuntimeIndex('yii2_test_rt_index');
$this->truncateIndex('yii2_test_rt_index');
parent::tearDown();
}

Expand Down
4 changes: 2 additions & 2 deletions tests/SchemaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ public function testIndexType()

$index = $schema->getIndexSchema('yii2_test_article_index');
$this->assertEquals('local', $index->type);
$this->assertFalse($index->isRuntime);
$this->assertFalse($index->isRt);

$index = $schema->getIndexSchema('yii2_test_rt_index');
$this->assertEquals('rt', $index->type);
$this->assertTrue($index->isRuntime);
$this->assertTrue($index->isRt);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public function getConnection($reset = false, $open = true)
* Truncates the runtime index.
* @param string $indexName index name.
*/
protected function truncateRuntimeIndex($indexName)
protected function truncateIndex($indexName)
{
if ($this->sphinx) {
$this->sphinx->createCommand('TRUNCATE RTINDEX ' . $indexName)->execute();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace yiiunit\extensions\sphinx\data\ar;

class RuntimeIndex extends ActiveRecord
class RtIndex extends ActiveRecord
{
public static function indexName()
{
Expand Down
4 changes: 2 additions & 2 deletions tests/data/fixture/MySphinxTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace yiiunit\extensions\sphinx\data\fixture;

use yii\test\FixtureTrait;
use yiiunit\extensions\sphinx\data\fixture\RuntimeIndexFixture;
use yiiunit\extensions\sphinx\data\fixture\RtIndexFixture;

class MySphinxTestCase
{
Expand All @@ -22,7 +22,7 @@ public function tearDown()
public function fixtures()
{
return [
'runtimeIndex' => RuntimeIndexFixture::className(),
'runtimeIndex' => RtIndexFixture::className(),
];
}
}
20 changes: 20 additions & 0 deletions tests/data/fixture/RtIndexFixture.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace yiiunit\extensions\sphinx\data\fixture;

use yii\sphinx\ActiveFixture;
use yiiunit\extensions\sphinx\data\ar\RtIndex;

class RtIndexFixture extends ActiveFixture
{
public $modelClass = 'yiiunit\extensions\sphinx\data\ar\RtIndex';

/**
* @inheritdoc
*/
public function init()
{
$this->dataFile = __DIR__ . '/../fixtures/' . RtIndex::indexName() . '.php';
parent::init();
}
}
20 changes: 0 additions & 20 deletions tests/data/fixture/RuntimeIndexFixture.php

This file was deleted.

0 comments on commit b07b7bb

Please sign in to comment.