Index: trunk/kernel/include/searchitems.php =================================================================== diff -u -r1124 -r1155 --- trunk/kernel/include/searchitems.php (.../searchitems.php) (revision 1124) +++ trunk/kernel/include/searchitems.php (.../searchitems.php) (revision 1155) @@ -176,6 +176,8 @@ var $FieldList; var $FieldWeight; var $WhereClauses; + var $ExcludeWhereClause; // excluding all keywords with '-' operator + var $RequireWhereClause = Array(); // requiring all keywords with '+' operator var $SourceTable; var $Relationships; var $Ignored_Words; @@ -393,8 +395,11 @@ $where = ""; } - $complete= BuildWhereClause($where,$req_where,$not_where); - $this->WhereClauses[$FieldName]="(".$complete.")"; + $complete = BuildWhereClause($where, $req_where, $not_where, &$this); + if ($complete) + { + $this->WhereClauses[$FieldName]="(".$complete.")"; + } $this->Ignored_Words=$this->keywords["ignored"]; } @@ -517,6 +522,19 @@ $SelectSQL .= implode(" or ",$this->WhereClauses); $SelectSQL .= ")"; + if (strlen($this->ExcludeWhereClause)) + { + $SelectSQL .= ' AND '.$this->ExcludeWhereClause; + } + + if (count($this->RequireWhereClause)>0) + { + foreach ($this->RequireWhereClause as $clause_part) + { + $SelectSQL .= ' AND ('.$clause_part.')'; + } + } + if(is_array($idlist)) { $SelectSQL .= " AND (".$this->SourceTable.".ResourceId IN (".implode(",",$idlist)."))"; @@ -627,15 +645,15 @@ } break; - case "+": + case '+': if(strlen($exact_word)==0) { $token = "+"; } else $exact_word .= "+"; break; - case "-": + case '-': if(strlen($exact_word)==0) { $token = "-"; @@ -724,23 +742,46 @@ return($keywords); } -function BuildWhereClause($normal,$required,$notallowed) +function BuildWhereClause($normal, $required, $notallowed, &$SearchObj) { - $return=""; - - $return = $required; - - if(strlen($return)>0 && strlen($notallowed)>0) + //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)) + { + $or_is_null = ' OR '.substr($notallowed, 0, strpos($notallowed, 'NOT')).' IS NULL '; + if (!strlen($SearchObj->ExcludeWhereClause)) + { + $SearchObj->ExcludeWhereClause = '('.$notallowed.$or_is_null.'))'; + } + else + { + $SearchObj->ExcludeWhereClause .= ' AND ('.$notallowed.$or_is_null.'))'; + } } - $return .= $notallowed; - if(strlen($return)>0 && strlen($normal)>0) + + 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; - return $return; + }*/ + return $normal; } function GetIgnoreList()