Index: trunk/kernel/include/searchitems.php =================================================================== diff -u -r1164 -r1165 --- trunk/kernel/include/searchitems.php (.../searchitems.php) (revision 1164) +++ trunk/kernel/include/searchitems.php (.../searchitems.php) (revision 1165) @@ -176,7 +176,7 @@ var $FieldList; var $FieldWeight; var $WhereClauses; - var $ExcludeWhereClause; // excluding all keywords with '-' operator + var $ExcludeWhereClause = Array();// excluding all keywords with '-' operator var $RequireWhereClause = Array(); // requiring all keywords with '+' operator var $SourceTable; var $Relationships; @@ -315,11 +315,12 @@ { if($i>0) { - $or =" AND "; + $or =" OR "; } else $or = ""; - $w .= $or." ".$FieldName." LIKE '%".$required[$i]."%'"; + $w .= $or." ".$FieldName." LIKE '%".$required[$i]."%'"; + $this->RequireWhereClause[$required[$i]][$FieldName] = '('.$FieldName." LIKE '%".$required[$i]."%')"; } } if(strlen($w)>0) @@ -345,6 +346,15 @@ else $or = ""; $w .= $or." ".$FieldName." NOT LIKE '%".$words[$i]."%'"; + $this->ExcludeWhereClause[$words[$i]][$FieldName] = '('.$FieldName." NOT LIKE '%".$words[$i]."%'"; + if (substr($FieldName, 0, strlen(GetTablePrefix())) == GetTablePrefix()) + { + $this->ExcludeWhereClause[$words[$i]][$FieldName] .= ')'; + } + else + { + $this->ExcludeWhereClause[$words[$i]][$FieldName] .= ' OR '.$FieldName.' IS NULL)'; // for custom fields + } } } if(strlen($w)>0) @@ -531,30 +541,51 @@ $where = $normal_where; - if (strlen($this->ExcludeWhereClause)) + if (count($this->ExcludeWhereClause)>0) { - if (strlen($normal_where)) - { - $where .= ' AND '; - } - $where .= $this->ExcludeWhereClause; + foreach ($this->ExcludeWhereClause as $section) + { + foreach ($section as $clause_part) + { + if (strlen($where)) + { + $where .= ' AND '; + } + $where .= '('.$clause_part.')'; + } + } } if (count($this->RequireWhereClause)>0) { - foreach ($this->RequireWhereClause as $clause_part) + $requirewhere .= '('; + foreach ($this->RequireWhereClause as $section) { - if (strlen($normal_where)) - { - $where .= ' AND '; - } - $where .= '('.$clause_part.')'; + $where_add = '('; + foreach ($section as $clause_part) + { + if (strlen($where_add) > 1) + { + $where_add .= ' OR '; + } + $where_add .= $clause_part; + } + $where_add .= ')'; + if (strlen($requirewhere) > 1) $requirewhere .= ' AND '; + $requirewhere .= $where_add; } + $requirewhere .= ')'; + if (strlen($where)) + { + $where .= ' AND '; + } + $where .= $requirewhere; } + if(is_array($idlist)) { - if (strlen($normal_where)) + if (strlen($where)) { $where .= ' AND '; } @@ -771,52 +802,7 @@ } function BuildWhereClause($normal, $required, $notallowed, &$SearchObj) -{ - //global $objSearch, $objLinkSearch, $objTopicSearch, $objNewsSearch; - //$return=""; - //$return = $required; - /* if(strlen($return)>0 && strlen($notallowed)>0) - { - $return .= " AND "; - }*/ - //$return .= $notallowed; - if (strlen($notallowed) && is_object($SearchObj)) - { - $elements = explode('.', $notallowed); // this and below code is to detect if $notallowed clause is concerned custom field or not - if (strpos($elements[0], 'inp')) - { - $or_is_null = ''; - } - else - { - $or_is_null = ' OR '.substr($notallowed, 1, strpos($notallowed, 'NOT') - 1).' IS NULL '; - } - if (!strlen($SearchObj->ExcludeWhereClause)) - { - $SearchObj->ExcludeWhereClause = '('.$notallowed.$or_is_null.')'; - } - else - { - $SearchObj->ExcludeWhereClause .= ' AND ('.$notallowed.$or_is_null.')'; - } - } - - if (strlen($required) && is_object($SearchObj)) - { - $keyword = substr($required, strpos($required,'LIKE') + 5); - if (!strlen($SearchObj->RequireWhereClause[$keyword])) - { - $SearchObj->RequireWhereClause[$keyword] = $required; - } - else - { - $SearchObj->RequireWhereClause[$keyword] .= ' OR '.$required; - } - } - /*if(strlen($return)>0 && strlen($normal)>0) - { - $return .= " AND "; - }*/ +{ return $normal; }