mirror of
https://github.com/silverstripe/silverstripe-postgresql
synced 2024-10-22 15:05:45 +00:00
API CHANGE: searchengine function fixed to use extendedSQL()
This commit is contained in:
parent
5a96d9620c
commit
508da2b933
@ -252,6 +252,7 @@ class PostgreSQLDatabase extends Database {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function createTable($tableName, $fields = null, $indexes = null, $options = null) {
|
public function createTable($tableName, $fields = null, $indexes = null, $options = null) {
|
||||||
|
|
||||||
$fieldSchemas = $indexSchemas = "";
|
$fieldSchemas = $indexSchemas = "";
|
||||||
if($fields) foreach($fields as $k => $v) $fieldSchemas .= "\"$k\" $v,\n";
|
if($fields) foreach($fields as $k => $v) $fieldSchemas .= "\"$k\" $v,\n";
|
||||||
if(isset($this->class)){
|
if(isset($this->class)){
|
||||||
@ -1151,27 +1152,33 @@ class PostgreSQLDatabase extends Database {
|
|||||||
|
|
||||||
$tables=Array();
|
$tables=Array();
|
||||||
|
|
||||||
$locale=Translatable::get_current_locale();
|
// Make column selection lists
|
||||||
|
$select = array(
|
||||||
|
'SiteTree' => array("\"ClassName\"","\"SiteTree\".\"ID\"","\"ParentID\"","\"Title\"","\"URLSegment\"","\"Content\"","\"LastEdited\"","\"Created\"","NULL AS \"Filename\"", "NULL AS \"Name\"", "\"CanViewType\""),
|
||||||
|
'File' => array("\"ClassName\"","\"File\".\"ID\"","NULL AS \"ParentID\"","\"Title\"","NULL AS \"URLSegment\"","\"Content\"","\"LastEdited\"","\"Created\"","\"Filename\"","\"Name\"", "NULL AS \"CanViewType\""),
|
||||||
|
);
|
||||||
|
|
||||||
foreach($result as $row){
|
foreach($result as $row){
|
||||||
if($row['table_name']=='SiteTree'){
|
if($row['table_name']=='SiteTree')
|
||||||
$showInSearch="AND \"ShowInSearch\"=1 ";
|
$showInSearch="AND \"ShowInSearch\"=1 ";
|
||||||
$localeFilter=" AND \"SiteTree\".\"Locale\"='$locale'";
|
else
|
||||||
} else {
|
|
||||||
$showInSearch='';
|
$showInSearch='';
|
||||||
$localeFilter='';
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO: this needs to be changed to use augmentSQL in the same way the MySQL equivilent does:
|
//public function extendedSQL($filter = "", $sort = "", $limit = "", $join = "", $having = ""){
|
||||||
if($keywords){
|
$query=singleton($row['table_name'])->extendedSql("\"" . $row['column_name'] . "\" " . $this->default_fts_search_method . ' q ' . $showInSearch, '');
|
||||||
$thisSql = "SELECT \"ID\", '{$row['table_name']}' AS ClassName, ts_rank(\"{$row['column_name']}\", q) AS Relevance FROM \"{$row['table_name']}\", to_tsquery('english', '$keywords') AS q WHERE \"{$row['column_name']}\" " . $this->default_fts_search_method . " q $localeFilter $showInSearch";
|
|
||||||
} else {
|
|
||||||
$thisSql = "SELECT \"ID\", '{$row['table_name']}' AS ClassName FROM \"{$row['table_name']}\" WHERE 1=1 $localeFilter $showInSearch";
|
$query->select=$select[$row['table_name']];
|
||||||
}
|
$query->from['tsearch']=", to_tsquery('english', '$keywords') AS q";
|
||||||
|
|
||||||
|
$query->select[]="ts_rank(\"{$row['column_name']}\", q) AS Relevance";
|
||||||
|
|
||||||
|
$query->orderby=null;
|
||||||
|
|
||||||
//Add this query to the collection
|
//Add this query to the collection
|
||||||
$tables[] = $thisSql;
|
$tables[] = $query->sql();
|
||||||
}
|
}
|
||||||
|
|
||||||
$doSet=new DataObjectSet();
|
$doSet=new DataObjectSet();
|
||||||
|
|
||||||
$limit=$pageLength;
|
$limit=$pageLength;
|
||||||
@ -1187,18 +1194,16 @@ class PostgreSQLDatabase extends Database {
|
|||||||
$records = DB::query($fullQuery);
|
$records = DB::query($fullQuery);
|
||||||
$totalCount=0;
|
$totalCount=0;
|
||||||
foreach($records as $record){
|
foreach($records as $record){
|
||||||
$item=DB::query("SELECT * FROM \"{$record['classname']}\" WHERE \"ID\"={$record['ID']};")->first();
|
$objects[] = new $record['ClassName']($record);
|
||||||
$objects[] = new $record['classname']($item);
|
|
||||||
$totalCount++;
|
$totalCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isset($objects)) $doSet = new DataObjectSet($objects);
|
if(isset($objects)) $doSet = new DataObjectSet($objects);
|
||||||
else $doSet = new DataObjectSet();
|
else $doSet = new DataObjectSet();
|
||||||
|
|
||||||
$doSet->setPageLimits($start, $pageLength, $totalCount);
|
$doSet->setPageLimits($start, $pageLength, $totalCount);
|
||||||
|
|
||||||
return $doSet;
|
return $doSet;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user