function data_search_update_index in Data 8
Same name and namespace in other branches
- 6 data_search/data_search.module \data_search_update_index()
- 7 data_search/data_search.module \data_search_update_index()
Implements hook_update_index().
File
- data_search/
data_search.module, line 77
Code
function data_search_update_index() {
$limit = (int) variable_get('search_cron_limit', 100);
$connection = \Drupal::database();
$tables = data_search_get_tables();
foreach ($tables as $table) {
$name = $table
->get('name');
$schema = $table
->get('table_schema');
$fields = data_search_get_fields($table);
$fields = implode(', ', $fields);
$base_field = current($schema['primary key']);
// TODO Please convert this statement to the D7 database API syntax.
$result = $connection
->queryRange("SELECT dt.{$base_field} id FROM {{$name}} dt LEFT JOIN {search_dataset} d ON d.type = '{$name}' AND d.sid = dt.{$base_field} WHERE d.sid IS NULL OR d.reindex <> 0 ORDER BY d.reindex ASC, dt.{$base_field} ASC");
while ($row = db_fetch_object($result)) {
// TODO Please convert this statement to the D7 database API syntax.
$values = db_fetch_array($connection
->query("SELECT {$fields} FROM {{$name}} WHERE {$base_field} = '%s'", $row->id));
$fulltext = '';
foreach ($values as $field => $value) {
$fulltext .= "{$value}\n\n";
}
Drupal::service('search.index')
->index($row->id, $name, $fulltext);
}
// Delete orphaned data search records, no nodeapi to take care of this as it occurs.
// TODO Please convert this statement to the D7 database API syntax.
$connection
->query("DELETE sd, si, snl FROM {search_dataset} sd LEFT JOIN {{$name}} dt ON sd.type = '{$name}' AND sd.sid = dt.{$base_field} LEFT JOIN {search_index} si ON sd.sid = si.sid AND sd.type = si.type LEFT JOIN {search_node_links} snl ON sd.sid = snl.sid AND sd.type = snl.type WHERE dt.{$base_field} IS NULL");
}
}