You are here

function similar_index in Similar Entries 7.2

Adds FULLTEXT index to a single field in the database.

Parameters

string $field: The machine-name of the field being indexed.

string $table: The table that contains the field to be indexed.

string $column: The name of the column to index.

array $info: An optional array of information to store in Similar Entries settings.

Return value

bool FALSE if the index already exists or the field does not exist. TRUE otherwise.

1 call to similar_index()
similar_index_fields in ./similar.module
Indexes fields defined by Field module.

File

./similar.module, line 95
Module that shows a block listing similar entries. NOTE: Uses MySQL's FULLTEXT indexing for MyISAM tables.

Code

function similar_index($field, $table, $column, $info = array()) {

  // Return FALSE if the field doesn't exist.
  $index = "similar_{$field}";
  if (!db_table_exists($table) || !db_field_exists($table, $column)) {
    return FALSE;
  }
  if (!db_index_exists($table, $index)) {
    db_query("ALTER TABLE {" . $table . "} ENGINE = MYISAM");
    db_query("ALTER TABLE {" . $table . "} ADD FULLTEXT `{$index}` (`{$column}`)");
  }

  // Add data to the info array for storage in similar indices variable.
  $info += array(
    'index' => $index,
  );
  return _similar_save_index($field, $table, $column, $info);
}