3

I want to creat a sql query in yii framework that look like this:

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');

i try this but it's not working:

    $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
        ));
Swissa Yaakov
  • 186
  • 3
  • 15

2 Answers2

2

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

This refers to the WHERE clause in an SQL statement

So there should be only MATCH (title,body) AGAINST ('Security implications of running MySQL as root')

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

This refers to the SELECT clause in an SQL statement

Here your place for id, body, MATCH (title,body) AGAINST ('Security implications of running MySQL as root') AS score

gaRex
  • 4,144
  • 25
  • 37
2

First of all you need to execute the ALTER query for search column.

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

Query to search

 $query = \common\models\Item::find()
             ->where(['is_active'=>'1']);
 $query->andWhere("MATCH(title,description,location) AGAINST 
 ('$searchKeywords' IN BOOLEAN MODE)"); 
Mohd Bashir
  • 949
  • 1
  • 8
  • 17