Esempio n. 1
0
 /**
  * 
  * @param type $keyword
  * @param type $limit
  * @param type $areaIds 当前地区及子地区
  * @return type
  */
 public function suggest($keyword, $limit = 20, $areaIds = '', $field = '*')
 {
     if (!$keyword) {
         return false;
     }
     $items = KeywordIndexer::model()->findAll(array('condition' => 'classify="poi" AND title LIKE :keyword' . ($areaIds ? " AND areaid IN({$areaIds})" : ''), 'limit' => $limit, 'select' => 'DISTINCT(logid)', 'order' => 'len ASC', 'params' => array(':keyword' => '%' . strtr($keyword, array('%' => '\\%', '_' => '\\_', '\\' => '\\\\')) . '%')));
     if (!empty($items)) {
         $ids = join(',', array_keys(CHtml::listData($items, 'logid', '')));
         if ($ids != '') {
             $_sql = "SELECT {$field} FROM {{position}} WHERE id IN({$ids}) AND status=" . Posts::STATUS_PASSED . " ORDER BY FIELD(id,{$ids})";
             $items = Yii::app()->db->createCommand($_sql)->queryAll();
             return $items;
         }
     }
     return false;
 }
Esempio n. 2
0
 public static function createKeywords($item)
 {
     if (!$item || empty($item)) {
         return false;
     }
     KeywordIndexer::model()->deleteAll('logid=:logid AND classify="poi"', array(':logid' => $item['id']));
     $_data = array('logid' => $item['id'], 'classify' => 'poi', 'areaid' => $item['areaid'], 'status' => $item['status']);
     if ($item['title_cn'] != '') {
         $_data['len'] = mb_strlen($item['title_cn'], 'GBK');
         $_data['title'] = $item['title_cn'];
         $hash = md5($_data['title']);
         $_data['hash'] = $hash;
         $_exinfo = KeywordIndexer::model()->find('areaid=:areaid AND classify="poi" AND hash=:hash', array(':areaid' => $item['areaid'], ':hash' => $hash));
         if (!$_exinfo) {
             $_data['times'] = 0;
         } elseif ($item['status'] != Posts::STATUS_PASSED) {
             $_data['times'] = 1;
         } else {
             $_data['times'] = 1;
             KeywordIndexer::model()->updateCounters(array('times' => 1), 'id=:id', array(':id' => $_exinfo['id']));
         }
         $model = new KeywordIndexer();
         $model->attributes = $_data;
         $model->save(false);
     }
     if ($item['title_en'] != '') {
         $_data['len'] = mb_strlen($item['title_en'], 'GBK');
         $_data['title'] = $item['title_en'];
         $hash = md5($_data['title']);
         $_data['hash'] = $hash;
         $_exinfo = KeywordIndexer::model()->find('areaid=:areaid AND classify="poi" AND hash=:hash', array(':areaid' => $item['areaid'], ':hash' => $hash));
         if (!$_exinfo) {
             $_data['times'] = 0;
         } elseif ($item['status'] != Posts::STATUS_PASSED) {
             $_data['times'] = 1;
         } else {
             $_data['times'] = 1;
             KeywordIndexer::model()->updateCounters(array('times' => 1), 'id=:id', array(':id' => $_exinfo['id']));
         }
         $model = new KeywordIndexer();
         $model->attributes = $_data;
         $model->save(false);
     }
     if ($item['title_local'] != '') {
         $_data['len'] = mb_strlen($item['title_local'], 'GBK');
         $_data['title'] = $item['title_local'];
         $hash = md5($_data['title']);
         $_data['hash'] = $hash;
         $_exinfo = KeywordIndexer::model()->find('areaid=:areaid AND classify="poi" AND hash=:hash', array(':areaid' => $item['areaid'], ':hash' => $hash));
         if (!$_exinfo) {
             $_data['times'] = 0;
         } elseif ($item['status'] != Posts::STATUS_PASSED) {
             $_data['times'] = 1;
         } else {
             $_data['times'] = 1;
             KeywordIndexer::model()->updateCounters(array('times' => 1), 'id=:id', array(':id' => $_exinfo['id']));
         }
         $model = new KeywordIndexer();
         $model->attributes = $_data;
         $model->save(false);
     }
     $nicks = array();
     if ($item['nickname'] != '') {
         $nicks = explode('#', $item['nickname']);
     }
     if (!empty($nicks)) {
         foreach ($nicks as $nick) {
             $_data = array('logid' => $item['id'], 'classify' => 'poi', 'areaid' => $item['areaid']);
             $_data['len'] = mb_strlen($nick, 'GBK');
             $_data['title'] = $nick;
             $hash = md5($_data['title']);
             $_data['hash'] = $hash;
             $_exinfo = KeywordIndexer::model()->find('areaid=:areaid AND classify="poi" AND hash=:hash', array(':areaid' => $item['areaid'], ':hash' => $hash));
             if (!$_exinfo) {
                 $_data['times'] = 0;
             } elseif ($item['status'] != Posts::STATUS_PASSED) {
                 $_data['times'] = 1;
             } else {
                 $_data['times'] = 1;
                 KeywordIndexer::model()->updateCounters(array('times' => 1), 'id=:id', array(':id' => $_exinfo['id']));
             }
             $model = new KeywordIndexer();
             $model->attributes = $_data;
             $model->save(false);
         }
     }
     return true;
 }