/** * @return CSolrClient */ private static function getClient() { if (is_null(self::$_client)) { $params = array("hostname" => CSettingsManager::getSettingValue("solr_server"), "port" => CSettingsManager::getSettingValue("solr_port"), "path" => "solr/PortalASU"); self::$_client = new SolrClient($params); } return self::$_client; }
public function actionExport() { $metaModel = CCoreObjectsManager::getCoreModel(CRequest::getInt("id")); if (!$metaModel->isExportable()) { $this->redirect("models.php?action=edit&id=" . $metaModel->getId()); echo 1; return false; } $modelClass = $metaModel->class_name; $model = new $modelClass(); $records = CActiveRecordProvider::getAllFromTable($model->getRecord()->getTable()); foreach ($records->getItems() as $record) { $model = new $modelClass($record); CSolr::addObject($model); } CSolr::commit(); echo 1; }
public function actionGlobalSearch() { /** * Запрос, который отправил пользователь */ $userQuery = CRequest::getString("keyword"); /** * Задачи, в которые у него есть доступ */ $tasks = array(); foreach (CSession::getCurrentUser()->getRoles()->getItems() as $role) { $tasks[] = $role->getId(); } /** * Непосредственно, поиск */ $params = array("_is_main_" => 1, "_highlight_" => "doc_body"); $resultObj = CSolr::search($userQuery, $params); /** * Формируем модель данных для рисования результата */ $result = array(); $userQuery = mb_strtolower($userQuery); foreach ($resultObj->getDocuments() as $doc) { $hl = $resultObj->getHighlighingByDocument($doc); $res = array("text" => implode(", ", $hl)); /** * Получаем метамодель для этого типа объекта * Смотрим, какие задачи с ней связны */ $model = CCoreObjectsManager::getCoreModel($doc->_class_); $tasks = array(); if (!is_null($model)) { foreach ($model->tasks->getItems() as $task) { /** * Для каждой задачи формируем URL с фильтром */ $title = $task->name; $url = $task->url; $urlParams = array(); $urlParams[] = "filterClass=" . $doc->_class_; $urlParams[] = "filterLabel=" . str_replace("</em>", "", str_replace("<em>", "", implode(", ", $hl))); foreach ($model->fields->getItems() as $field) { if (property_exists($doc, $field->field_name)) { $fieldName = $field->field_name; $fieldValue = mb_strtolower($doc->{$fieldName}); if (mb_strpos($fieldValue, $userQuery) !== false) { if (mb_strlen($fieldValue) < 100) { $urlParams[] = "filter=" . $fieldName . ":" . $fieldValue; } else { $urlParams[] = "filter=" . $fieldName . ":" . $userQuery; } } } } $url .= "?" . implode("&", $urlParams); $tasks[$url] = $title; } } $res["tasks"] = $tasks; $result[] = $res; } /** * Склеиваем результаты с одинаковым текстом */ $outResults = array(); foreach ($result as $res) { $key = $res["text"]; if (array_key_exists($key, $outResults)) { $obj = $outResults[$key]; $tasks = $obj["tasks"]; foreach ($res["tasks"] as $url => $title) { $tasks[$url] = $title; } $obj["tasks"] = $tasks; } else { $obj = $res; } $outResults[$key] = $obj; } /** * Отображением */ $this->setData("results", $outResults); $this->renderView("_search/results.tpl"); }