Authored by 周少峰

搜索提示跨域访问

... ... @@ -217,7 +217,7 @@ class SearchModel
$result = SearchData::getSuggest($query);
if (isset($result['code']) && $result['code'] == 200 && isset($result['suggest']['items']) && !empty($result['suggest']['items'])) {
foreach ($result['suggest']['items'] as $v) {
$data .= '<li><a style="display: block;" href="http://search.yohobuy.com/?query='.$v['item'].'" class="clearfix clear search-item" title="'.$v['item'].'" act="http://search.yohobuy.com/?query='.$v['item'].'"><span class="searchvalue" >'.$v['item'].'</span><span class="valuenum">约'.$v['frequency'].'个商品</span></a></li>';
$data []= '<li><a style="display: block;" href="http://search.yohobuy.com/?query='.$v['item'].'" class="clearfix clear search-item" title="'.$v['item'].'" act="http://search.yohobuy.com/?query='.$v['item'].'"><span class="searchvalue" >'.$v['item'].'</span><span class="valuenum">约'.$v['frequency'].'个商品</span></a></li>';
}
}
return $data;
... ...
... ... @@ -21,13 +21,21 @@ class SearchController extends WebAction
*/
public function suggestAction()
{
$suggest = '';
$callback = $this->get('callback');
$query = rawurldecode($this->get('query'));
$size = rawurldecode($this->get('size',10));
if (empty($query)) {
$this->helpJsonCallbackResult($callback, 412, '搜索词为空');
}
if ($size > 50) {
$size = 10;
}
if ($query) {
$param['query'] = $query;
$param['size'] = $size;
$suggest = SearchModel::getSuggest($param);
}
echo $suggest;
$this->helpJsonCallbackResult($callback, 200, 'suggest', $suggest);
}
/**
... ...