Index: trunk/core/units/config_search/config_search_event_handler.php =================================================================== diff -u -N -r4052 -r4084 --- trunk/core/units/config_search/config_search_event_handler.php (.../config_search_event_handler.php) (revision 4052) +++ trunk/core/units/config_search/config_search_event_handler.php (.../config_search_event_handler.php) (revision 4084) @@ -54,6 +54,10 @@ function OnCreateCustomField(&$event) { $custom_field =& $event->MasterEvent->getObject(); + if ($custom_field->GetDBField('Type') == 6) { + // user custom fields are not searchable + return false; + } $sql = 'SELECT Module FROM '.TABLE_PREFIX.'ItemTypes Index: trunk/kernel/include/advsearch.php =================================================================== diff -u -N -r3282 -r4084 --- trunk/kernel/include/advsearch.php (.../advsearch.php) (revision 3282) +++ trunk/kernel/include/advsearch.php (.../advsearch.php) (revision 4084) @@ -89,109 +89,136 @@ $this->keywords = GetKeywords($keywords); } - function AddAdvancedField($TableName,$FieldName,$Verb,$Value,$conj) + function AddAdvancedField($TableName,$FieldName,$Verb,$Value,$conj, $main_prefix) { global $objSearchConfig, $objConfig; - static $x = 0; + static $x = 0, $customs_joined = Array(); if(!is_object($objSearchConfig)) $objSearchConfig = new clsSeachConfigList(); - if ($TableName==GetTablePrefix().'CustomField') - { + if ($TableName == GetTablePrefix().'CustomField') { + // stupid custom fields already have prefix in SearchConfig table (not for in-commerce module :D) $prefix = ''; } - else - { + else { $prefix = GetTablePrefix(); } $f = $prefix.$TableName.".".$FieldName; $FieldConfig = $objSearchConfig->GetItemByName($TableName,$FieldName); - if(is_object($FieldConfig)) + if(!is_object($FieldConfig)) { + return false; + } + + if ($FieldConfig->Get('ForeignField')) { + $x++; + $parts = explode(".",$FieldConfig->Get("ForeignField")); + $Table = $parts[0]; + $pseudo = 'c'.$x; + $Table = AddTablePrefix($Table); + $Field = $parts[1]; + $join = $FieldConfig->Get("JoinClause"); + $join = str_replace($Table, $pseudo, $join); + $join = str_replace("{ForeignTable}", $pseudo, $join); + $join = str_replace("{LocalTable}", $TableName, $join); + $join = str_replace("{Table}", AddTablePrefix($this->SourceTable), $join); + $join = '('.$join.' AND '.$pseudo.'.CustomFieldId='.$FieldConfig->Get('CustomFieldId').')'; + $this->AddRelationship($Table.' AS '.$pseudo, $join); + + // for items that does not have appropriate records in CustomMetaData table + if ($Verb == 'notcontains' || $Verb == 'isnot') + { + $or_not_null = ' OR '.$pseudo.'.'.$Field.' IS NULL'; + } + else + { + $or_not_null = ''; + } + + $FieldItem["where"] = str_replace('CustomMetaData', $pseudo, $FieldConfig->GetWhereClause($Verb,$Value)).$or_not_null; + $FieldItem["Field"] = $FieldConfig->Get("ForeignField"); + $FieldItem["Table"] = $pseudo; + $FieldItem["conjuction"] = $conj; + $FieldItem["weight"] = $FieldConfig->Get("Priority"); + } + else { - if(strlen($FieldConfig->Get("ForeignField"))>0) - { - $x++; - $parts = explode(".",$FieldConfig->Get("ForeignField")); - $Table = $parts[0]; - $pseudo = 'c'.$x; - $Table = AddTablePrefix($Table); - $Field = $parts[1]; - $join = $FieldConfig->Get("JoinClause"); - $join = str_replace($Table, $pseudo, $join); - $join = str_replace("{ForeignTable}", $pseudo, $join); - $join = str_replace("{LocalTable}", $TableName, $join); - $join = str_replace("{Table}", AddTablePrefix($this->SourceTable), $join); - $join = '('.$join.' AND '.$pseudo.'.CustomFieldId='.$FieldConfig->Get('CustomFieldId').')'; - $this->AddRelationship($Table.' AS '.$pseudo, $join); - - // for items that does not have appropriate records in CustomMetaData table - if ($Verb == 'notcontains' || $Verb == 'isnot') - { - $or_not_null = ' OR '.$pseudo.'.'.$Field.' IS NULL'; - } - else - { - $or_not_null = ''; - } - - $FieldItem["where"] = str_replace('CustomMetaData', $pseudo, $FieldConfig->GetWhereClause($Verb,$Value)).$or_not_null; - $FieldItem["Field"] = $FieldConfig->Get("ForeignField"); - $FieldItem["Table"] = $pseudo; - $FieldItem["conjuction"] = $conj; - $FieldItem["weight"] = $FieldConfig->Get("Priority"); - } - else - { - $classes = Array( 'Link' => '_clsLinkList', - 'News' => '_clsNewsList', - 'Topic' => '_clsTopicList', - 'Category' => 'clsCatList'); - $list_class = $classes[$TableName]; - $objList =& new $list_class(); - switch ($FieldName) - { - case 'HotItem': - $cutoff = $objList->GetHotValue(); - $Value == 1 ? $not = '' : $not = 'NOT '; - $where_clause = $FieldConfig->GetWhereClause($Verb, $Value); - $where_clause .= ' OR ('.AddTablePrefix($TableName).'.HotItem=2 AND '. - $not.'('.AddTablePrefix($TableName). - '.Hits>='.$cutoff.'))'; - break; - case 'PopItem': - $cutoff = $objList->GetPopValue(); - $Value == 1 ? $not = '' : $not = 'NOT '; - $where_clause = $FieldConfig->GetWhereClause($Verb, $Value); - $where_clause .= ' OR ('.AddTablePrefix($TableName).'.PopItem=2 AND '. - $not.'('.AddTablePrefix($TableName). - '.CachedRating>='.$cutoff.'))'; - break; - case 'NewItem': - $NewTime = $objConfig->Get($TableName.'_NewDays')*3600*24; - $Value == 1 ? $not = '' : $not = 'NOT '; - $where_clause = $FieldConfig->GetWhereClause($Verb, $Value); - $where_clause .= ' OR ('.AddTablePrefix($TableName).'.NewItem=2 AND '. - $not.'('.adodb_mktime().'-'.AddTablePrefix($TableName). - '.CreatedOn<'.$NewTime.'))'; - break; - default: - $where_clause = $FieldConfig->GetWhereClause($Verb, $Value); - } - $FieldItem = array(); - $FieldItem['Table'] = AddTablePrefix($TableName); - $FieldItem['Field'] = $FieldName; - $FieldItem['where'] = $FieldItem['Table'].'.'.$where_clause; - $FieldItem['conjuction'] = $conj; - $FieldItem['weight'] = $FieldConfig->Get('Priority'); - } - $this->FieldList[] = $FieldItem; - - unset($FieldItem); - } + $classes = Array( 'Link' => '_clsLinkList', + 'News' => '_clsNewsList', + 'Topic' => '_clsTopicList', + 'Category' => 'clsCatList'); + $list_class = getArrayValue($classes, $TableName); + if ($list_class) { + $objList =& new $list_class(); + } + + if ($FieldConfig->Get('CustomFieldId')) { + $ml_formatter =& $this->Application->recallObject('kMultiLanguage'); + $FieldConfig->Set('FieldName', $ml_formatter->LangFieldName('cust_'.$FieldConfig->Get('CustomFieldId'))); + } + + switch ($FieldName) + { + case 'HotItem': + $cutoff = $objList->GetHotValue(); + $Value == 1 ? $not = '' : $not = 'NOT '; + $where_clause = $FieldConfig->GetWhereClause($Verb, $Value); + $where_clause .= ' OR ('.AddTablePrefix($TableName).'.HotItem=2 AND '. + $not.'('.AddTablePrefix($TableName). + '.Hits>='.$cutoff.'))'; + break; + case 'PopItem': + $cutoff = $objList->GetPopValue(); + $Value == 1 ? $not = '' : $not = 'NOT '; + $where_clause = $FieldConfig->GetWhereClause($Verb, $Value); + $where_clause .= ' OR ('.AddTablePrefix($TableName).'.PopItem=2 AND '. + $not.'('.AddTablePrefix($TableName). + '.CachedRating>='.$cutoff.'))'; + break; + case 'NewItem': + $NewTime = $objConfig->Get($TableName.'_NewDays')*3600*24; + $Value == 1 ? $not = '' : $not = 'NOT '; + $where_clause = $FieldConfig->GetWhereClause($Verb, $Value); + $where_clause .= ' OR ('.AddTablePrefix($TableName).'.NewItem=2 AND '. + $not.'('.adodb_mktime().'-'.AddTablePrefix($TableName). + '.CreatedOn<'.$NewTime.'))'; + break; + default: + $where_clause = $FieldConfig->GetWhereClause($Verb, $Value); + break; + } + + $FieldItem = Array(); + if ($FieldConfig->Get('CustomFieldId')) { + if (!getArrayValue($customs_joined, $main_prefix)) { + $item_table = $this->Application->getUnitOption($main_prefix, 'TableName'); + $custom_table = $this->Application->getUnitOption($main_prefix.'-cdata', 'TableName'); + $this->AddRelationship($custom_table.' AS '.$main_prefix.'_custom_data', $main_prefix.'_custom_data.ResourceId = '.$item_table.'.ResourceId'); + $customs_joined[$main_prefix] = true; + } + + $FieldItem['Table'] = $main_prefix.'_custom_data'; + $FieldItem['Field'] = $FieldConfig->Get('FieldName'); + } + else { + $FieldItem['Table'] = AddTablePrefix($TableName); + $FieldItem['Field'] = $FieldName; + } + + $FieldItem['where'] = $FieldItem['Table'].'.'.$where_clause; + $FieldItem['conjuction'] = $conj; + $FieldItem['weight'] = $FieldConfig->Get('Priority'); + + + } + $this->FieldList[] = $FieldItem; + + unset($FieldItem); + } + /* function AddAdvancedCustomFields() { Index: trunk/kernel/frontaction.php =================================================================== diff -u -N -r4077 -r4084 --- trunk/kernel/frontaction.php (.../frontaction.php) (revision 4077) +++ trunk/kernel/frontaction.php (.../frontaction.php) (revision 4084) @@ -954,7 +954,7 @@ $objSearchList->UpdateKeyword($keywords,0); $objSearch->SetKeywords($keywords); - $objSearch->AddSimpleFields(); + $objSearch->AddSimpleFields('c'); if (is_numeric($objConfig->Get("SearchRel_Pop_category"))) { $objSearch->PctPop = ($objConfig->Get("SearchRel_Pop_category")/100); } @@ -993,17 +993,16 @@ break; case "m_adv_search": - if ($_GET['type']) - { + if ($_GET['type']) { $modules = Array( 1 => 'In-Portal', 2 => 'In-News', 3 => 'In-Bulletin', 4 => 'In-Link', 11 => 'In-Commerce'); $module = $modules[$_GET["type"]]; } - else - { + else { $module = 0; } + if( !is_object($objSearchConfig) ) $objSearchConfig = new clsSearchConfigList($module); switch($_GET["type"]) { @@ -1049,7 +1048,7 @@ if(strlen($Value) && strlen($Verb)>0 && $Verb!="any") { //echo "Adding CAT SearchField: [".$field->Get("TableName")."]; [".$field->Get("FieldName")."]; [$Verb]; [$Value]; [$Conjuction]
"; - $objAdvSearch->AddAdvancedField($field->Get("TableName"),$field->Get("FieldName"),$Verb,$Value,$Conjuction); + $objAdvSearch->AddAdvancedField($field->Get("TableName"),$field->Get("FieldName"),$Verb,$Value,$Conjuction, 'c'); } } @@ -1098,7 +1097,7 @@ $objSearchList->UpdateKeyword($keywords,0); $objSearch->SetKeywords($keywords); - $objSearch->AddSimpleFields(); + $objSearch->AddSimpleFields('c'); if (is_numeric($objConfig->Get("SearchRel_Pop_category"))) { $objSearch->PctPop = ($objConfig->Get("SearchRel_Pop_category")/100); } Index: trunk/kernel/units/config_search/config_search_event_handler.php =================================================================== diff -u -N -r4052 -r4084 --- trunk/kernel/units/config_search/config_search_event_handler.php (.../config_search_event_handler.php) (revision 4052) +++ trunk/kernel/units/config_search/config_search_event_handler.php (.../config_search_event_handler.php) (revision 4084) @@ -54,6 +54,10 @@ function OnCreateCustomField(&$event) { $custom_field =& $event->MasterEvent->getObject(); + if ($custom_field->GetDBField('Type') == 6) { + // user custom fields are not searchable + return false; + } $sql = 'SELECT Module FROM '.TABLE_PREFIX.'ItemTypes Index: trunk/kernel/include/searchitems.php =================================================================== diff -u -N -r4052 -r4084 --- trunk/kernel/include/searchitems.php (.../searchitems.php) (revision 4052) +++ trunk/kernel/include/searchitems.php (.../searchitems.php) (revision 4084) @@ -248,39 +248,34 @@ $this->keywords = GetKeywords($keywords); } - function AddSimpleCustomFields() + function AddSimpleCustomFields($main_prefix) { $table_to_module = Array( 'Category' => 'In-Portal', 'Link' => 'In-Link', 'Topic' => 'In-Bulletin', 'PortalUser' => 'In-Portal', 'News' => 'In-News'); $module = $table_to_module[$this->SourceTable]; - $sql = "SELECT * FROM ".GetTablePrefix()."SearchConfig WHERE ModuleName='".$module."' AND SimpleSearch=1 AND CustomFieldId>0"; - //$sql = "SELECT * FROM ".GetTablePrefix()."SearchConfig WHERE TableName='".$this->SourceTable."' AND SimpleSearch=1 AND CustomFieldId>0"; - //echo $sql; - foreach($this->Relationships as $Table=>$clause) - { - if(strlen($Table)>0 && $Table != "Category") - $sql .= " OR TableName='".$Table."'"; + + $sql = 'SELECT Priority, CustomFieldId FROM '.TABLE_PREFIX.'SearchConfig + WHERE ModuleName = '.$this->Conn->qstr($module).' AND SimpleSearch = 1 AND CustomFieldId > 0'; + + $search_config = $this->Conn->GetCol($sql, 'CustomFieldId'); + if ($search_config) { + $item_table = $this->Application->getUnitOption($main_prefix, 'TableName'); + $custom_table = $this->Application->getUnitOption($main_prefix.'-cdata', 'TableName'); + $this->AddRelationship($custom_table.' AS '.$main_prefix.'_custom_data', $main_prefix.'_custom_data.ResourceId = '.$item_table.'.ResourceId'); + + $ml_formatter =& $this->Application->recallObject('kMultiLanguage'); + foreach ($search_config as $custom_id => $custom_priority) { + $field_name = $main_prefix.'_custom_data.'.$ml_formatter->LangFieldName('cust_'.$custom_id); + $this->FieldList[] = $field_name; + $this->FieldWeight[$field_name] = $custom_priority; + } } - $ctable = GetTablePrefix()."CustomMetaData"; - $rs = $this->adodbConnection->Execute($sql); - $CustomJoined = FALSE; - while($rs && !$rs->EOF) - { - $x = $rs->fields["CustomFieldId"]; - $t = $ctable." as c".$x; - $join = "(c$x.ResourceId=".GetTablePrefix().$this->SourceTable.".ResourceId AND c$x.CustomFieldId=".$rs->fields["CustomFieldId"].")"; - $this->AddRelationship($t,$join); - $f = "c".$x.".Value "; - $this->FieldList[] = $f; - $this->FieldWeight[$f] = $rs->fields["Priority"]; - $rs->MoveNext(); - } } - function AddSimpleFields() + function AddSimpleFields($main_prefix) { $sql = "SELECT * FROM ".GetTablePrefix()."SearchConfig WHERE TableName='".$this->SourceTable."' AND SimpleSearch=1 AND CustomFieldId IS NULL"; //echo $sql; @@ -298,7 +293,7 @@ $this->FieldWeight[$f] = $rs->fields["Priority"]; $rs->MoveNext(); } - $this->AddSimpleCustomFields(); + $this->AddSimpleCustomFields($main_prefix); } function AddSearchWhereClause($FieldName)