ActiveDataProvider таким образом
public function actionSearch($query)
{
$search = Serial::find()->where(['or',['like', 'name_serial', $query],['like', 'description_serial', $query]])->limit(30);
$searchDataprovider = new ActiveDataProvider([
'query' => $search,
'pagination' => [
'pageSize' => 15,
],
]);
return $this->render('search', [
'searchDataprovider' => $searchDataprovider
]);
}
SELECT * FROM `fl_serial` WHERE (`name_serial` LIKE '%Игра престолов%') OR (`description_serial` LIKE '%Игра престолов%') LIMIT 15
SELECT * FROM `fl_serial` WHERE (`name_serial` LIKE '%Елизавета I%') OR (`description_serial` LIKE '%Елизавета I%') LIMIT 15
public function actionSearch($query)
{
$search = Serial::find()->where(['or',['like', 'name_serial', str_replace(' ','%',$query)],['like', 'description_serial', str_replace(' ','%',$query)]])->limit(30);
$searchDataprovider = new ActiveDataProvider([
'query' => $search,
'pagination' => [
'pageSize' => 15,
],
]);
return $this->render('search', [
'searchDataprovider' => $searchDataprovider
]);
}
SELECT * FROM `fl_serial` WHERE (`name_serial` LIKE '%Елизавета//%I%') OR (`description_serial` LIKE '%Елизавета//%I%') LIMIT 15
like: operand 1 should be a column or DB expression, and operand 2 be a string or an array representing the values that the column or DB expression should be like. For example, ['like', 'name', 'tester'] will generate name LIKE '%tester%'. When the value range is given as an array, multiple LIKE predicates will be generated and concatenated using AND. For example, ['like', 'name', ['test', 'sample']] will generate name LIKE '%test%' AND name LIKE '%sample%'. The method will properly quote the column name and escape special characters in the values. Sometimes, you may want to add the percentage characters to the matching value by yourself, you may supply a third operand false to do so. For example, ['like', 'name', '%tester', false] will generate name LIKE '%tester'.
or like: similar to the like operator except that OR is used to concatenate the LIKE predicates when operand 2 is an array.
not like: similar to the like operator except that LIKE is replaced with NOT LIKE in the generated condition.
or not like: similar to the not like operator except that OR is used to concatenate the NOT LIKE predicates.
public function actionSearch($query)
{
$subqueries = preg_split("/\s/u", $query, -1, PREG_SPLIT_NO_EMPTY);
//Лучше потом отфильровать $subqueries убрав короткие слова или пошаманить с регуляркой что разбивало только если за пробелом слово больше n символов (чтоб Елизавета X так и осталась Елизавета X)
// например так
// $subqueries = preg_split("/\s(?=\w{2,})/u", $query, -1, PREG_SPLIT_NO_EMPTY)
$search = Serial::find()->where(['or',['like', 'name_serial', $subqueries],['like', 'description_serial', $subqueries]]);
$searchDataprovider = new ActiveDataProvider([
'query' => $search,
'pagination' => [
'pageSize' => 15,
],
]);
return $this->render('search', [
'searchDataprovider' => $searchDataprovider
]);
}