BUG FIX: searchEngine() now takes into account the locality

API CHANGE: Integer replaces Numeric for the Int() type, and it defaults to 32 in precision
This commit is contained in:
Geoff Munn 2009-10-05 02:03:00 +00:00
parent 74954dc374
commit 5a96d9620c

View File

@ -522,7 +522,6 @@ class PostgreSQLDatabase extends Database {
if(sizeof($constraints)>0){ if(sizeof($constraints)>0){
//Get the default: //Get the default:
//TODO: perhaps pass this to the enum function so we can
$default=trim(substr($field['column_default'], 0, strpos($field['column_default'], '::')), "'"); $default=trim(substr($field['column_default'], 0, strpos($field['column_default'], '::')), "'");
$output[$field['column_name']]=$this->enum(Array('default'=>$default, 'name'=>$field['column_name'], 'enums'=>$constraints)); $output[$field['column_name']]=$this->enum(Array('default'=>$default, 'name'=>$field['column_name'], 'enums'=>$constraints));
} }
@ -534,6 +533,10 @@ class PostgreSQLDatabase extends Database {
case 'numeric': case 'numeric':
$output[$field['column_name']]='numeric(' . $field['numeric_precision'] . ')'; $output[$field['column_name']]='numeric(' . $field['numeric_precision'] . ')';
break; break;
case 'integer':
$output[$field['column_name']]='integer(' . $field['numeric_precision'] . ')';
break;
default: default:
$output[$field['column_name']] = $field; $output[$field['column_name']] = $field;
} }
@ -595,9 +598,9 @@ class PostgreSQLDatabase extends Database {
$tableCol= 'ix_' . $tableName . '_' . $indexName; $tableCol= 'ix_' . $tableName . '_' . $indexName;
if(strlen($tableCol)>64){ if(strlen($tableCol)>64){
$tableCol=substr($indexName, 0, 59) . rand(1000, 9999); $tableCol=substr($indexName, 0, 59) . rand(1000, 9999);
//echo 'it is now ' . $tableCol . "\n\n";
} }
//It is possible to specify indexes through strings:
if(!is_array($indexSpec)){ if(!is_array($indexSpec)){
$indexSpec=trim($indexSpec, '()'); $indexSpec=trim($indexSpec, '()');
$bits=explode(',', $indexSpec); $bits=explode(',', $indexSpec);
@ -608,15 +611,15 @@ class PostgreSQLDatabase extends Database {
return "create index $tableCol ON \"" . $tableName . "\" (" . $indexes . ");"; return "create index $tableCol ON \"" . $tableName . "\" (" . $indexes . ");";
} else { } else {
//Arrays offer much more flexibility and many more options:
//Misc options first: //Misc options first:
$fillfactor=$where='';; $fillfactor=$where='';
if(isset($indexSpec['fillfactor'])) if(isset($indexSpec['fillfactor']))
$fillfactor='WITH (FILLFACTOR = ' . $indexSpec['fillfactor'] . ')'; $fillfactor='WITH (FILLFACTOR = ' . $indexSpec['fillfactor'] . ')';
if(isset($indexSpec['where'])) if(isset($indexSpec['where']))
$where='WHERE ' . $indexSpec['where']; $where='WHERE ' . $indexSpec['where'];
//TODO: create tablespace and where clause support
//create a type-specific index //create a type-specific index
//NOTE: hash should be removed. This is only here to demonstrate how other indexes can be made //NOTE: hash should be removed. This is only here to demonstrate how other indexes can be made
switch($indexSpec['type']){ switch($indexSpec['type']){
@ -637,6 +640,8 @@ class PostgreSQLDatabase extends Database {
$spec="create index $tableCol ON \"" . $tableName . "\" USING hash (\"" . $indexSpec['value'] . "\") $fillfactor $where"; $spec="create index $tableCol ON \"" . $tableName . "\" USING hash (\"" . $indexSpec['value'] . "\") $fillfactor $where";
break; break;
case 'index':
//'index' is the same as default, just a normal index with the default type decided by the database.
default: default:
$spec="create index $tableCol ON \"" . $tableName . "\" (\"" . $indexSpec['value'] . "\") $fillfactor $where"; $spec="create index $tableCol ON \"" . $tableName . "\" (\"" . $indexSpec['value'] . "\") $fillfactor $where";
} }
@ -795,6 +800,9 @@ class PostgreSQLDatabase extends Database {
//Annoyingly, we need to do a good ol' fashioned switch here: //Annoyingly, we need to do a good ol' fashioned switch here:
($values['default']) ? $default='1' : $default='0'; ($values['default']) ? $default='1' : $default='0';
if(!isset($values['arrayValue']))
$values['arrayValue']='';
if($asDbValue) if($asDbValue)
return Array('data_type'=>'smallint'); return Array('data_type'=>'smallint');
else { else {
@ -816,10 +824,10 @@ class PostgreSQLDatabase extends Database {
* @return string * @return string
*/ */
public function date($values){ public function date($values){
//For reference, this is what typically gets passed to this function:
//$parts=Array('datatype'=>'date'); if(!isset($values['arrayValue']))
//DB::requireField($this->tableName, $this->name, "date"); $values['arrayValue']='';
return "date{$values['arrayValue']}"; return "date{$values['arrayValue']}";
} }
@ -830,10 +838,10 @@ class PostgreSQLDatabase extends Database {
* @return string * @return string
*/ */
public function decimal($values, $asDbValue=false){ public function decimal($values, $asDbValue=false){
//For reference, this is what typically gets passed to this function:
//$parts=Array('datatype'=>'decimal', 'precision'=>"$this->wholeSize,$this->decimalSize"); if(!isset($values['arrayValue']))
//DB::requireField($this->tableName, $this->name, "decimal($this->wholeSize,$this->decimalSize)"); $values['arrayValue']='';
// Avoid empty strings being put in the db // Avoid empty strings being put in the db
if($values['precision'] == '') { if($values['precision'] == '') {
$precision = 1; $precision = 1;
@ -875,10 +883,9 @@ class PostgreSQLDatabase extends Database {
* @return string * @return string
*/ */
public function float($values, $asDbValue=false){ public function float($values, $asDbValue=false){
//For reference, this is what typically gets passed to this function: if(!isset($values['arrayValue']))
//$parts=Array('datatype'=>'float'); $values['arrayValue']='';
//DB::requireField($this->tableName, $this->name, "float");
if($asDbValue) if($asDbValue)
return Array('data_type'=>'double precision'); return Array('data_type'=>'double precision');
else return "float{$values['arrayValue']}"; else return "float{$values['arrayValue']}";
@ -891,8 +898,12 @@ class PostgreSQLDatabase extends Database {
* @return string * @return string
*/ */
public function int($values, $asDbValue=false){ public function int($values, $asDbValue=false){
if(!isset($values['arrayValue']))
$values['arrayValue']='';
if($asDbValue) if($asDbValue)
return Array('data_type'=>'integer', 'precision'=>$values['precision']); return Array('data_type'=>'integer', 'precision'=>'32');
else { else {
if($values['arrayValue']!='') if($values['arrayValue']!='')
$default=''; $default='';
@ -911,10 +922,10 @@ class PostgreSQLDatabase extends Database {
* @return string * @return string
*/ */
public function ssdatetime($values, $asDbValue=false){ public function ssdatetime($values, $asDbValue=false){
//For reference, this is what typically gets passed to this function:
//$parts=Array('datatype'=>'datetime'); if(!isset($values['arrayValue']))
//DB::requireField($this->tableName, $this->name, $values); $values['arrayValue']='';
if($asDbValue) if($asDbValue)
return Array('data_type'=>'timestamp without time zone'); return Array('data_type'=>'timestamp without time zone');
else else
@ -928,9 +939,9 @@ class PostgreSQLDatabase extends Database {
* @return string * @return string
*/ */
public function text($values, $asDbValue=false){ public function text($values, $asDbValue=false){
//For reference, this is what typically gets passed to this function:
//$parts=Array('datatype'=>'mediumtext', 'character set'=>'utf8', 'collate'=>'utf8_general_ci'); if(!isset($values['arrayValue']))
//DB::requireField($this->tableName, $this->name, "mediumtext character set utf8 collate utf8_general_ci"); $values['arrayValue']='';
if($asDbValue) if($asDbValue)
return Array('data_type'=>'text'); return Array('data_type'=>'text');
@ -946,10 +957,9 @@ class PostgreSQLDatabase extends Database {
* @return string * @return string
*/ */
public function time($values){ public function time($values){
//For reference, this is what typically gets passed to this function: if(!isset($values['arrayValue']))
//$parts=Array('datatype'=>'time'); $values['arrayValue']='';
//DB::requireField($this->tableName, $this->name, "time");
return "time{$values['arrayValue']}"; return "time{$values['arrayValue']}";
} }
@ -960,9 +970,10 @@ class PostgreSQLDatabase extends Database {
* @return string * @return string
*/ */
public function varchar($values, $asDbValue=false){ public function varchar($values, $asDbValue=false){
//For reference, this is what typically gets passed to this function:
//$parts=Array('datatype'=>'varchar', 'precision'=>$this->size, 'character set'=>'utf8', 'collate'=>'utf8_general_ci'); if(!isset($values['arrayValue']))
//DB::requireField($this->tableName, $this->name, "varchar($this->size) character set utf8 collate utf8_general_ci"); $values['arrayValue']='';
if(!isset($values['precision'])) if(!isset($values['precision']))
$values['precision']=255; $values['precision']=255;
@ -976,6 +987,10 @@ class PostgreSQLDatabase extends Database {
* Return a 4 digit numeric type. MySQL has a proprietary 'Year' type. * Return a 4 digit numeric type. MySQL has a proprietary 'Year' type.
*/ */
public function year($values, $asDbValue=false){ public function year($values, $asDbValue=false){
if(!isset($values['arrayValue']))
$values['arrayValue']='';
if($asDbValue) if($asDbValue)
return Array('data_type'=>'numeric', 'precision'=>'4'); return Array('data_type'=>'numeric', 'precision'=>'4');
else return "numeric(4){$values['arrayValue']}"; else return "numeric(4){$values['arrayValue']}";
@ -1119,7 +1134,7 @@ class PostgreSQLDatabase extends Database {
/** /**
* The core search engine configuration. * The core search engine configuration.
* @todo There is no result relevancy or ordering as it currently stands. * @todo Properly extract the search functions out of the core.
* *
* @param string $keywords Keywords as a space separated string * @param string $keywords Keywords as a space separated string
* @return object DataObjectSet of result pages * @return object DataObjectSet of result pages
@ -1136,16 +1151,22 @@ class PostgreSQLDatabase extends Database {
$tables=Array(); $tables=Array();
$locale=Translatable::get_current_locale();
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 ";
else $localeFilter=" AND \"SiteTree\".\"Locale\"='$locale'";
$showInSearch='';
if($keywords){
$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 $showInSearch";
} else { } else {
$thisSql = "SELECT \"ID\", '{$row['table_name']}' AS ClassName FROM \"{$row['table_name']}\" WHERE 1=1 $showInSearch"; $showInSearch='';
$localeFilter='';
}
//TODO: this needs to be changed to use augmentSQL in the same way the MySQL equivilent does:
if($keywords){
$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";
} }
//Add this query to the collection //Add this query to the collection