Стоит задача сделать полнотекстовый поиск с пагинацией с базой mongo.
Полноценно поиск, без полноценного поиска и пагинацией реализовал, но как то просмотрел что реализация именно полнотекстового поиска после добавления индекса проходит иначе чем просто поиск и выполняется через команду
Так работает в консоли
Код: Выделить всё
db.products.runCommand("text",{search:'привет'});
Сейчас код примерно такой:
Код: Выделить всё
$category = new Category;
$model_category = $category -> getcategory();
$model = new Products;
$model -> section = Yii::$app -> request -> get('section');
$model -> text = Yii::$app -> request -> get('text');
$model -> price_min = (int) Yii::$app -> request -> get('price_min', 0);
$model -> price_max = (int) Yii::$app -> request -> get('price_max', 10000000);
$menu = $category -> building_tree($model -> section);
if ($model -> price_min != 0){
$price['price.cost'] = ['$gt' => $model -> price_min ];
}
if ($model -> price_max != 0)
$price['price.cost'] = ['$lt' => (int)$model -> price_max,'$gt' => $model -> price_min];
$price['price.cost'] = ['$lt' => (int)$model -> price_max,'$gt' => $model -> price_min];
$categorys = ['category.id' => ['$in' => $category -> node_element_array]];
$text_title = ['item_name' => ['$regex' => '.*' . $model -> text . '.*', '$options' => '$is']];
$text_property = ['property.description' => ['$regex' => '.*' . $model -> text . '.*', '$options' => '$is']];
$query = $model->find()
-> Where($text_title)
-> orWhere($text_property)
-> andwhere($categorys)
-> andwhere($price)
-> orderBy('item_name ASC');
$countQuery = clone $query;
$pages = new Pagination(['totalCount' => $countQuery -> count()]);
$model_page = $query -> offset($pages -> offset) -> limit($pages -> limit) -> all();