public function tidy()
{
// Is the fulltext indexer disabled? If yes then we need not
// carry on ... it's okay ... I know when I'm not wanted boo hoo
if (!$this->config['fulltext_native_load_upd']) {
$this->config->set('search_last_gc', time(), false);
return;
}
$destroy_cache_words = array();
// Remove common words
if ($this->config['num_posts'] >= 100 && $this->config['fulltext_native_common_thres']) {
$common_threshold = (double) $this->config['fulltext_native_common_thres'] / 100.0;
// First, get the IDs of common words
$sql = 'SELECT word_id, word_text
FROM ' . SEARCH_WORDLIST_TABLE . '
WHERE word_count > ' . floor($this->config['num_posts'] * $common_threshold) . '
OR word_common = 1';
$result = $this->db->sql_query($sql);
$sql_in = array();
while ($row = $this->db->sql_fetchrow($result)) {
$sql_in[] = $row['word_id'];
$destroy_cache_words[] = $row['word_text'];
}
$this->db->sql_freeresult($result);
if (sizeof($sql_in)) {
// Flag the words
$sql = 'UPDATE ' . SEARCH_WORDLIST_TABLE . '
SET word_common = 1
WHERE ' . $this->db->sql_in_set('word_id', $sql_in);
$this->db->sql_query($sql);
// by setting search_last_gc to the new time here we make sure that if a user reloads because the
// following query takes too long, he won't run into it again
$this->config->set('search_last_gc', time(), false);
// Delete the matches
$sql = 'DELETE FROM ' . SEARCH_WORDMATCH_TABLE . '
WHERE ' . $this->db->sql_in_set('word_id', $sql_in);
$this->db->sql_query($sql);
}
unset($sql_in);
}
if (sizeof($destroy_cache_words)) {
// destroy cached search results containing any of the words that are now common or were removed
$this->destroy_cache(array_unique($destroy_cache_words));
}
$this->config->set('search_last_gc', time(), false);
}