search_update_totals

  1. drupal
    1. 5
    2. 6
    3. 7
    4. 8
Versions
5 – 8 search_update_totals()

Updates the {search_total} database table.

This function is called on shutdown to ensure that {search_total} is always up to date (even if cron times out or otherwise fails).

▾ 10 functions call search_update_totals()

SearchAdvancedSearchForm::setUp in modules/search/search.test
Generates a random database prefix, runs the install scripts on the prefixed database and enable the specified modules. After installation many caches are flushed and the internal browser is setup so that the page requests will run on the new prefix.…
SearchCommentCountToggleTestCase::setUp in modules/search/search.test
Generates a random database prefix, runs the install scripts on the prefixed database and enable the specified modules. After installation many caches are flushed and the internal browser is setup so that the page requests will run on the new prefix.…
SearchConfigSettingsForm::setUp in modules/search/search.test
Generates a random database prefix, runs the install scripts on the prefixed database and enable the specified modules. After installation many caches are flushed and the internal browser is setup so that the page requests will run on the new prefix.…
SearchEmbedForm::setUp in modules/search/search.test
Generates a random database prefix, runs the install scripts on the prefixed database and enable the specified modules. After installation many caches are flushed and the internal browser is setup so that the page requests will run on the new prefix.…
SearchExactTestCase::testExactQuery in modules/search/search.test
Tests that the correct number of pager links are found for both keywords and phrases.
SearchMatchTestCase::_setup in modules/search/search.test
Set up a small index of items to test against.
SearchNodeAccessTest::testPhraseSearchPunctuation in modules/search/search.test
Tests that search returns results with punctuation in the search phrase.
SearchRankingTestCase::testDoubleRankings in modules/search/search.test
Verifies that if we combine two rankings, search still works.
SearchRankingTestCase::testHTMLRankings in modules/search/search.test
Test rankings of HTML tags.
SearchRankingTestCase::testRankings in modules/search/search.test

Code

modules/search/search.module, line 373

<?php
function search_update_totals() {
  // Update word IDF (Inverse Document Frequency) counts for new/changed words.
  foreach (search_dirty() as $word => $dummy) {
    // Get total count
    $total = db_query("SELECT SUM(score) FROM {search_index} WHERE word = :word", array(':word' => $word), array('target' => 'slave'))->fetchField();
    // Apply Zipf's law to equalize the probability distribution.
    $total = log10(1 + 1 / (max(1, $total)));
    db_merge('search_total')
      ->key(array('word' => $word))
      ->fields(array('count' => $total))
      ->execute();
  }
  // Find words that were deleted from search_index, but are still in
  // search_total. We use a LEFT JOIN between the two tables and keep only the
  // rows which fail to join.
  $result = db_query("SELECT t.word AS realword, i.word FROM {search_total} t LEFT JOIN {search_index} i ON t.word = i.word WHERE i.word IS NULL", array(), array('target' => 'slave'));
  $or = db_or();
  foreach ($result as $word) {
    $or->condition('word', $word->realword);
  }
  if (count($or) > 0) {
    db_delete('search_total')
      ->condition($or)
      ->execute();
  }
}
?>