$SelectSQL .= $relcalc.$popcalc.$ratecalc." as Relevance, ";
$SelectSQL .= $this->SourceTable.".".$idField." as ItemId, ".$this->SourceTable.".ResourceId as ResourceId, CONCAT($typestr) as ItemType, EditorsPick as EdPick FROM ".$this->SourceTable." ";
foreach($this->Relationships as $JoinTable=>$OnClause)
{
$SelectSQL .= "LEFT JOIN $JoinTable ON $OnClause ";
}
$first=1;
$where=0;
foreach($this->FieldList as $field)
{
if(strpos($field,"as")>0)
{
$fparts = explode("as",$field,2);
$f = $fparts[1];
$this->AddSearchWhereClause($field);
}
else {
$this->AddSearchWhereClause($field);
}
}
- $SelectSQL .= " WHERE (";
- $SelectSQL .= implode(" or ",$this->WhereClauses);
- $SelectSQL .= ")";
+ if (count($this->WhereClauses))
+ {
+ $normal_where = '('; // not - or +
+ $normal_where .= implode(" or ",$this->WhereClauses);
+ $normal_where .= ')';
+ }
+ else
+ {
+ $normal_where = '';
+ }
+
+ $where = $normal_where;
if (strlen($this->ExcludeWhereClause))
{
- $SelectSQL .= ' AND '.$this->ExcludeWhereClause;
+ if (strlen($normal_where))
+ {
+ $where .= ' AND ';
+ }
+ $where .= $this->ExcludeWhereClause;
}
if (count($this->RequireWhereClause)>0)
{
foreach ($this->RequireWhereClause as $clause_part)
{
- $SelectSQL .= ' AND ('.$clause_part.')';
+ if (strlen($normal_where))
+ {
+ $where .= ' AND ';
+ }
+ $where .= '('.$clause_part.')';
}
}
if(is_array($idlist))
{
- $SelectSQL .= " AND (".$this->SourceTable.".ResourceId IN (".implode(",",$idlist)."))";
+ if (strlen($normal_where))
+ {
+ $where .= ' AND ';
+ }
+ $where .= '('.$this->SourceTable.'.ResourceId IN ('.implode(',',$idlist).'))';
}
}
+
+ if (!strlen($where))
+ {
+ $where = '1';
+ }
+ $SelectSQL .= " WHERE ".$where;
+
$SelectSQL .= " GROUP BY $idField ";
//echo $SelectSQL."<br><br>\n";
if($InitTable == TRUE)
{
$this->adodbConnection->Execute("DROP TABLE IF EXISTS ".$this->ResultTable);
//$indexSQL = "(INDEX(Relevance), INDEX(ItemId), INDEX(ItemType), INDEX sorting (EdPick,Relevance)) ";