Class yii\sphinx\Command
| Inheritance | yii\sphinx\Command » yii\db\Command | 
|---|---|
| Available since version | 2.0 | 
Command represents a SQL statement to be executed against a Sphinx.
A command object is usually created by calling yii\sphinx\Connection::createCommand(). The SQL statement it represents can be set via the \yii\sphinx\sql property.
To execute a non-query SQL (such as INSERT, REPLACE, DELETE, UPDATE), call \yii\sphinx\execute(). To execute a SQL statement that returns result data set (such as SELECT, CALL SNIPPETS, CALL KEYWORDS), use \yii\sphinx\queryAll(), \yii\sphinx\queryOne(), \yii\sphinx\queryColumn(), \yii\sphinx\queryScalar(), or \yii\sphinx\query(). For example,
$articles = $connection->createCommand("SELECT * FROM `idx_article` WHERE MATCH('programming')")->queryAll();
Command supports SQL statement preparation and parameter binding just as \yii\db\Command does.
Command also supports building SQL statements by providing methods such as \yii\sphinx\insert(), update(), etc. For example,
$connection->createCommand()->update('idx_article', [
    'genre_id' => 15,
    'author_id' => 157,
])->execute();
To build SELECT SQL statements, please use yii\sphinx\Query and yii\sphinx\QueryBuilder instead.
Public Properties
| Property | Type | Description | Defined By | 
|---|---|---|---|
| $db | yii\sphinx\Connection | The Sphinx connection that this command is associated with. | yii\sphinx\Command | 
Public Methods
Property Details
Method Details
| public void addColumn ( $table, $column, $type ) | ||
| $table | ||
| $column | ||
| $type | ||
| public void addForeignKey ( $name, $table, $columns, $refTable, $refColumns, $delete = null, $update = null ) | ||
| $name | ||
| $table | ||
| $columns | ||
| $refTable | ||
| $refColumns | ||
| $delete | ||
| $update | ||
| public void addPrimaryKey ( $name, $table, $columns ) | ||
| $name | ||
| $table | ||
| $columns | ||
| public void alterColumn ( $table, $column, $type ) | ||
| $table | ||
| $column | ||
| $type | ||
Creates a batch INSERT command.
For example,
$connection->createCommand()->batchInsert('idx_user', ['name', 'age'], [
    ['Tom', 30],
    ['Jane', 20],
    ['Linda', 25],
])->execute();
Note that the values in each row must match the corresponding column names.
| public $this batchInsert ( $index, $columns, $rows ) | ||
| $index | string | The index that new rows will be inserted into. | 
| $columns | array | The column names | 
| $rows | array | The rows to be batch inserted into the index | 
| return | $this | The command object itself | 
|---|---|---|
Creates a batch REPLACE command.
For example,
$connection->createCommand()->batchReplace('idx_user', ['name', 'age'], [
    ['Tom', 30],
    ['Jane', 20],
    ['Linda', 25],
])->execute();
Note that the values in each row must match the corresponding column names.
| public $this batchReplace ( $index, $columns, $rows ) | ||
| $index | string | The index that new rows will be replaced. | 
| $columns | array | The column names | 
| $rows | array | The rows to be batch replaced in the index | 
| return | $this | The command object itself | 
|---|---|---|
| public void bindValue ( $name, $value, $dataType = null ) | ||
| $name | ||
| $value | ||
| $dataType | ||
| public void bindValues ( $values ) | ||
| $values | ||
Returns tokenized and normalized forms of the keywords, and, optionally, keyword statistics.
| public $this callKeywords ( $index, $text, $fetchStatistic = false ) | ||
| $index | string | The name of the index from which to take the text processing settings | 
| $text | string | The text to break down to keywords. | 
| $fetchStatistic | boolean | Whether to return document and hit occurrence statistics | 
| return | $this | The command object itself | 
|---|---|---|
Builds a snippet from provided data and query, using specified index settings.
| public $this callSnippets ( $index, $source, $match, $options = [] ) | ||
| $index | string | Name of the index, from which to take the text processing settings. | 
| $source | string|array | Is the source data to extract a snippet from. It could be either a single string or array of strings. | 
| $match | string | The full-text query to build snippets for. | 
| $options | array | List of options in format: optionName => optionValue | 
| return | $this | The command object itself | 
|---|---|---|
| public void checkIntegrity ( $check = true, $schema = '', $table = '' ) | ||
| $check | ||
| $schema | ||
| $table | ||
| public void createIndex ( $name, $table, $columns, $unique = false ) | ||
| $name | ||
| $table | ||
| $columns | ||
| $unique | ||
| public void createTable ( $table, $columns, $options = null ) | ||
| $table | ||
| $columns | ||
| $options | ||
| public void dropColumn ( $table, $column ) | ||
| $table | ||
| $column | ||
| public void dropForeignKey ( $name, $table ) | ||
| $name | ||
| $table | ||
| public void dropIndex ( $name, $table ) | ||
| $name | ||
| $table | ||
| public void dropPrimaryKey ( $name, $table ) | ||
| $name | ||
| $table | ||
| public void dropTable ( $table ) | ||
| $table | ||
| public void getRawSql ( ) | 
| public void prepare ( $forRead = null ) | ||
| $forRead | ||
| public void renameColumn ( $table, $oldName, $newName ) | ||
| $table | ||
| $oldName | ||
| $newName | ||
| public void renameTable ( $table, $newName ) | ||
| $table | ||
| $newName | ||
Creates an REPLACE command.
For example,
$connection->createCommand()->replace('idx_user', [
    'name' => 'Sam',
    'age' => 30,
])->execute();
The method will properly escape the column names, and bind the values to be replaced.
Note that the created command is not executed until \yii\sphinx\execute() is called.
| public $this replace ( $index, $columns ) | ||
| $index | string | The index that new rows will be replaced into. | 
| $columns | array | The column data (name => value) to be replaced into the index. | 
| return | $this | The command object itself | 
|---|---|---|
| public void resetSequence ( $table, $value = null ) | ||
| $table | ||
| $value | ||
Creates a SQL command for truncating a runtime index.
| public $this truncateIndex ( $index ) | ||
| $index | string | The index to be truncated. The name will be properly quoted by the method. | 
| return | $this | The command object itself | 
|---|---|---|
| public void truncateTable ( $table ) | ||
| $table | ||
Creates an UPDATE command.
For example,
$connection->createCommand()->update('user', ['status' => 1], 'age > 30')->execute();
The method will properly escape the column names and bind the values to be updated.
Note that the created command is not executed until \yii\sphinx\execute() is called.
| public $this update ( $index, $columns, $condition = '', $params = [], $options = [] ) | ||
| $index | string | The index to be updated. | 
| $columns | array | The column data (name => value) to be updated. | 
| $condition | string|array | The condition that will be put in the WHERE part. Please refer to yii\sphinx\Query::where() on how to specify condition. | 
| $params | array | The parameters to be bound to the command | 
| $options | array | List of options in format: optionName => optionValue | 
| return | $this | The command object itself | 
|---|---|---|