3

我想在 yii 框架中创建一个如下所示的 sql 查询:

mysql> SELECT id, body, MATCH (title,body) AGAINST
-> ('Security implications of running MySQL as root') AS score
-> FROM articles WHERE MATCH (title,body) AGAINST
-> ('Security implications of running MySQL as root');

我试试这个,但它不工作:

    $dataProvider = new CActiveDataProvider('data', array(
            'criteria'=>array(
                'condition' => 'MATCH (title,body) AGAINST ('Security implications of running MySQL as root') AS score', 
WHERE MATCH (title,body) AGAINST ('Security implications of running MySQL as root')
                'limit' => '20',            ),
            'pagination' => false
        ));
4

2 回答 2

2

http://www.yiiframework.com/doc/api/1.1/CDbCriteria#condition-detail

这是指 SQL 语句中的 WHERE 子句

所以应该只有MATCH (title,body) AGAINST ('Security implications of running MySQL as root')

http://www.yiiframework.com/doc/api/1.1/CDbCriteria#select-detail

这是指 SQL 语句中的 SELECT 子句

这里是你的地方id, body, MATCH (title,body) AGAINST ('Security implications of running MySQL as root') AS score

于 2014-01-09T07:51:26.177 回答
2

首先,您需要对搜索列执行 ALTER 查询。

 ALTER TABLE item ADD FULLTEXT(title,description,location);

查询要搜索

 $query = \common\models\Item::find()
             ->where(['is_active'=>'1']);
 $query->andWhere("MATCH(title,description,location) AGAINST 
 ('$searchKeywords' IN BOOLEAN MODE)"); 
于 2017-08-25T04:58:37.357 回答