示例#1
0
 private static function _init()
 {
     if (!self::$_SCWS) {
         self::$_SCWS = scws_new();
         if (!self::$_SCWS) {
             return false;
         }
         self::$_SCWS->set_charset('utf8');
         self::$_SCWS->set_rule(DBConfig::$SCWS['rule']);
         //设置配置文件utf8
         self::$_SCWS->set_ignore(true);
         //忽略标点
         //字典 默认 自定义 txt类型
         self::$_SCWS->set_dict(DBConfig::$SCWS['default_dict']);
         self::$_SCWS->add_dict(DBConfig::$SCWS['my_dict'], SCWS_XDICT_TXT);
     }
     return true;
 }
示例#2
0
 public function createUrlByWord($word)
 {
     $re = array();
     if (is_numeric($this->typeId) && $this->typeId != 0) {
         $re[] = array('word' => $this->params[$this->type]['name'] . '类', 'url' => UrlNamespace::searchUrl($this->orgWord));
     } elseif ($this->typeId === 'author') {
         $re[] = array('word' => '作者', 'url' => UrlNamespace::searchUrl($this->orgWord));
     } elseif (strtolower($this->typeId) == 'uid') {
         $this->typeId = 'author';
         $w = '';
         foreach (DBScws::cutWord($this->params['username']) as $v) {
             $w .= $v;
         }
         $re[] = array('word' => $this->params['username'], 'url' => UrlNamespace::searchUrl());
         return $re;
     } elseif (strtolower($this->typeId) == 'bookid') {
         $this->typeId = 'bookname';
         $w = '';
         foreach (DBScws::cutWord($this->params['diarybook']) as $v) {
             $w .= $v;
         }
         $re[] = array('word' => $this->params['diarybook'], 'url' => UrlNamespace::searchUrl());
         return $re;
     } elseif ($this->typeId === 'bookname') {
         $re[] = array('word' => '日记本', 'url' => UrlNamespace::searchUrl($this->orgWord));
     }
     foreach ($word as $value) {
         $w = '';
         foreach ($this->cutWord as $v) {
             if ($value != $v) {
                 $w .= $v;
             }
         }
         $re[] = array('word' => $value, 'url' => UrlNamespace::searchUrl($w, $this->typeId));
     }
     return $re;
 }
示例#3
0
 /**
  * 
  * @brief xapian query
  * @param array $params
  * @param int $page
  * @param int $pagesize
  */
 public static function searchHospital($disease = '', $province = '', $city = '', $district = '', $street = '', $level = 0, $keyword = '', $page = '', $pagesize = 20, $id = '')
 {
     $page = empty($page) ? 1 : $page;
     if (!self::_connect('/var/www/html/diary/xapian/hospital')) {
         return false;
     }
     //
     if ($keyword) {
         $realQuery = DBScws::cutWord($keyword, true);
     }
     //
     if ($disease) {
         $realQuery[] = 'DISEASE' . $disease;
     }
     //
     if ($province) {
         $realQuery[] = 'PROVINCE' . $province;
     }
     //
     if ($city) {
         $realQuery[] = 'CITY' . $city;
     }
     //
     if ($district) {
         $realQuery[] = 'DISTRICT' . $district;
     }
     //
     if ($street) {
         $realQuery[] = 'STREET' . $street;
     }
     //
     if ($level) {
         $realQuery[] = 'LEVEL' . $level;
     }
     //id
     if ($id) {
         $realQuery[] = 'ID' . $id;
     }
     if (empty($realQuery)) {
         $realQuery[] = 'HOSPITAL' . 'default';
     }
     $queryparser = new XapianQueryParser();
     $queryparser->set_database(self::$_INSTANCE);
     $enquire = new XapianEnquire(self::$_INSTANCE);
     $enquire->set_sort_by_value(0);
     //
     $query = new XapianQuery(XapianQuery::OP_AND, $realQuery);
     $enquire->set_query($query);
     $matches = $enquire->get_mset(0, 4000);
     //
     $start = $matches->begin();
     $end = $matches->end();
     $count = $matches->size();
     $index = 0;
     $re = array();
     while (!$start->equals($end)) {
         $data = array();
         if ($index < $page * $pagesize && $index >= ($page - 1) * $pagesize) {
             $doc = $start->get_document();
             $result = json_decode($doc->get_data(), true);
             $result['phone'] = $result['contact'];
             $r = explode("||", $result['title']);
             $result['title'] = $r[0];
             $r = explode(",", $result['contact']);
             $result['contact'] = $r[0];
             unset($result['puid'], $result['thumb_img'], $result['score'], $result['website'], $result['post_at'], $result['refresh_at'], $result['grab_url'], $result['ad_status'], $result['ad_types'], $result['user_id'], $result['username'], $result['listing_status'], $result['base_tag'], $result['image_count']);
             $re[] = $result;
             /*
             $termStart = $doc->termlist_begin();
                             $termEnd   = $doc->termlist_end();
                             $d['term']='';
                             while (!($termStart->equals($termEnd))) {
                                 $d['term'].= '|'.$termStart->get_term();
                                 $termStart->next();
                             }
                             var_dump($d);
             */
         } elseif ($index >= $page * $pagesize) {
             break;
         }
         $start->next();
         $index++;
     }
     return array($re, $count);
 }