1. Go to this page and download the library: Download cornernote/yii-sphinx library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
$ids = array_keys($resArray['matches']);
$criteria = new CDbCriteria;
$criteria->addInCondition('id', $ids);
$criteria->order = 'FIELD(t.id, ' . implode(', ', $ids) . ')'; // order by weight
$products = Product::model()->findAll($criteria);
class Product extends CActiveRecord
{
public function tableName()
{
return 'product';
}
public function afterSave()
{
ProductIndex::model()->updateIndex($this);
parent::afterSave();
}
public function afterDelete()
{
ProductIndex::model()->deleteIndex($this);
parent::afterDelete();
}
}
class ProductIndex extends ESphinxActiveRecord
{
public function tableName()
{
return 'product';
}
public function truncateIndex()
{
$this->dbConnection->createCommand('TRUNCATE RTINDEX ' . ProductIndex::model()->tableName())->execute();
}
public function deleteIndex($product)
{
$this->dbConnection->createCommand("DELETE FROM " . ProductIndex::model()->tableName() . " WHERE id = " . $product->id)->execute();
}
public function updateIndex($product)
{
$productIndex = new ProductIndex();
$productIndex->id = $product->id;
$productIndex->name = $product->name;
$productIndex->description = $product->description;
$productIndex->status = $product->status;
$productIndex->save(false);
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.