$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);
}
}
if (count($this->WhereClauses))
{
$normal_where = '('; // not - or +
$normal_where .= implode(" or ",$this->WhereClauses);
$normal_where .= ')';
}
else
{
$normal_where = '';
}
$where = $normal_where;
if (count($this->ExcludeWhereClause)>0)
{
foreach ($this->ExcludeWhereClause as $section)
{
foreach ($section as $clause_part)
{
if (strlen($where))
{
$where .= ' AND ';
}
$where .= '('.$clause_part.')';
}
}
}
if (count($this->RequireWhereClause)>0)
{
$requirewhere .= '(';
foreach ($this->RequireWhereClause as $section)
{
$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($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)) ";