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; }
/** * * @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); }