Index: trunk/core/units/general/cat_event_handler.php =================================================================== diff -u -N -r6093 -r6428 --- trunk/core/units/general/cat_event_handler.php (.../cat_event_handler.php) (revision 6093) +++ trunk/core/units/general/cat_event_handler.php (.../cat_event_handler.php) (revision 6428) @@ -376,8 +376,6 @@ $excepts_and_filter_h =& $this->Application->makeClass('kMultipleFilter'); $excepts_and_filter_h->setType(FLT_TYPE_AND); - $except_types_array = explode(',', $types); - if ($types) { $types_array = explode(',', $types); for ($i = 0; $i < sizeof($types_array); $i++) { @@ -681,10 +679,11 @@ $object =& $event->getObject(); $this->Application->SetVar($event->getPrefixSpecial().'_Page', 1); $lang = $this->Application->GetVar('m_lang'); - $product_table = $this->Application->getUnitOption('p', 'TableName'); + $items_table = $this->Application->getUnitOption($event->Prefix, 'TableName'); + $module_name = $this->Application->findModule('Var', $event->Prefix, 'Name'); $sql = ' SELECT * FROM '.$this->Application->getUnitOption('confs', 'TableName').' - WHERE ModuleName="In-Commerce" + WHERE ModuleName="'.$module_name.'" AND SimpleSearch=1'; $search_config = $this->Conn->Query($sql, 'FieldName'); $field_list = array_keys($search_config); @@ -699,7 +698,7 @@ $custom_fields = $this->Application->getUnitOption($event->Prefix, 'CustomFields'); if ($custom_fields) { $custom_table = $this->Application->getUnitOption($event->Prefix.'-cdata', 'TableName'); - $join_clauses[] = ' LEFT JOIN '.$custom_table.' custom_data ON '.$product_table.'.ResourceId = custom_data.ResourceId'; + $join_clauses[] = ' LEFT JOIN '.$custom_table.' custom_data ON '.$items_table.'.ResourceId = custom_data.ResourceId'; } // what field in search config becomes what field in sql (key - new field, value - old field (from searchconfig table)) @@ -740,17 +739,31 @@ } else { + $multi_lingual = false; + if ($exploded[0] == 'MULTI') + { + $multi_lingual = true; + $foreign_field = $exploded[1]; + } $exploded = explode('.', $foreign_field); // format: table.field_name $foreign_table = TABLE_PREFIX.$exploded[0]; $alias_counter++; $alias = 't'.$alias_counter; - $field_list[$key] = $alias.'.'.$exploded[1]; - $search_config_map[ $field_list[$key] ] = $field; + if ($multi_lingual) { + $field_list[$key] = $alias.'.'.'l'.$lang.'_'.$exploded[1]; + $field_list[$key.'_primary'] = 'l'.$this->Application->GetDefaultLanguageId().'_'.$field; + $search_config_map[ $field_list[$key] ] = $field; + $search_config_map[ $field_list[$key.'_primary'] ] = $field; + } + else { + $field_list[$key] = $alias.'.'.$exploded[1]; + $search_config_map[ $field_list[$key] ] = $field; + } $join_clause = str_replace('{ForeignTable}', $alias, $search_config[$field]['JoinClause']); - $join_clause = str_replace('{LocalTable}', $product_table, $join_clause); + $join_clause = str_replace('{LocalTable}', $items_table, $join_clause); $join_clauses[] = ' LEFT JOIN '.$foreign_table.' '.$alias.' ON '.$join_clause; @@ -771,20 +784,20 @@ $search_helper =& $this->Application->recallObject('SearchHelper'); $where_clause = $search_helper->buildWhereClause($keywords, $field_list); - $where_clause = $where_clause.' AND '.$product_table.'.Status=1'; + $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 '.$product_table.'.ResourceId IN ('.implode(',', $event->specificParams['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') ) { - $where_clause .= ' AND '.$product_table.'.ResourceId IN ('.implode(',', $event->MasterEvent->getEventParam('ResultIds')).')'; + $where_clause .= ' AND '.$items_table.'.ResourceId IN ('.implode(',', $event->MasterEvent->getEventParam('ResultIds')).')'; } } @@ -801,34 +814,45 @@ $revelance_parts[] = 'IF('.$field.' LIKE "%'.$keyword.'%", '.$weight.', 0)'; } } - $rel_keywords = $this->Application->ConfigValue('SearchRel_Keyword_products') / 100; - $rel_pop = $this->Application->ConfigValue('SearchRel_Pop_products') / 100; - $rel_rating = $this->Application->ConfigValue('SearchRel_Rating_products') / 100; + $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; + $rel_rating = $this->Application->ConfigValue('SearchRel_Rating_'.$conf_postfix) / 100; $relevance_clause = '('.implode(' + ', $revelance_parts).') / '.$weight_sum.' * '.$rel_keywords; - $relevance_clause .= ' + (Hits + 1) / (MAX(Hits) + 1) * '.$rel_pop; - $relevance_clause .= ' + (CachedRating + 1) / (MAX(CachedRating) + 1) * '.$rel_rating; + if ($rel_pop && isset($object->Fields['Hits'])) { + $relevance_clause .= ' + (Hits + 1) / (MAX(Hits) + 1) * '.$rel_pop; + } + if ($rel_rating && isset($object->Fields['CachedRating'])) { + $relevance_clause .= ' + (CachedRating + 1) / (MAX(CachedRating) + 1) * '.$rel_rating; + } // building final search query - if (!$this->Application->GetVar('INPORTAL_ON')) { + if (!$this->Application->GetVar('do_not_drop_search_table') && !$this->Application->GetVar('INPORTAL_ON')) { $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); } - if ($this->Conn->Query('SHOW TABLES LIKE "'.$search_table.'"')) { + + $search_table_exists = $this->Conn->Query('SHOW TABLES LIKE "'.$search_table.'"'); + if ($search_table_exists) { $select_intro = 'INSERT INTO '.$search_table.' (Relevance, ItemId, ResourceId, ItemType, EdPick) '; } else { $select_intro = 'CREATE TABLE '.$search_table.' AS '; } + $edpick_clause = $this->Application->getUnitOption($event->Prefix.'.EditorsPick', 'Fields') ? $items_table.'.EditorsPick' : '0'; + + $sql = $select_intro.' SELECT '.$relevance_clause.' AS Relevance, - '.$product_table.'.ProductId AS ItemId, - '.$product_table.'.ResourceId, - 11 AS ItemType, - '.$product_table.'.EditorsPick AS EdPick + '.$items_table.'.'.$this->Application->getUnitOption($event->Prefix, 'IDField').' AS ItemId, + '.$items_table.'.ResourceId, + '.$this->Application->getUnitOption($event->Prefix, 'ItemType').' AS ItemType, + '.$edpick_clause.' AS EdPick FROM '.$object->TableName.' '.implode(' ', $join_clauses).' WHERE '.$where_clause.' - GROUP BY '.$product_table.'.ProductId'; + GROUP BY '.$items_table.'.'.$this->Application->getUnitOption($event->Prefix, 'IDField'); $res = $this->Conn->Query($sql); } @@ -1887,7 +1911,6 @@ } } } - } ?> \ No newline at end of file