protected function launch() { $query = Index::find(); $indexTable = Index::tableName(); if (!empty($this->_words)) { $searchWords = Yii::$app->db->quoteValue(implode(' ', $this->_words)); $query->select(["{$indexTable}.*", 'relevance' => "(MATCH ({$indexTable}.title, {$indexTable}.content) AGAINST ({$searchWords}) + (MATCH ({$indexTable}.tags) AGAINST ({$searchWords}) * 0.3))"])->where("MATCH ({$indexTable}.title, {$indexTable}.content) AGAINST ({$searchWords}) OR MATCH ({$indexTable}.tags) AGAINST ({$searchWords})")->orderBy("relevance DESC"); } else { // empty search $query->select("{$indexTable}.*")->orderBy("{$indexTable}.updated_at DESC"); } if (empty($this->models)) { $this->models = array_keys(self::models()); } // ищем только по тем моделям которые в списке $query->andWhere(['model_class' => $this->models]); // ивент на модификацию запроса сторонними модулями foreach ($this->models as $modelClass) { ModuleEvent::trigger(self::EVENT_BEFORE_SEARCH . $modelClass, new SqlBeforeSearchEvent(['query' => $query, 'sender' => $this])); } echo $this->render($this->layout, ['dataProvider' => new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => $this->pageSize]]), 'itemLayout' => $this->itemLayout]); }
/** * @inheritdoc */ public function deletePage($event) { $index = Index::find()->where(['model_id' => $event->model->getPrimaryKey(), 'model_class' => $event->model->className()])->one(); ModuleEvent::trigger(self::EVENT_BEFORE_DELETE_INDEX . $event->model->className(), new SqlIndexEvent(['model' => $event->model, 'index' => $index])); if ($index) { $index->delete(); } }