You are here

function apachesolr_schema in Apache Solr Search 7

Same name and namespace in other branches
  1. 8 apachesolr.install \apachesolr_schema()
  2. 6.3 apachesolr.install \apachesolr_schema()
  3. 6 apachesolr.install \apachesolr_schema()
  4. 6.2 apachesolr.install \apachesolr_schema()

Implements hook_schema().

File

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

Code

function apachesolr_schema() {
  $table = drupal_get_schema_unprocessed('system', 'cache');
  $table['description'] = 'Cache table for apachesolr to store Luke data and indexing information.';
  $schema['cache_apachesolr'] = $table;
  $schema['apachesolr_environment'] = array(
    'description' => 'The Solr search environment table.',
    // Enable CTools exportables based on this table.
    'export' => array(
      // Environment machine name.
      'key' => 'env_id',
      // Description of key.
      'key name' => 'Environment machine name',
      // Apache Solr doesn't allow disabling environments.
      'can disable' => FALSE,
      // Variable name to use in exported code.
      'identifier' => 'environment',
      // Thin wrapper for the environment save callback.
      'save callback' => 'apachesolr_ctools_environment_save',
      // Thin wrapper for the environment delete callback.
      'delete callback' => 'apachesolr_ctools_environment_delete',
      // Includes the environment variables in 'conf' as well as the fields in this table.
      'export callback' => 'apachesolr_ctools_environment_export',
      // Use the same hook as the API name below.
      'default hook' => 'apachesolr_environments',
      // CTools API implementation.
      'api' => array(
        'owner' => 'apachesolr',
        'api' => 'apachesolr_environments',
        'minimum_version' => 1,
        'current_version' => 1,
      ),
    ),
    'fields' => array(
      'env_id' => array(
        'description' => 'Unique identifier for the environment',
        'type' => 'varchar',
        'length' => 64,
        'not null' => TRUE,
      ),
      'name' => array(
        'description' => 'Human-readable name for the server',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'url' => array(
        'description' => 'Full url for the server',
        'type' => 'varchar',
        'length' => 1000,
        'not null' => TRUE,
      ),
      'service_class' => array(
        'description' => 'Optional class name to use for connection',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
    ),
    'primary key' => array(
      'env_id',
    ),
  );
  $schema['apachesolr_environment_variable'] = array(
    'description' => 'Variable values for each Solr search environment.',
    'fields' => array(
      'env_id' => array(
        'description' => 'Unique identifier for the environment',
        'type' => 'varchar',
        'length' => 64,
        'not null' => TRUE,
      ),
      'name' => array(
        'description' => 'The name of the variable.',
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
        'default' => '',
      ),
      'value' => array(
        'description' => 'The value of the variable.',
        'type' => 'blob',
        'not null' => TRUE,
        'size' => 'big',
      ),
    ),
    'primary key' => array(
      'env_id',
      'name',
    ),
  );

  // Technically the entity system does not require an integer ID.
  // However, documentation mentions :
  // id: The name of the property that contains the primary id of the
  // entity. Every entity object passed to the Field API must have this
  // property and its value must be numeric.

  //Predefine an amount of types that get their own table
  $types = array(
    'other' => 'apachesolr_index_entities',
    'node' => 'apachesolr_index_entities_node',
  );
  foreach ($types as $type => $table) {
    $schema[$table] = array(
      'description' => 'Stores a record of when an entity changed to determine if it needs indexing by Solr.',
      'fields' => array(
        'entity_type' => array(
          'description' => 'The type of entity.',
          'type' => 'varchar',
          'length' => 32,
          'not null' => TRUE,
        ),
        'entity_id' => array(
          'description' => 'The primary identifier for an entity.',
          'type' => 'int',
          'unsigned' => TRUE,
          'not null' => TRUE,
        ),
        'bundle' => array(
          'description' => 'The bundle to which this entity belongs.',
          'type' => 'varchar',
          'length' => 128,
          'not null' => TRUE,
        ),
        'status' => array(
          'description' => 'Boolean indicating whether the entity should be in the index.',
          'type' => 'int',
          'not null' => TRUE,
          'default' => 1,
        ),
        'changed' => array(
          'description' => 'The Unix timestamp when an entity was changed.',
          'type' => 'int',
          'not null' => TRUE,
          'default' => 0,
        ),
      ),
      'indexes' => array(
        'bundle_changed' => array(
          'bundle',
          'changed',
        ),
      ),
      'primary key' => array(
        'entity_id',
      ),
    );
    if ($type == 'other') {

      // Need the entity type also in the pkey for multiple entities in one table.
      $schema[$table]['primary key'][] = 'entity_type';
    }
  }
  $schema['apachesolr_index_bundles'] = array(
    'description' => 'Records what bundles we should be indexing for a given environment.',
    'fields' => array(
      'env_id' => array(
        'description' => 'The name of the environment.',
        'type' => 'varchar',
        'length' => 64,
        'not null' => TRUE,
      ),
      'entity_type' => array(
        'description' => 'The type of entity.',
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
      ),
      'bundle' => array(
        'description' => 'The bundle to index.',
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
      ),
    ),
    'primary key' => array(
      'env_id',
      'entity_type',
      'bundle',
    ),
  );
  return $schema;
}