You are here

function apachesolr_update_5000 in Apache Solr Search 5.2

Create node indexing table.

File

./apachesolr.install, line 172
Install and related hooks for apachesolr_search.

Code

function apachesolr_update_5000() {
  set_time_limit(0);

  // Create table.
  $ret = array();
  if (!db_table_exists('apachesolr_search_node')) {

    // Create tables.
    switch ($GLOBALS['db_type']) {
      case 'mysql':
      case 'mysqli':
        $ret[] = update_sql("CREATE TABLE {apachesolr_search_node} (\n                    nid int(10) unsigned NOT NULL COMMENT 'The primary identifier for a node.',\n                    status int(11) NOT NULL default 1 COMMENT 'Boolean indicating whether the node is published (visible to non-administrators).',\n                    changed int(11) NOT NULL default 0 COMMENT 'The Unix timestamp when a node property was changed.',\n                    PRIMARY KEY (nid),\n                    KEY changed (changed, status)\n                 ) TYPE=MyISAM COMMENT='Stores a record of when a node property changed to determine if it needs indexing by Solr.' /*!40100 DEFAULT CHARACTER SET utf8 */;");
        break;
      case 'pgsql':

        // PostgreSQL DB
        $ret[] = update_sql("CREATE TABLE {apachesolr_search_node} (\n                    nid numeric(10) NOT NULL default 0,\n                    status numeric(11) NOT NULL default 1,\n                    changed numeric(11) NOT NULL default 0,\n                    PRIMARY KEY (nid)\n                  )");
        $ret[] = update_sql("CREATE INDEX {apachesolr_search_node}_changed_idx ON {apachesolr_search_node} (changed)");
        break;
    }
  }

  // Populate table
  $ret[] = update_sql("INSERT INTO {apachesolr_search_node} (nid, status, changed)\n                       SELECT n.nid, n.status, GREATEST(n.created, n.changed, COALESCE(c.last_comment_timestamp, 0)) AS changed\n                       FROM {node} n LEFT JOIN {apachesolr_search_node} asn ON n.nid = asn.nid\n                       LEFT JOIN {node_comment_statistics} c ON n.nid = c.nid\n                       WHERE asn.changed IS NULL");
  return $ret;
}