PHP 클래스 yii\sphinx\ActiveRecord

Warning: optimistic lock will NOT work in case of updating fields (not attributes) for the runtime indexes!
부터: 2.0
저자: Paul Klimov ([email protected])
상속: extends yii\db\BaseActiveRecord
파일 보기 프로젝트 열기: yiisoft/yii2-sphinx 1 사용 예제들

공개 메소드들

메소드 설명
attributes ( ) : array Returns the list of all attribute names of the model.
callKeywords ( string $text, boolean $fetchStatistic = false ) : array Returns tokenized and normalized forms of the keywords, and, optionally, keyword statistics.
callSnippets ( string | array $source, string $match, array $options = [] ) : string | array Builds a snippet from provided data and query, using specified index settings.
delete ( ) : integer | false Deletes the index entry corresponding to this active record.
deleteAll ( string | array $condition = '', array $params = [] ) : integer Deletes rows in the index using the provided conditions.
equals ( ActiveRecord $record ) : boolean Returns a value indicating whether the given active record is the same as the current one.
find ( ) : ActiveQuery
findBySql ( string $sql, array $params = [] ) : ActiveQuery Creates an ActiveQuery instance with a given SQL statement.
getDb ( ) : Connection Returns the Sphinx connection used by this AR class.
getIndexSchema ( ) : IndexSchema Returns the schema information of the Sphinx index associated with this AR class.
getSnippet ( string $match = null, array $options = [] ) : string Returns current snippet value or generates new one from given match.
getSnippetSource ( ) : string Returns the string, which should be used as a source to create snippet for this Active Record instance.
indexName ( ) : string Declares the name of the Sphinx index associated with this AR class.
insert ( boolean $runValidation = true, array $attributes = null ) : boolean Inserts a row into the associated Sphinx index using the attribute values of this record.
isTransactional ( integer $operation ) : boolean Returns a value indicating whether the specified operation is transactional in the current [[scenario]].
populateRecord ( $record, $row )
primaryKey ( ) : string[] Returns the primary key name for this AR class.
setSnippet ( string $snippet )
transactions ( ) : array Declares which operations should be performed within a transaction in different scenarios.
update ( boolean $runValidation = true, array $attributeNames = null ) : integer | false Saves the changes to this active record into the associated Sphinx index.
updateAll ( array $attributes, string | array $condition = '', array $params = [] ) : integer Updates the whole table using the provided attribute values and conditions.

보호된 메소드들

메소드 설명
fetchSnippet ( string $match, array $options = [] ) : string Builds up the snippet value from the given query.
updateInternal ( $attributes = null )

비공개 메소드들

메소드 설명
insertInternal ( $attributes = null )

메소드 상세

attributes() 공개 메소드

The default implementation will return all column names of the table associated with this AR class.
public attributes ( ) : array
리턴 array list of attribute names.

callKeywords() 공개 정적인 메소드

Returns tokenized and normalized forms of the keywords, and, optionally, keyword statistics.
public static callKeywords ( string $text, boolean $fetchStatistic = false ) : array
$text string the text to break down to keywords.
$fetchStatistic boolean whether to return document and hit occurrence statistics
리턴 array keywords and statistics

callSnippets() 공개 정적인 메소드

Builds a snippet from provided data and query, using specified index settings.
public static callSnippets ( string | array $source, string $match, array $options = [] ) : string | array
$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
리턴 string | array built snippet in case "source" is a string, list of built snippets in case "source" is an array.

delete() 공개 메소드

This method performs the following steps in order: 1. call [[beforeDelete()]]. If the method returns false, it will skip the rest of the steps; 2. delete the record from the index; 3. call [[afterDelete()]]. In the above step 1 and 3, events named [[EVENT_BEFORE_DELETE]] and [[EVENT_AFTER_DELETE]] will be raised by the corresponding methods.
public delete ( ) : integer | false
리턴 integer | false the number of rows deleted, or `false` if the deletion is unsuccessful for some reason. Note that it is possible the number of rows deleted is 0, even though the deletion execution is successful.

deleteAll() 공개 정적인 메소드

For example, to delete all articles whose status is 3: php Article::deleteAll('status = 3');
public static deleteAll ( string | array $condition = '', array $params = [] ) : integer
$condition string | array the conditions that will be put in the WHERE part of the DELETE SQL. Please refer to [[Query::where()]] on how to specify this parameter.
$params array the parameters (name => value) to be bound to the query.
리턴 integer the number of rows deleted

equals() 공개 메소드

The comparison is made by comparing the index names and the primary key values of the two active records. If one of the records [[isNewRecord|is new]] they are also considered not equal.
public equals ( ActiveRecord $record ) : boolean
$record ActiveRecord record to compare to
리턴 boolean whether the two active records refer to the same row in the same index.

fetchSnippet() 보호된 메소드

Builds up the snippet value from the given query.
protected fetchSnippet ( string $match, array $options = [] ) : string
$match string the full-text query to build snippets for.
$options array list of options in format: optionName => optionValue
리턴 string snippet value.

find() 공개 정적인 메소드

public static find ( ) : ActiveQuery
리턴 ActiveQuery the newly created [[ActiveQuery]] instance.

findBySql() 공개 정적인 메소드

Note that because the SQL statement is already specified, calling additional query modification methods (such as where(), order()) on the created ActiveQuery instance will have no effect. However, calling with(), asArray() or indexBy() is still fine. Below is an example: php $customers = Article::findBySql("SELECT * FROM idx_article WHERE MATCH('development')")->all();
public static findBySql ( string $sql, array $params = [] ) : ActiveQuery
$sql string the SQL statement to be executed
$params array parameters to be bound to the SQL statement during execution.
리턴 ActiveQuery the newly created [[ActiveQuery]] instance

getDb() 공개 정적인 메소드

By default, the "sphinx" application component is used as the Sphinx connection. You may override this method if you want to use a different Sphinx connection.
public static getDb ( ) : Connection
리턴 Connection the Sphinx connection used by this AR class.

getIndexSchema() 공개 정적인 메소드

Returns the schema information of the Sphinx index associated with this AR class.
public static getIndexSchema ( ) : IndexSchema
리턴 IndexSchema the schema information of the Sphinx index associated with this AR class.

getSnippet() 공개 메소드

Returns current snippet value or generates new one from given match.
public getSnippet ( string $match = null, array $options = [] ) : string
$match string snippet source query
$options array list of options in format: optionName => optionValue
리턴 string snippet value

getSnippetSource() 공개 메소드

Child classes must implement this method to return the actual snippet source text. For example: php public function getSnippetSource() { return $this->snippetSourceRelation->content; }
public getSnippetSource ( ) : string
리턴 string snippet source string.

indexName() 공개 정적인 메소드

By default this method returns the class name as the index name by calling [[Inflector::camel2id()]]. For example, 'Article' becomes 'article', and 'StockItem' becomes 'stock_item'. You may override this method if the index is not named after this convention.
public static indexName ( ) : string
리턴 string the index name

insert() 공개 메소드

This method performs the following steps in order: 1. call [[beforeValidate()]] when $runValidation is true. If validation fails, it will skip the rest of the steps; 2. call [[afterValidate()]] when $runValidation is true. 3. call [[beforeSave()]]. If the method returns false, it will skip the rest of the steps; 4. insert the record into index. If this fails, it will skip the rest of the steps; 5. call [[afterSave()]]; In the above step 1, 2, 3 and 5, events [[EVENT_BEFORE_VALIDATE]], [[EVENT_BEFORE_INSERT]], [[EVENT_AFTER_INSERT]] and [[EVENT_AFTER_VALIDATE]] will be raised by the corresponding methods. Only the [[changedAttributes|changed attribute values]] will be inserted. For example, to insert an article record: php $article = new Article(); $article->id = $id; $article->genre_id = $genreId; $article->content = $content; $article->insert();
public insert ( boolean $runValidation = true, array $attributes = null ) : boolean
$runValidation boolean whether to perform validation before saving the record. If the validation fails, the record will not be inserted.
$attributes array list of attributes that need to be saved. Defaults to null, meaning all attributes that are loaded from index will be saved.
리턴 boolean whether the attributes are valid and the record is inserted successfully.

isTransactional() 공개 메소드

Returns a value indicating whether the specified operation is transactional in the current [[scenario]].
public isTransactional ( integer $operation ) : boolean
$operation integer the operation to check. Possible values are [[OP_INSERT]], [[OP_UPDATE]] and [[OP_DELETE]].
리턴 boolean whether the specified operation is transactional in the current [[scenario]].

populateRecord() 공개 정적인 메소드

public static populateRecord ( $record, $row )

primaryKey() 공개 정적인 메소드

The default implementation will return the primary key as declared in the Sphinx index, which is associated with this AR class. Note that an array should be returned even for a table with single primary key.
public static primaryKey ( ) : string[]
리턴 string[] the primary keys of the associated Sphinx index.

setSnippet() 공개 메소드

public setSnippet ( string $snippet )
$snippet string

transactions() 공개 메소드

The supported DB operations are: [[OP_INSERT]], [[OP_UPDATE]] and [[OP_DELETE]], which correspond to the ActiveRecord::insert, ActiveRecord::update and ActiveRecord::delete methods, respectively. By default, these methods are NOT enclosed in a transaction. In some scenarios, to ensure data consistency, you may want to enclose some or all of them in transactions. You can do so by overriding this method and returning the operations that need to be transactional. For example, php return [ 'admin' => self::OP_INSERT, 'api' => self::OP_INSERT | self::OP_UPDATE | self::OP_DELETE, the above is equivalent to the following: 'api' => self::OP_ALL, ]; The above declaration specifies that in the "admin" scenario, the insert operation (ActiveRecord::insert) should be done in a transaction; and in the "api" scenario, all the operations should be done in a transaction.
public transactions ( ) : array
리턴 array the declarations of transactional operations. The array keys are scenarios names, and the array values are the corresponding transaction operations.

update() 공개 메소드

This method performs the following steps in order: 1. call [[beforeValidate()]] when $runValidation is true. If validation fails, it will skip the rest of the steps; 2. call [[afterValidate()]] when $runValidation is true. 3. call [[beforeSave()]]. If the method returns false, it will skip the rest of the steps; 4. save the record into index. If this fails, it will skip the rest of the steps; 5. call [[afterSave()]]; In the above step 1, 2, 3 and 5, events [[EVENT_BEFORE_VALIDATE]], [[EVENT_BEFORE_UPDATE]], [[EVENT_AFTER_UPDATE]] and [[EVENT_AFTER_VALIDATE]] will be raised by the corresponding methods. Only the [[changedAttributes|changed attribute values]] will be saved into database. For example, to update an article record: php $article = Article::findOne($id); $article->genre_id = $genreId; $article->group_id = $groupId; $article->update(); Note that it is possible the update does not affect any row in the table. In this case, this method will return 0. For this reason, you should use the following code to check if update() is successful or not: php if ($this->update() !== false) { update successful } else { update failed }
public update ( boolean $runValidation = true, array $attributeNames = null ) : integer | false
$runValidation boolean whether to perform validation before saving the record. If the validation fails, the record will not be inserted into the database.
$attributeNames array list of attributes that need to be saved. Defaults to null, meaning all attributes that are loaded from DB will be saved.
리턴 integer | false the number of rows affected, or `false` if validation fails or [[beforeSave()]] stops the updating process.

updateAll() 공개 정적인 메소드

For example, to change the status to be 1 for all articles which status is 2: php Article::updateAll(['status' => 1], 'status = 2');
public static updateAll ( array $attributes, string | array $condition = '', array $params = [] ) : integer
$attributes array attribute values (name-value pairs) to be saved into the table
$condition string | array the conditions that will be put in the WHERE part of the UPDATE SQL. Please refer to [[Query::where()]] on how to specify this parameter.
$params array the parameters (name => value) to be bound to the query.
리턴 integer the number of rows updated

updateInternal() 보호된 메소드

또한 보기: CActiveRecord::update()
protected updateInternal ( $attributes = null )