[DATABASE] Re-introduce PostgreSQL support

This commit is contained in:
Alexei Sorokin
2019-09-11 14:14:40 +03:00
parent 644b417f6c
commit ee7f0a2016
22 changed files with 606 additions and 410 deletions

View File

@@ -70,6 +70,43 @@ class SearchEngine
}
}
class PostgreSQLSearch extends SearchEngine
{
public function query($q)
{
if ($this->table === 'profile') {
$cols = implode(" || ' ' || ", array_map(
function ($col) {
return sprintf(
"COALESCE(%s.%s, '')",
common_database_tablename($this->table),
$col
);
},
['nickname', 'fullname', 'location', 'bio', 'homepage']
));
$this->target->whereAdd(sprintf(
'to_tsvector(\'english\', %2$s) @@ plainto_tsquery(\'%1$s\')',
$this->target->escape($q, true),
$cols
));
return true;
} elseif ($this->table === 'notice') {
// Don't show imported notices
$this->target->whereAdd('notice.is_local <> ' . Notice::GATEWAY);
$this->target->whereAdd(sprintf(
'to_tsvector(\'english\', content) @@ plainto_tsquery(\'%1$s\')',
$this->target->escape($q, true)
));
return true;
} else {
throw new ServerException('Unknown table: ' . $this->table);
}
}
}
class MySQLSearch extends SearchEngine
{
public function query($q)
@@ -120,7 +157,7 @@ class MySQLSearch extends SearchEngine
}
}
class MySQLLikeSearch extends SearchEngine
class SQLLikeSearch extends SearchEngine
{
public function query($q)
{
@@ -145,18 +182,3 @@ class MySQLLikeSearch extends SearchEngine
return true;
}
}
class PGSearch extends SearchEngine
{
public function query($q)
{
if ($this->table === 'profile') {
return $this->target->whereAdd('textsearch @@ plainto_tsquery(\'' . $this->target->escape($q) . '\')');
} elseif ($this->table === 'notice') {
// XXX: We need to filter out gateway notices (notice.is_local = -2) --Zach
return $this->target->whereAdd('to_tsvector(\'english\', content) @@ plainto_tsquery(\'' . $this->target->escape($q) . '\')');
} else {
throw new ServerException('Unknown table: ' . $this->table);
}
}
}