Page MenuHomeIn-Portal Phabricator

in-portal
No OneTemporary

File Metadata

Created
Sun, Feb 2, 1:13 PM

in-portal

Index: trunk/kernel/include/advsearch.php
===================================================================
--- trunk/kernel/include/advsearch.php (revision 1173)
+++ trunk/kernel/include/advsearch.php (revision 1174)
@@ -1,264 +1,270 @@
<?php
class clsAdvancedSearchResults extends clsItemCollection
{
var $ResultTable;
var $FieldList;
var $FieldWeight;
var $WhereClauses;
var $SourceTable;
var $Relationships;
var $Ignored_Words;
var $CatClause;
var $Keywords;
var $Phrase = "";
var $SearchType;
var $RequiredRelevance;
var $PctRelevance;
var $PctPop;
var $PctRating;
function clsAdvancedSearchResults($SearchSource,$DataClass, $ItemType = 0)
{
global $objConfig, $objSearchConfig;
$this->clsItemCollection();
$this->SourceTable = $SearchSource;
$this->SetResultTable($SearchSource,$DataClass);
$this->FieldList = array();
$this->Relationships = array();
$this->Ignored_Words = array();
$this->WhereClauses = array();
$this->FieldWeight = array();
$this->Keywords = GetKeywords("");
$this->SearchType = 0; //simple
$this->RequiredRelevance=0;
$this->PctRelevance = $objConfig->Get("SearchRel_DefaultKeyword")/100;
$this->PctPop = $objConfig->Get("SearchRel_DefaultPop")/100;
$this->PctRating = $objConfig->Get("SearchRel_DefaultRating")/100;
if(!is_object($objSearchConfig))
$objSearchConfig = new clsSearchConfigList();
$objSearchConfig->Clear();
if ($ItemType == 0) {
$objSearchConfig->Query_Item("SELECT * FROM ".$objSearchConfig->SourceTable." WHERE TableName='$SearchSource' AND AdvancedSearch=1 ORDER BY DisplayOrder");
}
else {
$tables = Array(1 => 'Category', 2 => 'News',
3 => 'Topic', 4 => 'Link');
$table = $tables[$ItemType];
$sql = "SELECT sc.* FROM ".$objSearchConfig->SourceTable." AS sc LEFT JOIN ".GetTablePrefix()."CustomField AS cf ON sc.CustomFieldId = cf.CustomFieldId WHERE TableName='$table' OR (TableName='".GetTablePrefix()."CustomField' AND cf.Type = $ItemType) AND AdvancedSearch=1 ORDER BY sc.DisplayOrder";
$objSearchConfig->Query_Item($sql);
}
}
function SetResultTable($SearchSource,$DataClass)
{
global $objSession;
//$this->ResultTable = $objSession->GetSessionKey()."_Search";
$this->ResultTable = $objSession->GetSessionTable('Search', '');
$this->classname= $DataClass;
}
function LoadSearchResults($Start=0,$PerPage=NULL)
{
if($PerPage)
{
$limit = "LIMIT $Start,$PerPage";
}
$sql = "SELECT * FROM ".$this->ResultTable." ".$limit;
$this->Clear();
$rs = $this->adodbConnection->Execute($sql);
return $this->Query_Item($sql);
}
function SetCategoryClause($whereclause)
{
$this->CatClause=$whereclause;
}
function AddRelationship($JoinTable,$JoinExpression=NULL)
{
$this->Relationships[$JoinTable]=$JoinExpression;
}
function SetKeywords($keywords)
{
$this->Phrase=$keywords;
$this->keywords = GetKeywords($keywords);
}
function AddAdvancedField($TableName,$FieldName,$Verb,$Value,$conj)
{
global $objSearchConfig;
+ static $x = 0;
+
if(!is_object($objSearchConfig))
$objSearchConfig = new clsSeachConfigList();
if ($TableName==GetTablePrefix().'CustomField')
{
$prefix = '';
}
else
{
$prefix = GetTablePrefix();
}
$f = $prefix.$TableName.".".$FieldName;
$FieldConfig = $objSearchConfig->GetItemByName($TableName,$FieldName);
if(is_object($FieldConfig))
{
if(strlen($FieldConfig->Get("ForeignField"))>0)
{
+ $x++;
$parts = explode(".",$FieldConfig->Get("ForeignField"));
$Table = $parts[0];
+ $pseudo = 'c'.$x;
$Table = AddTablePrefix($Table);
$Field = $parts[1];
$join = $FieldConfig->Get("JoinClause");
- $join = str_replace("{ForeignTable}",$Table,$join);
- $join = str_replace("{LocalTable}",AddTablePrefix($TableName),$join);
+ $join = str_replace($Table, $pseudo, $join);
+ $join = str_replace("{ForeignTable}", $pseudo, $join);
+ $join = str_replace("{LocalTable}", $TableName, $join);
$join = str_replace("{Table}", AddTablePrefix($this->SourceTable), $join);
- $this->AddRelationship($Table,$join);
+ $join = '('.$join.' AND '.$pseudo.'.CustomFieldId='.$FieldConfig->Get('CustomFieldId').')';
+ $this->AddRelationship($Table.' AS '.$pseudo, $join);
- $FieldItem["where"] = GetTablePrefix().$FieldConfig->GetWhereClause($Verb,$Value);
+ $FieldItem["where"] = str_replace('CustomMetaData', $pseudo, $FieldConfig->GetWhereClause($Verb,$Value));
$FieldItem["Field"] = $FieldConfig->Get("ForeignField");
- $FieldItem["Table"] = "";
+ $FieldItem["Table"] = $pseudo;
$FieldItem["conjuction"] = $conj;
$FieldItem["weight"] = $FieldConfig->Get("Priority");
}
else
{
$FieldItem = array();
$FieldItem["Table"] = AddTablePrefix($TableName);
$FieldItem["Field"] = $FieldName;
- $FieldItem["where"] = $FieldConfig->GetWhereClause($Verb,$Value);
+ $FieldItem["where"] = $FieldItem["Table"].'.'.$FieldConfig->GetWhereClause($Verb,$Value);
$FieldItem["conjuction"] = $conj;
$FieldItem["weight"] = $FieldConfig->Get("Priority");
}
$this->FieldList[] = $FieldItem;
unset($FieldItem);
}
}
/* function AddAdvancedCustomFields()
{
$sql = "SELECT * FROM ".GetTablePrefix()."SearchConfig WHERE TableName='".$this->SourceTable."' AND AdvancedSearch=1 AND CustomFieldId>0";
//echo $sql;
foreach($this->Relationships as $Table=>$clause)
{
if(strlen($Table)>0 && $Table != "Category")
$sql .= " OR TableName='".$Table."'";
}
$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 AddAdvancedFields()
{
$sql = "SELECT * FROM ".GetTablePrefix()."SearchConfig WHERE TableName='".$this->SourceTable."' AND AdvancedSearch=1 AND CustomFieldId=0";
//echo $sql;
foreach($this->Relationships as $Table=>$clause)
{
if(strlen($Table)>0 && $Table != "Category")
$sql .= " OR TableName='".$Table."'";
}
$rs = $this->adodbConnection->Execute($sql);
while($rs && !$rs->EOF)
{
$f = GetTablePrefix().$rs->fields["TableName"].".".$rs->fields["FieldName"];
$this->FieldList[] = $f;
$this->FieldWeight[$f] = $rs->fields["Priority"];
$rs->MoveNext();
}
$this->AddAdvancedCustomFields();
}*/
/* ready to write the code to build the query and go */
function BuildWhereClause()
{
$where = "";
foreach($this->FieldList as $f)
$where .= " (".$f["where"].") ".$f["conjuction"];
$cut_length = substr($where, -2) == 'OR' ? 2 : substr($where, -3) == 'AND' ? 3 : 0;
$where = substr($where, 0, strlen($where) - $cut_length);
return $where;
}
function PerformSearch($ItemType,$OrderBy=NULL,$InitTable=FALSE, $idlist=NULL)
{
static $SelectSQL, $OldItemType;
global $objSession, $objItemTypes;
$ctype = $objItemTypes->GetItem($ItemType);
$idField = $ctype->Get("SourceTable")."Id";
$this->SourceTable = AddTablePrefix($ctype->Get("SourceTable"));
$result=0;
$PopField = $ctype->Get("PopField");
$RateField = $ctype->Get("RateField");
$typestr = str_pad($ItemType,2,"0",STR_PAD_LEFT);
$SelectSQL = "SELECT ".$this->SourceTable.".".$idField." as ItemId, ". $this->SourceTable.".Priority as Relevance, ".$this->SourceTable.".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;
$WhereClause = $this->BuildWhereClause();
if(strlen($WhereClause)>0)
{
$SelectSQL .= " WHERE ".$WhereClause;
}
$SelectSQL .= " GROUP BY $idField ";
//echo $SelectSQL;
$this->adodbConnection->Execute("DROP TABLE IF EXISTS ".$this->ResultTable);
$full_sql = "CREATE TABLE ".$this->ResultTable." ".$indexSQL.$SelectSQL;
$this->adodbConnection->Execute($full_sql);
// if advanced seaech used, then delete simple search keywords
$objSession->SetVariable('Search_Keywords', '');
//print_pre($full_sql);
}
function BuildIndexes()
{
$sql = "ALTER TABLE ".$this->ResultTable." ADD INDEX (Relevance), ";
$sql .="ADD INDEX (ItemId), ";
$sql .="ADD INDEX (ItemType), ";
$sql .=" ADD INDEX sorting (EdPick,Relevance)";
$this->adodbConnection->Execute($sql);
}
function Result_IdList()
{
/* returns an array contain a resource ID list */
$sql = "SELECT DISTINCT(ResourceId) FROM ".$this->ResultTable;
$rs = $this->adodbConnection->Execute($sql);
$result = array();
while($rs && !$rs->EOF)
{
$result[] = $rs->fields["ResourceId"];
$rs->MoveNext();
}
return $result;
}
function SetRelevence($ItemType, $IdField)
{
}
}
?>
\ No newline at end of file
Property changes on: trunk/kernel/include/advsearch.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.6
\ No newline at end of property
+1.7
\ No newline at end of property

Event Timeline