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 1346 Lines • ▼ Show 20 Line(s) | |||||
if ($rel_pop && $object->isField('Hits')) { | if ($rel_pop && $object->isField('Hits')) { | ||||
$relevance_clause .= ' + (Hits + 1) / (MAX(Hits) + 1) * '.$rel_pop; | $relevance_clause .= ' + (Hits + 1) / (MAX(Hits) + 1) * '.$rel_pop; | ||||
} | } | ||||
if ($rel_rating && $object->isField('CachedRating')) { | if ($rel_rating && $object->isField('CachedRating')) { | ||||
$relevance_clause .= ' + (CachedRating + 1) / (MAX(CachedRating) + 1) * '.$rel_rating; | $relevance_clause .= ' + (CachedRating + 1) / (MAX(CachedRating) + 1) * '.$rel_rating; | ||||
} | } | ||||
// building final search query | // building final search query | ||||
$search_table_exists = $this->Conn->Query('SHOW TABLES LIKE "'.$search_table.'"'); | |||||
if (!$this->Application->GetVar('do_not_drop_search_table')) { | 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 | if ( $search_table_exists ) { | ||||
$this->Conn->Query('TRUNCATE TABLE '.$search_table); | |||||
} | |||||
$this->Application->SetVar('do_not_drop_search_table', true); | $this->Application->SetVar('do_not_drop_search_table', true); | ||||
} | } | ||||
$search_table_exists = $this->Conn->Query('SHOW TABLES LIKE "'.$search_table.'"'); | |||||
if ($search_table_exists) { | if ($search_table_exists) { | ||||
$select_intro = 'INSERT INTO '.$search_table.' (Relevance, ItemId, ResourceId, ItemType, EdPick) '; | $select_intro = 'INSERT INTO '.$search_table.' (Relevance, ItemId, ResourceId, ItemType, EdPick) '; | ||||
} | } | ||||
else { | else { | ||||
$select_intro = 'CREATE TABLE '.$search_table.' AS '; | $select_intro = 'CREATE TABLE '.$search_table.' ENGINE = MEMORY AS '; | ||||
} | } | ||||
$edpick_clause = $this->Application->getUnitOption($event->Prefix.'.EditorsPick', 'Fields') ? $items_table.'.EditorsPick' : '0'; | $edpick_clause = $this->Application->getUnitOption($event->Prefix.'.EditorsPick', 'Fields') ? $items_table.'.EditorsPick' : '0'; | ||||
$sql = $select_intro.' SELECT '.$relevance_clause.' AS Relevance, | $sql = $select_intro.' SELECT '.$relevance_clause.' AS Relevance, | ||||
'.$items_table.'.'.$this->Application->getUnitOption($event->Prefix, 'IDField').' AS ItemId, | '.$items_table.'.'.$this->Application->getUnitOption($event->Prefix, 'IDField').' AS ItemId, | ||||
'.$items_table.'.ResourceId, | '.$items_table.'.ResourceId, | ||||
'.$this->Application->getUnitOption($event->Prefix, 'ItemType').' AS ItemType, | '.$this->Application->getUnitOption($event->Prefix, 'ItemType').' AS ItemType, | ||||
▲ Show 20 Lines • Show All 268 Lines • ▼ Show 20 Line(s) | |||||
} | } | ||||
$where_clause .= ' AND '.$items_table.'.Status = 1'; | $where_clause .= ' AND '.$items_table.'.Status = 1'; | ||||
/** @var kSearchHelper $search_helper */ | /** @var kSearchHelper $search_helper */ | ||||
$search_helper = $this->Application->recallObject('SearchHelper'); | $search_helper = $this->Application->recallObject('SearchHelper'); | ||||
// Building final search query. | // Building final search query. | ||||
$search_table = $search_helper->getSearchTable(); | $search_table = $search_helper->getSearchTable(); | ||||
$this->Conn->Query('DROP TABLE IF EXISTS '.$search_table); | $search_table_exists = $this->Conn->Query('SHOW TABLES LIKE "'.$search_table.'"'); | ||||
if ($search_table_exists) { | |||||
$this->Conn->Query('TRUNCATE TABLE '.$search_table); | |||||
$select_intro = 'INSERT INTO '.$search_table.' (Relevance, ItemId, ResourceId, ItemType, EdPick) '; | |||||
} | |||||
else { | |||||
$select_intro = 'CREATE TABLE '.$search_table.' ENGINE = MEMORY AS '; | |||||
} | |||||
$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 = $select_intro.'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; | ||||
$this->Conn->Query($sql); | |||||
if ( !$search_table_exists ) { | |||||
$sql = 'ALTER TABLE ' . $search_table . ' | |||||
ADD INDEX (ResourceId), | |||||
ADD INDEX (Relevance)'; | |||||
$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', | ||||
'contains' => '%s LIKE %s', | 'contains' => '%s LIKE %s', | ||||
▲ Show 20 Lines • Show All 1418 Lines • Show Last 20 Lines |