require(WEBPATH.'includes/sphinx_api/sphinxapi.php'); $m_return = ''; $rpp=isset($m_params['rpp']) ? $m_params['rpp'] : 50; //$page = defined('page') ? page : Tools_Http::Get('page',true); $page = Tools_Http::Get('page',true); $session = Core_Session::getInstance(); $view = $session->Get('view'); $view_switch = Tools_Http::Get('view'); if($view_switch) $view = $view_switch; $session->Set('view',$view); $products = new Products(); $searchClass = new Products_Searches(); $PageData = Common_Page::getInstance(); $mode= isset($m_params['filter']) ? $m_params['filter'] : 'default'; if (isset($m_params)) { $catid = isset($m_params['catid']) ? $m_params['catid'] : 0; $car_make = !empty($m_params['car_make']) > 0 ? $m_params['car_make'] : 0; } else { $catid = defined ('catid') ? catid : 0; $car_make = defined ('car_make') ? car_make : 0; //Tools_Http::Get('filter_make',true) } $params = array( 'length' => $rpp, 'offset' => $page, 'order' => 'price asc' ); $fields = array(); if ($catid) { $fields['catid'][1] = $catid; $fields['catid'][2] =$catid; $fields['catid'][3] =$catid; $fields['catid'][4] =$catid; } if ($car_make) { $fields['carid'] = $car_make; } if (isset($search) && !empty($search)) { //$search = $DB->Escape($search); //echo strlen($search); $search = str_replace('!','',$search); $search = str_replace(' - ',' ',$search); $search = trim($search); $search_array=explode(' ',$search); $c=1; $pp = $page; if(!$page) $pp = 1; $per_page = 100; // SPHINX $keywords = explode(" ", $search); $keyword=''; foreach($keywords as $k) if(strlen($k)>1) $keyword.='+'.$k.'* '; $sq = ''; foreach($keywords as $str) { $sq .= $str.'* '; } $cl = new SphinxClient(); $cl->SetServer('localhost', 3313); $opts = array ( "before_match" => "", "after_match" => "", "chunk_separator" => " ... ", "limit" => 70, "around" => 3, ); $cl->SetSortMode ( SPH_SORT_ATTR_ASC, 'price' ); $cl->SetMatchMode(SPH_MATCH_EXTENDED2); $cl->SetRankingMode( SPH_RANK_PROXIMITY_BM25 ); $cl-> SetLimits(($pp-1)* $per_page,$per_page,$per_page+(($pp-1)* $per_page)); $result = $cl->Query($sq,'main_products_lv'); // print_r($result['matches']); if ($result && isset($result['matches']) && is_array($result['matches'])) { $ids = array_keys($result['matches']); $all_ids = implode(',',$ids); } $fields['id'] = $ids; /* foreach($search_array as $string) { $fields['search'][] =trim($string); // if(count($search_array)>1 && $c!=count($search_array)) $fields['title'] .= ' AND LIKE'; // $c++; } */ } else $search=''; if ($mode == 'newest') { $fields['new'] = 1; } if ($mode == 'sale') { $fields['sale'] = 1; } //$fields['active']=1; $goods = $products -> getList ($fields, $params); if (isset($search) && !empty($search)) { $searchClass->insertSearch($search,$goods['total']); $phrase_id = $searchClass->getIdByPhrase($search); if($phrase_id) $phraseData = $searchClass->getPhraseDetails($phrase_id); else $phraseData = array(); } $top = array(); //$top['popular'] = $products ->getProductsTop(5,21,$catid); //$top['sales'] = $products ->getCategorySales(5,21,$catid); $page_client_card = $PageData->getPageData(119); //print_r($goods); $goods_items = $goods['data']; $total_items = $goods['total']; $category_title = ''; if(isset($cat_item['id'])) { $category_title =$L->StrT('goods_categories','title', $cat_item['id'], $cat_item['title']); $Template->description = $category_title; } foreach($goods_items as $good) { $title = $good['good_name']; $k = explode(' ',$title); foreach($k as $kk) { $keywords_all[$kk]=1; } } $m=0; $keywords = array(); foreach($keywords_all as $key => $val) { $m++; if($m>5) continue; if(strlen($key)>2) $keywords[]=$key; } $Template->keywords = implode(' ,',$keywords); $m_return .= '
'.$L->Str('No products in this category').'
'; $m_return .= ''; } $m_return .= '