| This page is user contributed documentation. See the bottom of the page for information about the author. | |
CREATE FUNCTION fti() RETURNS opaque
AS '/path/to/fti.so' LANGUAGE 'C';
CREATE TABLE articles_fti ( string type, id oid );Where 'type' should match the type of the fields to index, or at least be as large as the fields it's indexing. Note that this assumed the existence of an 'articles' table.
CREATE INDEX "articles_fti_string_idx" ON articles_fti(string); CREATE INDEX "articles_fti_id_idx" ON articles_fti(id); CREATE INDEX "articles_oid_idx" ON articles(oid);This indexing scheme makes lookups, insertions and deletions fast.
CREATE TRIGGER "articles_fti_trigger" AFTER UPDATE OR INSERT OR DELETE ON articles FOR EACH ROW EXECUTE PROCEDURE fti(articles_fti, title, body, keywords);Where in this case 'articles_fti' is the table where the index for 'articles' is kept, and 'title', 'body' and 'keywords' are the fields in the 'articles' table that we are indexing.
/path/to/fti.pl -d mydb -t articles -c title,body,keywords -f /dev/stdout | sort -u > fti.sql\copy articles_fti from fti.sql
SELECT DISTINCT(a.*) FROM articles a, articles_fti f1, articles_fti f2 WHERE f1.string ~ '^perth AND f2.string ~ '^stralia' AND f1.id=f2.id AND a.oid=f1.id;