diff options
author | Matthias Andreas Benkard <code@mail.matthias.benkard.de> | 2011-03-22 23:05:30 +0100 |
---|---|---|
committer | Matthias Andreas Benkard <code@mail.matthias.benkard.de> | 2011-03-22 23:05:30 +0100 |
commit | 1d44017f08c44ba6b36d1d054b84346d3eecfbcc (patch) | |
tree | b946e81c30a680fc61ab453246a96ab6fce2cbab | |
parent | c34ea8f4bfdeda74c30542db22c4a3f9445a5113 (diff) |
Database schema: Add function do_full_text_search and a couple of full-text search indices.
-rw-r--r-- | schema.sql | 48 |
1 files changed, 48 insertions, 0 deletions
@@ -297,4 +297,52 @@ CREATE VIEW article_branch_tips AS JOIN article_revisions USING (id); +-- You can customize the following depending on which languages you +-- support on your web site. + +CREATE INDEX article_revisions_german_ts_idx + ON article_revisions + USING gin((setweight(to_tsvector('german', title), 'A') + || setweight(to_tsvector('german', content), 'D'))); + +CREATE INDEX article_revisions_english_ts_idx + ON article_revisions + USING gin((setweight(to_tsvector('english', title), 'A') + || setweight(to_tsvector('english', content), 'D'))); + +CREATE INDEX article_revisions_french_ts_idx + ON article_revisions + USING gin((setweight(to_tsvector('french', title), 'A') + || setweight(to_tsvector('french', content), 'D'))); + +CREATE FUNCTION do_full_text_search(query tsquery, + language regconfig, + max_results INTEGER) +RETURNS SETOF record +AS $$ + WITH headline_options AS ( + SELECT 'StartSel=<strong>,StopSel=</strong>,FragmentDelimiter=" ... "'::varchar + AS headline_options + ), search AS ( + SELECT revision, + ts_rank(( setweight(to_tsvector($2, title), 'A') + || setweight(to_tsvector($2, content), 'D')), + $1, + 1) + AS rank, + title, + content + FROM article_branch_tips + JOIN article_revisions ON revision = id + ORDER BY rank DESC + LIMIT $3 + ) + SELECT rank, + revision, + ts_headline(content, $1, headline_options), + ts_headline(title, $1, headline_options) + FROM search + CROSS JOIN headline_options +$$ LANGUAGE SQL STABLE; + COMMIT; |