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)