You are here

public function FuzzySearchService::addIndex in Fuzzy Search 7

Implements SearchApiServiceInterface::__construct().

Does nothing, by default.

Overrides SearchApiAbstractService::addIndex

File

includes/service.inc, line 105

Class

FuzzySearchService
Search service class using the database for storing index information.

Code

public function addIndex(SearchApiIndex $index) {
  $this->options += array(
    'indexes' => array(),
  );
  $indexes =& $this->options['indexes'];
  if (isset($indexes[$index->machine_name])) {

    // Easiest and safest method to ensure all of the index' data is
    // properly re-added.
    $this
      ->removeIndex($index);
  }
  if (empty($index->options['fields']) || !is_array($index->options['fields'])) {

    // No fields, no work.
    $indexes[$index->machine_name] = array();
    $this->server
      ->save();
    return $this;
  }
  $prefix = 'fuzzysearch_' . $index->machine_name . '_';
  $indexes[$index->machine_name] = array();
  foreach ($index
    ->getFields() as $name => $field) {
    $table = $this
      ->findFreeTable($prefix, $name);
    $this
      ->createFieldTable($index, $field, $table);
    $indexes[$index->machine_name][$name]['table'] = $table;
    $indexes[$index->machine_name][$name]['type'] = $field['type'];
    $indexes[$index->machine_name][$name]['boost'] = $field['boost'];
  }
  $this->server
    ->save();
}