summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--actions/noticesearch.php7
-rw-r--r--actions/noticesearchrss.php8
-rw-r--r--actions/peoplesearch.php7
-rw-r--r--db/laconica_pg.sql14
4 files changed, 28 insertions, 8 deletions
diff --git a/actions/noticesearch.php b/actions/noticesearch.php
index c257ecec5..7022109e6 100644
--- a/actions/noticesearch.php
+++ b/actions/noticesearch.php
@@ -40,7 +40,12 @@ class NoticesearchAction extends SearchAction {
# lcase it for comparison
$q = strtolower($q);
- $notice->whereAdd('MATCH(content) against (\''.addslashes($q).'\')');
+
+ if(common_config('db','type')=='mysql') {
+ $notice->whereAdd('MATCH(content) against (\''.addslashes($q).'\')');
+ } else {
+ $notice->whereAdd('to_tsvector(\'english\', content) @@ plainto_tsquery(\''.addslashes($q).'\')');
+ }
# Ask for an extra to see if there's more.
diff --git a/actions/noticesearchrss.php b/actions/noticesearchrss.php
index c9d08ce8e..f598d833e 100644
--- a/actions/noticesearchrss.php
+++ b/actions/noticesearchrss.php
@@ -39,7 +39,11 @@ class NoticesearchrssAction extends Rss10Action {
# lcase it for comparison
$q = strtolower($q);
- $notice->whereAdd('MATCH(content) against (\''.addslashes($q).'\')');
+ if(common_config('db','type')=='mysql') {
+ $notice->whereAdd('MATCH(content) against (\''.addslashes($q).'\')');
+ } else {
+ $notice->whereAdd('to_tsvector(\'english\',content) @@ plainto_tsquery(\''.addslashes($q).'\')');
+ }
$notice->orderBy('created DESC, notice.id DESC');
# Ask for an extra to see if there's more.
@@ -70,4 +74,4 @@ class NoticesearchrssAction extends Rss10Action {
function get_image() {
return NULL;
}
-} \ No newline at end of file
+}
diff --git a/actions/peoplesearch.php b/actions/peoplesearch.php
index adacc0954..4e0ec3f0c 100644
--- a/actions/peoplesearch.php
+++ b/actions/peoplesearch.php
@@ -39,8 +39,13 @@ class PeoplesearchAction extends SearchAction {
# lcase it for comparison
$q = strtolower($q);
- $profile->whereAdd('MATCH(nickname, fullname, location, bio, homepage) ' .
+
+ if(common_config('db','type')=='mysql') {
+ $profile->whereAdd('MATCH(nickname, fullname, location, bio, homepage) ' .
'against (\''.addslashes($q).'\')');
+ } else {
+ $profile->whereAdd('textsearch @@ plainto_tsquery(\''.addslashes($q).'\')');
+ }
# Ask for an extra to see if there's more.
diff --git a/db/laconica_pg.sql b/db/laconica_pg.sql
index 315112b93..ff11219d5 100644
--- a/db/laconica_pg.sql
+++ b/db/laconica_pg.sql
@@ -9,14 +9,12 @@ create table profile (
bio varchar(140) /* comment 'descriptive biography' */,
location varchar(255) /* comment 'physical location' */,
created timestamp not null /* comment 'date this record was created' */,
- modified timestamp /* comment 'date this record was modified' */
+ modified timestamp /* comment 'date this record was modified' */,
-/* FULLTEXT(nickname, fullname, location, bio, homepage) */
+ textsearch tsvector
);
create index profile_nickname_idx on profile using btree(nickname);
-
-
create table avatar (
profile_id integer not null /* comment 'foreign key to profile table' */ references profile (id) ,
original integer default 0 /* comment 'uploaded by user or generated?' */,
@@ -289,3 +287,11 @@ create table foreign_subscription (
);
create index foreign_subscription_subscriber_idx on foreign_subscription using btree(subscriber);
create index foreign_subscription_subscribed_idx on foreign_subscription using btree(subscribed);
+
+/* Textsearch stuff */
+
+create index textsearch_idx on profile using gist(textsearch);
+create index noticecontent_idx on notice using gist(to_tsvector('english',content));
+create trigger textsearchupdate before insert or update on profile for each row
+execute procedure tsvector_update_trigger(textsearch, 'pg_catalog.english', nickname, fullname, location, bio, homepage);
+