Index: branches/5.2.x/core/kernel/db/cat_event_handler.php =================================================================== --- branches/5.2.x/core/kernel/db/cat_event_handler.php +++ branches/5.2.x/core/kernel/db/cat_event_handler.php @@ -444,8 +444,11 @@ $object = $event->getObject(); /* @var $object kDBList */ - $search_sql = ' FROM ' . TABLE_PREFIX . 'ses_' . $this->Application->GetSID() . '_' . TABLE_PREFIX . 'Search - search_result JOIN %1$s ON %1$s.ResourceId = search_result.ResourceId'; + /** @var kSearchHelper $search_helper */ + $search_helper = $this->Application->recallObject('SearchHelper'); + + $search_sql = ' FROM ' . $search_helper->getSearchTable() . ' search_result + JOIN %1$s ON %1$s.ResourceId = search_result.ResourceId'; $sql = str_replace('FROM %1$s', $search_sql, $object->GetPlainSelectSQL()); $object->SetSelectSQL($sql); @@ -1105,13 +1108,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 +1128,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 +1245,7 @@ } } - // keyword string processing - $search_helper = $this->Application->recallObject('SearchHelper'); - /* @var $search_helper kSearchHelper */ - + // Keyword string processing. $where_clause = Array (); foreach ($field_list as $field) { if (preg_match('/^' . preg_quote($items_table, '/') . '\.(.*)/', $field, $regs)) { @@ -1393,9 +1396,12 @@ // keep search results from other items after doing a sub-search on current item type $this->Application->SetVar('do_not_drop_search_table', true); - $ids = Array (); - $search_table = TABLE_PREFIX . 'ses_' . $this->Application->GetSID() . '_' . TABLE_PREFIX . 'Search'; + /** @var kSearchHelper $search_helper */ + $search_helper = $this->Application->recallObject('SearchHelper'); + + $search_table = $search_helper->getSearchTable(); $sql = 'SHOW TABLES LIKE "' . $search_table . '"'; + $ids = array(); if ( $this->Conn->Query($sql) ) { $item_type = $this->Application->getUnitOption($event->Prefix, 'ItemType'); @@ -1633,9 +1639,11 @@ } $where_clause .= ' AND '.$items_table.'.Status = 1'; - // building final search query - $search_table = TABLE_PREFIX.'ses_'.$this->Application->GetSID().'_'.TABLE_PREFIX.'Search'; + /** @var kSearchHelper $search_helper */ + $search_helper = $this->Application->recallObject('SearchHelper'); + // Building final search query. + $search_table = $search_helper->getSearchTable(); $this->Conn->Query('DROP TABLE IF EXISTS '.$search_table); $id_field = $this->Application->getUnitOption($event->Prefix, 'IDField'); @@ -1654,7 +1662,7 @@ GROUP BY '.$items_table.'.'.$id_field. $having_clause; - $res = $this->Conn->Query($sql); + $this->Conn->Query($sql); } function getAdvancedSearchCondition($field_name, $record, $keywords, $verbs, &$highlight_keywords) Index: branches/5.2.x/core/kernel/db/cat_tag_processor.php =================================================================== --- branches/5.2.x/core/kernel/db/cat_tag_processor.php +++ branches/5.2.x/core/kernel/db/cat_tag_processor.php @@ -534,7 +534,10 @@ { $object = $this->getObject($params); - $search_results_table = TABLE_PREFIX.'ses_'.$this->Application->GetSID().'_'.TABLE_PREFIX.'Search'; + /** @var kSearchHelper $search_helper */ + $search_helper = $this->Application->recallObject('SearchHelper'); + + $search_results_table = $search_helper->getSearchTable(); $sql = 'SELECT Relevance FROM '.$search_results_table.' WHERE ResourceId = '.$object->GetDBField('ResourceId'); @@ -948,4 +951,4 @@ return $json_helper->encode($categories); } - } \ No newline at end of file + } Index: branches/5.2.x/core/units/categories/categories_event_handler.php =================================================================== --- branches/5.2.x/core/units/categories/categories_event_handler.php +++ branches/5.2.x/core/units/categories/categories_event_handler.php @@ -501,6 +501,9 @@ $type_clauses['menu']['except'] = '%1$s.IsMenu = 0'; $type_clauses['menu']['having_filter'] = false; + /** @var kSearchHelper $search_helper */ + $search_helper = $this->Application->recallObject('SearchHelper'); + if (in_array('search', $types) || in_array('search', $except_types)) { $event_mapping = Array ( 'simple' => 'OnSimpleSearch', @@ -523,8 +526,8 @@ $object = $event->getObject(); /* @var $object kDBList */ - $search_sql = ' FROM ' . TABLE_PREFIX . 'ses_' . $this->Application->GetSID() . '_' . TABLE_PREFIX . 'Search - search_result JOIN %1$s ON %1$s.ResourceId = search_result.ResourceId'; + $search_sql = ' FROM ' . $search_helper->getSearchTable() . ' search_result + JOIN %1$s ON %1$s.ResourceId = search_result.ResourceId'; $sql = str_replace('FROM %1$s', $search_sql, $object->GetPlainSelectSQL()); $object->SetSelectSQL($sql); @@ -536,9 +539,6 @@ $type_clauses['search']['having_filter'] = false; } - $search_helper = $this->Application->recallObject('SearchHelper'); - /* @var $search_helper kSearchHelper */ - $search_helper->SetComplexFilter($event, $type_clauses, implode(',', $types), implode(',', $except_types)); } @@ -2448,13 +2448,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) ) { @@ -2464,7 +2467,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 } @@ -2583,10 +2586,7 @@ } } - // keyword string processing - $search_helper = $this->Application->recallObject('SearchHelper'); - /* @var $search_helper kSearchHelper */ - + // Keyword string processing. $where_clause = Array (); foreach ($field_list as $field) { if (preg_match('/^' . preg_quote($items_table, '/') . '\.(.*)/', $field, $regs)) { @@ -2730,9 +2730,12 @@ // keep search results from other items after doing a sub-search on current item type $this->Application->SetVar('do_not_drop_search_table', true); - $ids = Array (); - $search_table = TABLE_PREFIX . 'ses_' . $this->Application->GetSID() . '_' . TABLE_PREFIX . 'Search'; + /** @var kSearchHelper $search_helper */ + $search_helper = $this->Application->recallObject('SearchHelper'); + + $search_table = $search_helper->getSearchTable(); $sql = 'SHOW TABLES LIKE "' . $search_table . '"'; + $ids = array(); if ( $this->Conn->Query($sql) ) { $item_type = $this->Application->getUnitOption($event->Prefix, 'ItemType'); Index: branches/5.2.x/core/units/categories/categories_tag_processor.php =================================================================== --- branches/5.2.x/core/units/categories/categories_tag_processor.php +++ branches/5.2.x/core/units/categories/categories_tag_processor.php @@ -2180,13 +2180,16 @@ function RelevanceIndicator($params) { + /** @var kDBItem $object */ $object = $this->getObject($params); - /* @var $object kDBItem */ - $search_results_table = TABLE_PREFIX.'ses_'.$this->Application->GetSID().'_'.TABLE_PREFIX.'Search'; + /** @var kSearchHelper $search_helper */ + $search_helper = $this->Application->recallObject('SearchHelper'); + + $search_results_table = $search_helper->getSearchTable(); $sql = 'SELECT Relevance - FROM '.$search_results_table.' - WHERE ResourceId = '.$object->GetDBField('ResourceId'); + FROM ' . $search_results_table . ' + WHERE ResourceId = ' . $object->GetDBField('ResourceId'); $percents_off = (int)(100 - (100 * $this->Conn->GetOne($sql))); $percents_off = ($percents_off < 0) ? 0 : $percents_off; Index: branches/5.2.x/core/units/helpers/search_helper.php =================================================================== --- branches/5.2.x/core/units/helpers/search_helper.php +++ branches/5.2.x/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'; + } + + }