日期:2014-05-17 浏览次数:20585 次
public function search()
{
global $_FANWE;
$page_args = array(
'city_py' => CURRENT_CITY_PY,
'sort' => trim($_FANWE['request']['sort']),
'keyword' => trim($_FANWE['request']['keyword']),
);
$keyword = '';
if(!empty($page_args['keyword']))
{
$page_args['keyword'] = urldecode($page_args['keyword']);
$keyword = &$page_args['keyword'];
$keyword_query = clearSymbol($page_args['keyword']);
if(!empty($keyword_query))
{
$search_txt = clearRepeat($keyword_query);
$keyword_query = segmentToUnicode($keyword_query,'+');
$fields = ",MATCH (gm.content) AGAINST ('$keyword_query') AS similarity ";
$where.=" WHERE MATCH (gm.content) AGAINST ('$keyword_query' IN BOOLEAN MODE)";
}
else
$keyword = '';
}
if(!empty($keyword))
{
$insert_sort = 'gk.cr_sort ASC';
$city_name = $_FANWE['current_city']['name'];
if(CURRENT_CITY_PY == CHINA_CITY_PY)
{
//全国不包含所有城市商品时
if($_FANWE['setting']['all_city'] == 0)
{
$where.= " AND gk.city = '$city_name'";
}
else
$insert_sort = 'gk.r_sort ASC';
}
elseif(CURRENT_CITY_PY != '')
{
//城市显示全国商品时
if($_FANWE['setting']['index_all'] == 1)
{
$fields .= ",(gk.city = '$city_name') as is_now_city";
$insert_sort = 'is_now_city DESC,'.$insert_sort;
$quanguo_name = $_FANWE['cache']['city']['all'][CHINA_CITY_PY]['name'];
$where.= " AND gk.city IN ('$city_name','$quanguo_name')";
}
else
{
$where.= " AND gk.city = '$city_name'";
}
}
$order = '';
$sort = &$page_args['sort'];
$sort_array = array('spa'=>'g.shop_price ASC','spd'=>'g.shop_price DESC','eta'=>'gk.end_time ASC','etd'=>'gk.end_time DESC','cca'=>'g.click_count ASC','ccd'=>'g.click_count DESC','sa'=>'g.score ASC','sd'=>'g.score DESC','ba'=>'g.bought ASC','bd'=>'g.bought DESC','da'=>'discount ASC','dd'=>'discount DESC');
if(array_key_exists($sort,$sort_array))
$order = $sort_array[$sort];
else
{
unset($page_args['sort']);
$sort = '';
}
if(empty($order))
$order .= 'similarity DESC,'.$insert_sort.',gk.sort ASC,g.id ASC';
else
$order .= ',similarity DESC,'.$insert_sort.',gk.sort ASC,g.id DESC';
$goods_count = DB::resultFirst('SELECT COUNT(DISTINCT g.id)
FROM '.DB::table('goods_now_match').' AS gm
INNER JOIN '.DB::table('goods_now_key').' AS gk ON gk.id = gm.id
INNER JOIN '.DB::table('goods_now').' AS g ON g.id = gk.id '.$where);
$pager = buildPage('now/search',$