Exemplo n.º 1
0
 public function actionSearch()
 {
     $searchModel = new Search();
     $keyword = Yii::$app->request->get('keyword');
     if (empty($keyword)) {
         $this->goHome();
     }
     // 记录log
     $model = new SearchLog();
     $model->setAttributes(['user_id' => Yii::$app->user->isGuest ? '' : Yii::$app->user->identity->getId(), 'keyword' => $keyword, 'created_at' => time()]);
     $model->save();
     $dataProvider = $searchModel->search($keyword);
     return $this->render('search', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]);
 }
Exemplo n.º 2
0
 /**
  * wap站搜索
  * @return array
  */
 public function actionIndex()
 {
     $size = 10;
     $request = \Yii::$app->request;
     if ($request->isGet) {
         $key = $request->get('key');
         $tab = $request->get('tab');
         if (!empty($key)) {
             //关键词搜索
             $select = 'id,name,description,pinyin_initial';
             $where = array();
             if (!empty($tab)) {
                 //根据tab,判断搜索条件
                 if ($tab == 't1') {
                     $where = array('tmp_source_id' => array(1));
                     //只搜索疾病
                 } else {
                     if ($tab == 't2') {
                         $where = array('tmp_source_id' => array(2));
                         //只搜索症状
                     }
                 }
             }
             $paging = $this->helpPaging('wap_pager_search')->setSize($size)->setPageSetSize(7);
             $offset = $paging->getOffset();
             $res = Search::search_disease_symptom_merge($key, $offset, $size, 0, $where);
             //数据集合
             $paging->setTotal($res['total']);
             if (empty($res['list'])) {
                 //判断条件为空,转为站内搜索
                 return $this->redirect('http://sousuo.9939.com/cse/search?s=2200337477999120096&isNeedCheckDomain=1&jump=1&q=' . $key);
             }
             $data = array('res' => $res['list'], 'paging' => $paging, 'tab' => $tab, 'key' => $key, 'explain_words' => $res['explain_words']);
             return $this->render('keyword_index', $data);
         } else {
             $commonDisease = $this->seek->getCommonDisease();
             //查询相关疾病数据
             $departmentLevel1 = $this->department->getDepartmentLevel1();
             //获取页面的一级科室
             $partlevel1 = $this->part->getPartLevel1();
             //获取页面的一级部位
             $data = array('DepartmentLevel1' => $departmentLevel1, 'partlevel1' => $partlevel1, 'commonDisease' => $commonDisease);
             return $this->render('index', $data);
         }
     }
 }
 /**
  * 获取相关问答数据
  * @param type $param
  */
 public function getRelAsks($keywords, $offset = 0, $limit = 5)
 {
     $asks = Search::search_ask($keywords, $offset, $limit);
     //相关问答
     $doc = new Doctor();
     foreach ($asks['list'] as $k => $v) {
         if (isset($v['answer'])) {
             $v['userid'] = '';
             $res = $doc->getDoctorById($v['answer']['userid']);
             $doctor = array_shift($res);
             $asks['list'][$k]['answer']['truename'] = $doctor['truename'] ?: $doctor['nickname'];
             $asks['list'][$k]['answer']['doc_keshi'] = $doctor['doc_keshi'];
             $asks['list'][$k]['answer']['pic'] = $doctor['pic'] ?: 'default.jpg';
             unset($res);
             unset($doctor);
         }
     }
     return $asks;
 }
Exemplo n.º 4
0
 public function afterSave($insert, $changedAttributes)
 {
     parent::afterSave($insert, $changedAttributes);
     if ($insert) {
         $search = new Search();
         $search->topic_id = $this->id;
         $search->status = self::STATUS_ACTIVE;
     } else {
         //            Yii::$app->cache->set('topic' . $this->id, $this, 0);
         $search = Search::findOne($this->id);
         //            $search = false;
         if (!$search) {
             // 如果立即修改 会因为在 xunsearch 找不到而不能 save
             return false;
         }
         $search->status = $this->status;
     }
     $search->title = $this->title;
     $search->content = $this->content;
     $search->updated_at = $this->updated_at;
     $search->save();
 }
Exemplo n.º 5
0
 public function afterSave($insert, $changedAttributes)
 {
     parent::afterSave($insert, $changedAttributes);
     if (isset(Yii::$app->params['setting']) && Yii::$app->params['setting']['xunsearch']) {
         if ($insert) {
             $search = new Search();
             $search->topic_id = $this->id;
             $search->status = self::STATUS_ACTIVE;
         } else {
             $search = Search::findOne($this->id);
             if (!$search) {
                 // 如果立即修改 会因为在 xunsearch 找不到而不能 save
                 return false;
             }
             $search->status = $this->status;
         }
         $search->title = $this->title;
         $search->content = $this->content;
         $search->updated_at = $this->updated_at;
         $search->save();
     }
     (new NotificationService())->newPostNotify(\Yii::$app->user->identity, $this, $this->atUsers);
     if ($insert) {
         // 保存 meta data
         (new UserMeta())->saveNewMeta('topic', $this->id, 'follow');
         // 更新个人总统计
         UserInfo::updateAllCounters(['post_count' => 1], ['user_id' => $this->user_id]);
     }
 }
Exemplo n.º 6
0
 /**
  * 获取26字母下的热词
  */
 public function letterRandWords()
 {
     $letters = range('A', 'Z');
     $offset = 0;
     $length = 28;
     $type = array(array('filter' => 'filter', 'args' => array('typeid', array(0, 2, 3, 4))));
     foreach ($letters as $k => $v) {
         $ret[$v] = Search::search_words_byinitial($v, $offset, $length, $type);
     }
     $result['letter'] = $letters;
     $result['words'] = $ret;
     return $result;
 }
Exemplo n.º 7
0
 /**
  * 症状首页相关问答缓存数据
  * lc 2016-4-15
  * @param type $parms
  * @return type
  */
 public static function cacheSymptomRelateAsk($cacheKey, $parms, $forceCache = false)
 {
     $search = new Search();
     $symptomid = $parms['id'];
     $name = $parms['name'];
     $cache = \Yii::$app->cache_data_file;
     $key = $cacheKey . '_' . $symptomid;
     $data = $cache->get($key);
     if ($forceCache) {
         $data = false;
     }
     if (!isset($data) || empty($data)) {
         $questions = Search::search_ask($name, 0, 5);
         $cache->set($key, $questions, self::DURATION);
         return $questions;
     } else {
         return $data;
     }
 }
Exemplo n.º 8
0
 /**
  * 首页右侧热门关注
  * sphinx调用疾病文章查询
  * @return array latestFucus 对应的数据集合
  */
 public function latestFucus()
 {
     $cache = \Yii::$app->cache_file;
     $cache_key = 'frontend_seek_right_rmgz';
     //疾病搜索页面_右侧_热门关注
     $data = $cache->get($cache_key);
     if (!empty($data)) {
         return $data;
     } else {
         $queries = array(array('word' => '高血压', 'indexer' => 'index_9939_com_jb_art'), array('word' => '心脏病', 'indexer' => 'index_9939_com_jb_art'), array('word' => '包皮过长', 'indexer' => 'index_9939_com_jb_art'), array('word' => '乳腺增生', 'indexer' => 'index_9939_com_jb_art'), array('word' => '胃溃疡', 'indexer' => 'index_9939_com_jb_art'), array('word' => '宫颈癌', 'indexer' => 'index_9939_com_jb_art'), array('word' => '癫痫病', 'indexer' => 'index_9939_com_jb_art'), array('word' => '阳痿', 'indexer' => 'index_9939_com_jb_art'), array('word' => '哮喘', 'indexer' => 'index_9939_com_jb_art'), array('word' => '龋齿', 'indexer' => 'index_9939_com_jb_art'));
         $result = [];
         $ret = \librarys\helpers\utils\SearchHelper::batchSearch($queries);
         foreach ($ret as $kk => $ret) {
             $indexer_name = $ret['indexer'];
             $sphinx_result = Search::parse_search_data($ret, $indexer_name);
             $ret_list = $sphinx_result['list'];
             $kw = $queries[$kk]['word'];
             $result[$kw] = $ret_list;
         }
         $cache->set($cache_key, $result, 24 * 3600);
         return $result;
     }
 }
 public static function createCacheRandWords(array $condition = array(), $expired = 24)
 {
     ini_set('memory_limit', '512M');
     $return_pagenum_list = array();
     $expired = $expired * 3600;
     //一天
     $pagenum_expired = 2 * $expired;
     //两天
     $file_cache = \Yii::$app->cache_data_file;
     $cache_key_letter_pagenum = sprintf('$s|%s|%s|%s', 'disease_words', 'caches', 'randwords', 'pagenum');
     $cache_letter_pagenum_data = $file_cache->get($cache_key_letter_pagenum);
     if ($cache_letter_pagenum_data) {
         $return_pagenum_list = $cache_letter_pagenum_data;
     }
     //获取字母所对应的数据
     $letter_list = 'abcdefghijklmnopqrstuvwxyz';
     $len = strlen($letter_list);
     $return_list = array();
     $max_kw_length = 2500;
     // $size;
     for ($i = 0; $i < $len; $i++) {
         $wd = strtoupper($letter_list[$i]);
         $pagenum = isset($return_pagenum_list[$wd]) ? $return_pagenum_list[$wd] : 0;
         $pagenum = intval($pagenum) + 1;
         $tmp_offset = $pagenum * $max_kw_length;
         $return_info = Search::search_disease_symptom_words_byinitial($wd, $tmp_offset, $max_kw_length, $condition);
         if (count($return_info['list']) == 0 && $pagenum > 0) {
             $return_info = Search::search_disease_symptom_words_byinitial($wd, 0, $max_kw_length, $condition);
             $pagenum = 0;
         }
         $ret = $return_info['list'];
         $return_list[$wd] = $ret;
         $return_pagenum_list[$wd] = $pagenum;
     }
     self::createRandWordsForRedis($return_list);
     $cache_key_letter_words = sprintf('$s|%s|%s|%s', 'disease_words', 'caches', 'randwords', 'words');
     $file_cache->set($cache_key_letter_words, $return_list, $expired);
     $file_cache->set($cache_key_letter_pagenum, $return_pagenum_list, $pagenum_expired);
     return $return_list;
 }
Exemplo n.º 10
0
 /**
  * 首页 疾病资讯 inc_mid_news文件里的数据缓存
  * @param string $cacheKey
  * @param type $parms
  * @return 
  */
 public static function cacheIndexNewsBySphinx($cacheKey, $parms)
 {
     $newWords = $parms['newWords'];
     $art_obj = new \common\models\disease\Article();
     $cache = \Yii::$app->cache_data_file;
     $key = $cacheKey;
     $data = $cache->get($key);
     if (!isset($data) || empty($data)) {
         //1、根据不同的词拼出sphinx批量查询的条件
         $conditon = [];
         $n = 0;
         foreach ($newWords as $k => $v) {
             $w = $n;
             $conditon[$w] = ['word' => $k, 'indexer' => 'index_9939_com_jb_art'];
             $n++;
         }
         //            print_r($conditon);exit;
         //2、根据sphinx批量查询得到记录
         $sphinxRecords = SearchHelper::batchSearch($conditon);
         $result = array();
         foreach ($sphinxRecords as $kk => $ret) {
             $indexer_name = $ret['indexer'];
             $sphinx_result = Search::parse_search_data($ret, $indexer_name);
             $ret_list = $sphinx_result['list'];
             $kw = $conditon[$kk]['word'];
             $result[$kw] = $ret_list;
         }
         //            //7、设置缓存
         //            $cache->set($key, $result);
         return $result;
     } else {
         return $data;
     }
 }
Exemplo n.º 11
0
 private function get_relasklist($wd, $offset, $size)
 {
     $explain_ext_config = array('is_ext_words' => 1);
     $explainflag = 1;
     $condition = $this->rand_condition();
     return Search::search_ask($wd, $offset, $size, $condition, $explainflag, $explain_ext_config);
 }
Exemplo n.º 12
0
 /**
  * 在线问诊
  */
 public function actionOnlineInquiry()
 {
     $data = [];
     $temp = $this->params;
     $disease = $this->disease->getDiseasesByPinyin($temp['dname']);
     $doctor = $this->getDoctor($disease['id'], 3, 3);
     $asks = Search::search_ask($disease['keywords'], 0, 6);
     //相关问答
     //得到当前病 对应到 9939_com_v2sns wd_keshi 表中的 id 值
     $v2snsKeshiID = $this->diseaseService->getKeshiIDByName($disease['name']);
     $data['disease'] = $disease;
     $data['doctor'] = $doctor;
     $data['asks'] = $asks;
     $data['v2snsKeshiID'] = $v2snsKeshiID;
     return $this->render('online_inquiry', $data);
 }
Exemplo n.º 13
0
 public static function createCacheRandWords(array $condition = array(), $expired = 24)
 {
     ini_set('memory_limit', '512M');
     $key = md5(json_encode($condition));
     $return_pagenum_list = array();
     $expired = $expired * 3600;
     //一天
     $pagenum_expired = 2 * $expired;
     //两天
     $file_cache = \Yii::$app->cache_data_file;
     $file_cache->cachePath = \Yii::getAlias('@frontend') . '/runtime/cache/rand_words';
     $cache_key_letter_pagenum = sprintf('%s|%s|%s|%s', 'rand_words', 'caches', 'randwords' . '_' . $key, 'pagenum');
     $cache_letter_pagenum_data = $file_cache->get($cache_key_letter_pagenum);
     if ($cache_letter_pagenum_data) {
         $return_pagenum_list = $cache_letter_pagenum_data;
     }
     //获取字母所对应的数据
     $letter_list = 'abcdefghijklmnopqrstuvwxyz';
     $len = strlen($letter_list);
     $return_list = array();
     $max_kw_length = 3000;
     // $size;
     for ($i = 0; $i < $len; $i++) {
         $wd = strtoupper($letter_list[$i]);
         $pagenum = isset($return_pagenum_list[$wd]) ? $return_pagenum_list[$wd] : 0;
         $pagenum = intval($pagenum) + 1;
         $tmp_offset = $pagenum * $max_kw_length;
         $return_info = Search::search_words_byinitial($wd, $tmp_offset, $max_kw_length, $condition);
         if (count($return_info['list']) == 0 && $pagenum > 0) {
             $return_info = Search::search_words_byinitial($wd, 0, $max_kw_length, $condition);
             $pagenum = 0;
         }
         $ret = $return_info['list'];
         $return_list[$wd] = $ret;
         $return_pagenum_list[$wd] = $pagenum;
     }
     //根据查询条件生成redis缓存的key前缀
     $redis_cache_key_prefix = self::buildKey($condition);
     self::createRandWordsForRedis($redis_cache_key_prefix, $return_list);
     $cache_key_letter_words = sprintf('%s|%s|%s|%s', 'rand_words', 'caches', 'randwords' . '_' . $key, 'words');
     $file_cache->set($cache_key_letter_words, $return_list, $expired);
     $file_cache->set($cache_key_letter_pagenum, $return_pagenum_list, $pagenum_expired);
     return $return_list;
 }
Exemplo n.º 14
0
 /**
  * Deletes an existing Topic model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     $this->findModel($id)->delete();
     $search = Search::findOne($id);
     $search->delete();
     return $this->redirect(['index']);
 }
Exemplo n.º 15
0
 public function append()
 {
     if ($this->validate()) {
         $this->updated_at = time();
         if ($this->save()) {
             $topicContent = new TopicContent();
             if ($topicContent->load(Yii::$app->request->post())) {
                 $search = Search::findOne($this->id);
                 if (!empty($search)) {
                     $search->content .= $topicContent->content;
                     $search->save();
                 }
                 $topicContent->topic_id = $this->id;
                 $topicContent->is_append = 1;
                 $topicContent->created = time();
                 return $topicContent->save();
             }
         }
     }
     return false;
 }
 public function actionCheckBodyStepThree()
 {
     $condition['age'] = $this->helpGparam('age', 1);
     $condition['sex'] = $this->helpGparam('sex', 1);
     $condition['job'] = $this->helpGparam('job', 1);
     $model['option']['sex'] = $this->sexOptions;
     $model['option']['age'] = $this->ageOptions;
     $model['option']['job'] = $this->jobOptions;
     //已选择症状
     $selectSymptomId = $this->helpGparam('symptomid');
     $selectSymptomInfo = $this->symptom->getOneSymptom($selectSymptomId);
     $model['selectSymptom'] = $selectSymptomInfo;
     //相关症状
     $relSymptom = $this->relate->getRelateSymptoms($selectSymptomId);
     $model['relSymptom'] = $relSymptom;
     //相关疾病
     $relDisease = $this->relate->getRelateDiseases($selectSymptomId);
     $perpage = 6;
     $pagenum = $this->helpGparam('page', 1);
     $totalPage = count($relDisease);
     $page = $pagenum <= $totalPage / $perpage ? $pagenum : $totalPage / $perpage;
     $paging = $this->helpPaging('pagerjs_2')->setSize($perpage);
     $paging->setTotal($totalPage)->setCurrent($page);
     $offset = $paging->getOffset();
     $relDisease = array_slice($relDisease, $offset, $perpage);
     //查询结果
     $model['paging'] = $paging;
     $model['relDisease'] = $relDisease;
     //        print_r($relDisease);
     //        exit;
     //相关问答
     //        $cacheKey = 'frontend_symptom_index_xgwd';
     //        $parms = [
     //            'id' => $selectSymptomId,
     //            'name' => $selectSymptomInfo['name'],
     //        ];
     //        $questions = $this->cacheHelper->getCache($cacheKey, $parms);
     $questions = Search::search_ask($selectSymptomInfo['name'], 0, 5);
     //        print_r($questions['list']);
     //        exit;
     $doctor = new Doctor();
     $asks = [];
     foreach ($questions['list'] as $k => $v) {
         foreach ($v as $kk => $vv) {
             $asks[$k][$kk] = $vv;
             if (isset($v['answer'])) {
                 $doctorTmp = $doctor->getDoctorById($v['answer']['userid']);
                 $doctorTmp = array_shift($doctorTmp);
                 $asks[$k]['doctor'] = $doctorTmp;
             } else {
                 $asks[$k]['doctor'] = false;
             }
             //                print_r($tmp);
             //                exit;
         }
     }
     //        print_r($asks);
     //        exit;
     $model['questions'] = $asks;
     $model['condition'] = $condition;
     return $this->render('step3', ['model' => $model]);
 }
Exemplo n.º 17
0
 public function afterSave($insert, $changedAttributes)
 {
     parent::afterSave($insert, $changedAttributes);
     if (isset(Yii::$app->params['setting']) && Yii::$app->params['setting']['xunsearch']) {
         if ($insert) {
             $search = new Search();
             $search->topic_id = $this->id;
             $search->status = self::STATUS_ACTIVE;
         } else {
             $search = Search::findOne($this->id);
             if (!$search) {
                 // 如果立即修改 会因为在 xunsearch 找不到而不能 save
                 return false;
             }
             $search->status = $this->status;
         }
         $search->title = $this->title;
         $search->content = $this->content;
         $search->updated_at = $this->updated_at;
         $search->save();
     }
 }
Exemplo n.º 18
0
 /**
  * Deletes an existing Topic model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     $this->findModel($id)->delete();
     Yii::$app->cache->get('topic' . $id);
     $search = Search::findOne($id);
     $search->delete();
     return $this->redirect(['index']);
 }