Index: branches/5.0.x/core/kernel/db/cat_event_handler.php =================================================================== diff -u -N -r12368 -r12666 --- branches/5.0.x/core/kernel/db/cat_event_handler.php (.../cat_event_handler.php) (revision 12368) +++ branches/5.0.x/core/kernel/db/cat_event_handler.php (.../cat_event_handler.php) (revision 12666) @@ -1,6 +1,6 @@ 'OnSimpleSearch', - 'subsearch' => 'OnSubSearch', - 'advanced' => 'OnAdvancedSearch'); - if($this->Application->GetVar('INPORTAL_ON') && $this->Application->GetVar('Action') == 'm_simple_subsearch') - { - $type = 'subsearch'; - } - else - { - $type = $this->Application->GetVar('search_type') ? $this->Application->GetVar('search_type') : 'simple'; - } + $event_mapping = Array ( + 'simple' => 'OnSimpleSearch', + 'subsearch' => 'OnSubSearch', + 'advanced' => 'OnAdvancedSearch' + ); - if($keywords = $event->getEventParam('keyword_string')) // processing keyword_string param of ListProducts tag - { + $type = $this->Application->GetVar('search_type', 'simple'); + + if ($keywords = $event->getEventParam('keyword_string')) { + // processing keyword_string param of ListProducts tag $this->Application->SetVar('keywords', $keywords); $type = 'simple'; } + $search_event = $event_mapping[$type]; $this->$search_event($event); $search_table = TABLE_PREFIX.'ses_'.$this->Application->GetSID().'_'.TABLE_PREFIX.'Search'; $sql = 'SHOW TABLES LIKE "'.$search_table.'"'; + if ($this->Conn->Query($sql)) { $search_res_ids = $this->Conn->GetCol('SELECT ResourceId FROM '.$search_table); } @@ -414,6 +411,7 @@ $type_clauses['search']['include'] = '0'; $type_clauses['search']['except'] = '1'; } + $type_clauses['search']['having_filter'] = false; } @@ -1037,19 +1035,13 @@ } /** - * Makes simple search for products + * Makes simple search for category items * based on keywords string * * @param kEvent $event - * @todo Change all hardcoded Products table & In-Commerce module usage to dynamic usage from item config !!! */ function OnSimpleSearch(&$event) { - if($this->Application->GetVar('INPORTAL_ON') && !($this->Application->GetVar('Action') == 'm_simple_search')) - { - return; - } - $event->redirect = false; $search_table = TABLE_PREFIX.'ses_'.$this->Application->GetSID().'_'.TABLE_PREFIX.'Search'; @@ -1072,11 +1064,9 @@ } $this->Application->StoreVar('keywords', $keywords); - if (!$this->Application->GetVar('INPORTAL_ON')) { - // don't save search log, because in-portal already saved it - $this->saveToSearchLog($keywords, 0); // 0 - simple search, 1 - advanced search - } + $this->saveToSearchLog($keywords, 0); // 0 - simple search, 1 - advanced search + $keywords = strtr($keywords, Array('%' => '\\%', '_' => '\\_')); $event->setPseudoClass('_List'); @@ -1227,17 +1217,8 @@ $where_clause = $where_clause.' AND '.$items_table.'.Status=1'; - if($this->Application->GetVar('Action') == 'm_simple_subsearch') // subsearch, In-portal - { - if( $event->getEventParam('ResultIds') ) - { - $where_clause .= ' AND '.$items_table.'.ResourceId IN ('.implode(',', $event->specificParams['ResultIds']).')'; - } - } - if( $event->MasterEvent && $event->MasterEvent->Name == 'OnListBuild' ) // subsearch, k4 - { - if( $event->MasterEvent->getEventParam('ResultIds') ) - { + if ($event->MasterEvent && $event->MasterEvent->Name == 'OnListBuild') { + if ($event->MasterEvent->getEventParam('ResultIds')) { $where_clause .= ' AND '.$items_table.'.ResourceId IN ('.implode(',', $event->MasterEvent->getEventParam('ResultIds')).')'; } } @@ -1268,6 +1249,9 @@ $revelance_parts[] = 'IF('.$field.' LIKE "%'.$keyword.'%", '.$weight.', 0)'; } } + + $revelance_parts = array_unique($revelance_parts); + $conf_postfix = $this->Application->getUnitOption($event->Prefix, 'SearchConfigPostfix'); $rel_keywords = $this->Application->ConfigValue('SearchRel_Keyword_'.$conf_postfix) / 100; $rel_pop = $this->Application->ConfigValue('SearchRel_Pop_'.$conf_postfix) / 100; @@ -1281,7 +1265,7 @@ } // building final search query - if (!$this->Application->GetVar('do_not_drop_search_table') && !$this->Application->GetVar('INPORTAL_ON')) { + if (!$this->Application->GetVar('do_not_drop_search_table')) { $this->Conn->Query('DROP TABLE IF EXISTS '.$search_table); // erase old search table if clean k4 event $this->Application->SetVar('do_not_drop_search_table', true); }