Index: core/kernel/db/cat_event_handler.php =================================================================== --- core/kernel/db/cat_event_handler.php +++ core/kernel/db/cat_event_handler.php @@ -1105,13 +1105,16 @@ function OnSimpleSearch($event) { $event->redirect = false; - $search_table = TABLE_PREFIX.'ses_'.$this->Application->GetSID().'_'.TABLE_PREFIX.'Search'; $keywords = $this->Application->unescapeRequestVariable(trim($this->Application->GetVar('keywords'))); $query_object = $this->Application->recallObject('HTTPQuery'); /* @var $query_object kHTTPQuery */ + /** @var kSearchHelper $search_helper */ + $search_helper = $this->Application->recallObject('SearchHelper'); + + $search_table = $search_helper->getSearchTable(); $sql = 'SHOW TABLES LIKE "'.$search_table.'"'; if(!isset($query_object->Get['keywords']) && @@ -1122,7 +1125,7 @@ } if(!$keywords || strlen($keywords) < $this->Application->ConfigValue('Search_MinKeyword_Length')) { - $this->Conn->Query('DROP TABLE IF EXISTS '.$search_table); + $search_helper->ensureEmptySearchTable(); $this->Application->SetVar('keywords_too_short', 1); return; // if no or too short keyword entered, doing nothing } @@ -1239,10 +1242,6 @@ } } - // keyword string processing - $search_helper = $this->Application->recallObject('SearchHelper'); - /* @var $search_helper kSearchHelper */ - $where_clause = Array (); foreach ($field_list as $field) { if (preg_match('/^' . preg_quote($items_table, '/') . '\.(.*)/', $field, $regs)) { Index: core/units/categories/categories_event_handler.php =================================================================== --- core/units/categories/categories_event_handler.php +++ core/units/categories/categories_event_handler.php @@ -2450,13 +2450,16 @@ function OnSimpleSearch($event) { $event->redirect = false; - $search_table = TABLE_PREFIX.'ses_'.$this->Application->GetSID().'_'.TABLE_PREFIX.'Search'; $keywords = $this->Application->unescapeRequestVariable(trim($this->Application->GetVar('keywords'))); $query_object = $this->Application->recallObject('HTTPQuery'); /* @var $query_object kHTTPQuery */ + /** @var kSearchHelper $search_helper */ + $search_helper = $this->Application->recallObject('SearchHelper'); + + $search_table = $search_helper->getSearchTable(); $sql = 'SHOW TABLES LIKE "'.$search_table.'"'; if ( !isset($query_object->Get['keywords']) && !isset($query_object->Post['keywords']) && $this->Conn->Query($sql) ) { @@ -2466,7 +2469,7 @@ if(!$keywords || strlen($keywords) < $this->Application->ConfigValue('Search_MinKeyword_Length')) { - $this->Conn->Query('DROP TABLE IF EXISTS '.$search_table); + $search_helper->ensureEmptySearchTable(); $this->Application->SetVar('keywords_too_short', 1); return; // if no or too short keyword entered, doing nothing } @@ -2585,10 +2588,6 @@ } } - // keyword string processing - $search_helper = $this->Application->recallObject('SearchHelper'); - /* @var $search_helper kSearchHelper */ - $where_clause = Array (); foreach ($field_list as $field) { if (preg_match('/^' . preg_quote($items_table, '/') . '\.(.*)/', $field, $regs)) { Index: core/units/helpers/search_helper.php =================================================================== --- core/units/helpers/search_helper.php +++ core/units/helpers/search_helper.php @@ -802,4 +802,36 @@ $object->addFilter('includes_filter_h', $includes_or_filter_h, kDBList::HAVING_FILTER); $object->addFilter('excepts_filter_h', $excepts_and_filter_h, kDBList::HAVING_FILTER); } - } \ No newline at end of file + + /** + * Ensures empty search table + * + * @return void + */ + public function ensureEmptySearchTable() + { + $search_table = $this->getSearchTable(); + $this->Conn->Query('DROP TABLE IF EXISTS ' . $search_table); + $sql = 'CREATE TABLE ' . $search_table . ' ( + `Relevance` decimal(8,5) DEFAULT NULL, + `ItemId` int(11) NOT NULL DEFAULT 0, + `ResourceId` int(11) DEFAULT NULL, + `ItemType` int(1) NOT NULL DEFAULT 0, + `EdPick` tinyint(4) NOT NULL DEFAULT 0, + KEY `ResourceId` (`ResourceId`), + KEY `Relevance` (`Relevance`) + )'; + $this->Conn->Query($sql); + } + + /** + * Search table name + * + * @return string + */ + public function getSearchTable() + { + return TABLE_PREFIX . 'ses_' . $this->Application->GetSID() . '_' . TABLE_PREFIX . 'Search'; + } + + }