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