Changeset View
Changeset View
Standalone View
Standalone View
branches/5.2.x/core/kernel/db/cat_event_handler.php
Show First 20 Lines • Show All 438 Lines • ▼ Show 20 Line(s) | |||||
} | } | ||||
$search_event = $event_mapping[$type]; | $search_event = $event_mapping[$type]; | ||||
$this->$search_event($event); | $this->$search_event($event); | ||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object kDBList */ | /* @var $object kDBList */ | ||||
$search_sql = ' FROM ' . TABLE_PREFIX . 'ses_' . $this->Application->GetSID() . '_' . TABLE_PREFIX . 'Search | /** @var kSearchHelper $search_helper */ | ||||
search_result JOIN %1$s ON %1$s.ResourceId = search_result.ResourceId'; | $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()); | $sql = str_replace('FROM %1$s', $search_sql, $object->GetPlainSelectSQL()); | ||||
$object->SetSelectSQL($sql); | $object->SetSelectSQL($sql); | ||||
$object->addCalculatedField('Relevance', 'search_result.Relevance'); | $object->addCalculatedField('Relevance', 'search_result.Relevance'); | ||||
$type_clauses['search']['include'] = 'PrimaryCat = 1 AND ('.TABLE_PREFIX.'Categories.Status = '.STATUS_ACTIVE.')'; | $type_clauses['search']['include'] = 'PrimaryCat = 1 AND ('.TABLE_PREFIX.'Categories.Status = '.STATUS_ACTIVE.')'; | ||||
$type_clauses['search']['except'] = 'PrimaryCat = 1 AND ('.TABLE_PREFIX.'Categories.Status = '.STATUS_ACTIVE.')'; | $type_clauses['search']['except'] = 'PrimaryCat = 1 AND ('.TABLE_PREFIX.'Categories.Status = '.STATUS_ACTIVE.')'; | ||||
▲ Show 20 Lines • Show All 643 Lines • ▼ Show 20 Line(s) | |||||
* Makes simple search for category items | * Makes simple search for category items | ||||
* based on keywords string | * based on keywords string | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
*/ | */ | ||||
function OnSimpleSearch($event) | function OnSimpleSearch($event) | ||||
{ | { | ||||
$event->redirect = false; | $event->redirect = false; | ||||
$search_table = TABLE_PREFIX.'ses_'.$this->Application->GetSID().'_'.TABLE_PREFIX.'Search'; | |||||
$keywords = $this->Application->unescapeRequestVariable(trim($this->Application->GetVar('keywords'))); | $keywords = $this->Application->unescapeRequestVariable(trim($this->Application->GetVar('keywords'))); | ||||
$query_object = $this->Application->recallObject('HTTPQuery'); | $query_object = $this->Application->recallObject('HTTPQuery'); | ||||
/* @var $query_object kHTTPQuery */ | /* @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.'"'; | $sql = 'SHOW TABLES LIKE "'.$search_table.'"'; | ||||
if(!isset($query_object->Get['keywords']) && | if(!isset($query_object->Get['keywords']) && | ||||
!isset($query_object->Post['keywords']) && | !isset($query_object->Post['keywords']) && | ||||
$this->Conn->Query($sql)) | $this->Conn->Query($sql)) | ||||
{ | { | ||||
return; // used when navigating by pages or changing sorting in search results | return; // used when navigating by pages or changing sorting in search results | ||||
} | } | ||||
if(!$keywords || strlen($keywords) < $this->Application->ConfigValue('Search_MinKeyword_Length')) | 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); | $this->Application->SetVar('keywords_too_short', 1); | ||||
return; // if no or too short keyword entered, doing nothing | return; // if no or too short keyword entered, doing nothing | ||||
} | } | ||||
$this->Application->StoreVar('keywords', $keywords); | $this->Application->StoreVar('keywords', $keywords); | ||||
$this->saveToSearchLog($keywords, 0); // 0 - simple search, 1 - advanced search | $this->saveToSearchLog($keywords, 0); // 0 - simple search, 1 - advanced search | ||||
▲ Show 20 Lines • Show All 100 Lines • ▼ Show 20 Line(s) | |||||
$search_config_map[ $field_list[$key.'_primary'] ] = $field; | $search_config_map[ $field_list[$key.'_primary'] ] = $field; | ||||
} | } | ||||
$field_list[$key] = $local_table.'.'.$field_list[$key]; | $field_list[$key] = $local_table.'.'.$field_list[$key]; | ||||
$search_config_map[ $field_list[$key] ] = $field; | $search_config_map[ $field_list[$key] ] = $field; | ||||
} | } | ||||
} | } | ||||
// keyword string processing | // Keyword string processing. | ||||
$search_helper = $this->Application->recallObject('SearchHelper'); | |||||
/* @var $search_helper kSearchHelper */ | |||||
$where_clause = Array (); | $where_clause = Array (); | ||||
foreach ($field_list as $field) { | foreach ($field_list as $field) { | ||||
if (preg_match('/^' . preg_quote($items_table, '/') . '\.(.*)/', $field, $regs)) { | if (preg_match('/^' . preg_quote($items_table, '/') . '\.(.*)/', $field, $regs)) { | ||||
// local real field | // local real field | ||||
$filter_data = $search_helper->getSearchClause($object, $regs[1], $keywords, false); | $filter_data = $search_helper->getSearchClause($object, $regs[1], $keywords, false); | ||||
if ($filter_data) { | if ($filter_data) { | ||||
$where_clause[] = $filter_data['value']; | $where_clause[] = $filter_data['value']; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 134 Lines • ▼ Show 20 Line(s) | |||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
*/ | */ | ||||
function OnSubSearch($event) | function OnSubSearch($event) | ||||
{ | { | ||||
// keep search results from other items after doing a sub-search on current item type | // keep search results from other items after doing a sub-search on current item type | ||||
$this->Application->SetVar('do_not_drop_search_table', true); | $this->Application->SetVar('do_not_drop_search_table', true); | ||||
$ids = Array (); | /** @var kSearchHelper $search_helper */ | ||||
$search_table = TABLE_PREFIX . 'ses_' . $this->Application->GetSID() . '_' . TABLE_PREFIX . 'Search'; | $search_helper = $this->Application->recallObject('SearchHelper'); | ||||
$search_table = $search_helper->getSearchTable(); | |||||
$sql = 'SHOW TABLES LIKE "' . $search_table . '"'; | $sql = 'SHOW TABLES LIKE "' . $search_table . '"'; | ||||
$ids = array(); | |||||
if ( $this->Conn->Query($sql) ) { | if ( $this->Conn->Query($sql) ) { | ||||
$item_type = $this->Application->getUnitOption($event->Prefix, 'ItemType'); | $item_type = $this->Application->getUnitOption($event->Prefix, 'ItemType'); | ||||
// 1. get ids to be used as search bounds | // 1. get ids to be used as search bounds | ||||
$sql = 'SELECT DISTINCT ResourceId | $sql = 'SELECT DISTINCT ResourceId | ||||
FROM ' . $search_table . ' | FROM ' . $search_table . ' | ||||
WHERE ItemType = ' . $item_type; | WHERE ItemType = ' . $item_type; | ||||
▲ Show 20 Lines • Show All 221 Lines • ▼ Show 20 Line(s) | |||||
else | else | ||||
{ | { | ||||
$where_clause = '0'; | $where_clause = '0'; | ||||
$this->Application->SetVar('adv_search_error', 1); | $this->Application->SetVar('adv_search_error', 1); | ||||
} | } | ||||
} | } | ||||
$where_clause .= ' AND '.$items_table.'.Status = 1'; | $where_clause .= ' AND '.$items_table.'.Status = 1'; | ||||
// building final search query | /** @var kSearchHelper $search_helper */ | ||||
$search_table = TABLE_PREFIX.'ses_'.$this->Application->GetSID().'_'.TABLE_PREFIX.'Search'; | $search_helper = $this->Application->recallObject('SearchHelper'); | ||||
// Building final search query. | |||||
$search_table = $search_helper->getSearchTable(); | |||||
$this->Conn->Query('DROP TABLE IF EXISTS '.$search_table); | $this->Conn->Query('DROP TABLE IF EXISTS '.$search_table); | ||||
$id_field = $this->Application->getUnitOption($event->Prefix, 'IDField'); | $id_field = $this->Application->getUnitOption($event->Prefix, 'IDField'); | ||||
$fields = $this->Application->getUnitOption($event->Prefix, 'Fields'); | $fields = $this->Application->getUnitOption($event->Prefix, 'Fields'); | ||||
$pick_field = isset($fields['EditorsPick']) ? $items_table.'.EditorsPick' : '0'; | $pick_field = isset($fields['EditorsPick']) ? $items_table.'.EditorsPick' : '0'; | ||||
$sql = ' CREATE TABLE '.$search_table.' | $sql = ' CREATE TABLE '.$search_table.' | ||||
SELECT '.$relevance_clause.' AS Relevance, | SELECT '.$relevance_clause.' AS Relevance, | ||||
'.$items_table.'.'.$id_field.' AS ItemId, | '.$items_table.'.'.$id_field.' AS ItemId, | ||||
'.$items_table.'.ResourceId AS ResourceId, | '.$items_table.'.ResourceId AS ResourceId, | ||||
11 AS ItemType, | 11 AS ItemType, | ||||
'.$pick_field.' AS EdPick | '.$pick_field.' AS EdPick | ||||
FROM '.$items_table.' | FROM '.$items_table.' | ||||
'.implode(' ', $join_clauses).' | '.implode(' ', $join_clauses).' | ||||
WHERE '.$where_clause.' | WHERE '.$where_clause.' | ||||
GROUP BY '.$items_table.'.'.$id_field. | GROUP BY '.$items_table.'.'.$id_field. | ||||
$having_clause; | $having_clause; | ||||
$res = $this->Conn->Query($sql); | $this->Conn->Query($sql); | ||||
} | } | ||||
function getAdvancedSearchCondition($field_name, $record, $keywords, $verbs, &$highlight_keywords) | function getAdvancedSearchCondition($field_name, $record, $keywords, $verbs, &$highlight_keywords) | ||||
{ | { | ||||
$field = $record['FieldName']; | $field = $record['FieldName']; | ||||
$condition_patterns = Array ( | $condition_patterns = Array ( | ||||
'any' => '%s LIKE %s', | 'any' => '%s LIKE %s', | ||||
▲ Show 20 Lines • Show All 1426 Lines • Show Last 20 Lines |