mikl / drupal-tsearch

A revamped search module for Drupal, taking advantage of PostgreSQL's advanced full text search.

This URL has Read+Write access

drupal-tsearch / tsearch.install
bb21613d » mikl 2008-10-23 Forking Drupal's search mod... 1 <?php
69bbef23 » mikl 2008-10-23 Made new database schema, b... 2 // $Id$
3
4 /**
5 * @file
6 * Installation file for TSearch module.
7 */
8
9 /**
10 * Implementation of hook_requirements().
11 */
12 function tsearch_requirements($phase) {
13 $requirements = array();
14 $t = get_t();
15 $postgresql_version = 0;
16
17 $requirements['tsearch']['title'] = $t('PostgreSQL full text search');
18
19 if ($GLOBALS['db_type'] != 'pgsql') {
20 $requirements['tsearch']['value'] = $t('PostgreSQL required');
21 $requirements['tsearch']['description'] = $t('PostgreSQL full text search requires you to use the PostgreSQL database to work');
22 $requirements['tsearch']['severity'] = REQUIREMENT_ERROR;
23 return $requirements;
24 }
25
26 if (!db_result(db_query("SELECT lanname FROM pg_language WHERE lanname='plpgsql';"))) {
27 $requirements['tsearch']['value'] = $t('PL/pgSQL not found');
28 $requirements['tsearch']['description'] = $t('You need to enable PL/pgSQL in your database. This can be done with the following SQL query: "CREATE LANGUAGE plpgsql;"');
29 $requirements['tsearch']['severity'] = REQUIREMENT_ERROR;
30 return $requirements;
31 }
32
33 $pg_version = db_result(db_query("SELECT version();"));
34
35 // FIXME: Find a better way of checking the version.
36 if (strpos($pg_version, ' 8.3.') !== FALSE) {
37 // We have a supported version of PostgreSQL, how nice.
38 $requirements['tsearch']['value'] = $t('All OK!');
39 $requirements['tsearch']['description'] = $t('Your system is correctly configured to use PostgreSQL full text search."');
40 $requirements['tsearch']['severity'] = REQUIREMENT_OK;
41 }
42 else {
43 $requirements['tsearch']['value'] = $t('Unsupported version of PostgreSQL');
44 $requirements['tsearch']['description'] = $t('Your version of PostgreSQL %version is not supported.', array('%version' => $pg_version));
45 $requirements['tsearch']['severity'] = REQUIREMENT_ERROR;
46 }
47 return $requirements;
48 }
49
bb21613d » mikl 2008-10-23 Forking Drupal's search mod... 50
51 /**
52 * Implementation of hook_install().
53 */
5245c91b » mikl 2008-10-23 Renaming functions. 54 function tsearch_install() {
69bbef23 » mikl 2008-10-23 Made new database schema, b... 55 // Since we check requirements with hook_requirements, we assume that all
56 // is okay and create the table using very PostgreSQL-specific SQL.
57 $sql = <<<SQL
58 CREATE TABLE tsearch_node
59 (
60 nid int_unsigned NOT NULL,
d8c25548 » mikl 2008-10-29 Added vid column for the ts... 61 vid int_unsigned NOT NULL,
69bbef23 » mikl 2008-10-23 Made new database schema, b... 62 node_tsvector tsvector NOT NULL,
63 ts_language character varying(30),
64 updated int_unsigned NOT NULL DEFAULT 0,
65 CONSTRAINT tsearch_node_pkey PRIMARY KEY (nid),
66 CONSTRAINT node_nid FOREIGN KEY (nid)
67 REFERENCES node (nid) MATCH SIMPLE
d9a94aa7 » mikl 2009-03-21 Delete our index when the n... 68 ON UPDATE NO ACTION ON DELETE CASCADE
69bbef23 » mikl 2008-10-23 Made new database schema, b... 69 )
70 SQL;
71
72 db_query($sql);
73
74 // The main search index. Change to GIST if you have very frequent content changes.
75 db_query("CREATE INDEX search_idx
92acb02e » mikl 2008-10-25 Fixing indentation. 76 ON tsearch_node
77 USING gin (node_tsvector);");
69bbef23 » mikl 2008-10-23 Made new database schema, b... 78
79 // Index for the updated column.
80 db_query("CREATE INDEX updated_idx
92acb02e » mikl 2008-10-25 Fixing indentation. 81 ON tsearch_node
82 USING btree (updated);");
bb21613d » mikl 2008-10-23 Forking Drupal's search mod... 83 }
84
85 /**
86 * Implementation of hook_uninstall().
87 */
5245c91b » mikl 2008-10-23 Renaming functions. 88 function tsearch_uninstall() {
bb21613d » mikl 2008-10-23 Forking Drupal's search mod... 89 // Remove tables.
69bbef23 » mikl 2008-10-23 Made new database schema, b... 90 db_query("DROP TABLE tsearch_node;");
bb21613d » mikl 2008-10-23 Forking Drupal's search mod... 91
92 variable_del('minimum_word_size');
93 variable_del('overlap_cjk');
94 variable_del('search_cron_limit');
95 }