function search_log in Search Log 8
Same name and namespace in other branches
- 6 search_log.module \search_log()
- 7 search_log.module \search_log()
Store search keys, module, language and day.
Developers can call this function directly to add additional entries to the log or record failed searches (e.g. Lucene integration).
1 call to search_log()
- _search_log_preprocess_search_form in ./
search_log.module - Preprocess search form results before writing to DB.
1 string reference to 'search_log'
- search_log_uninstall in ./
search_log.install - Implements hook_uninstall().
File
- ./
search_log.module, line 177 - This module holds functions of Search Log Module.
Code
function search_log($keys, $module, $language = 'en', $counter = 1, $result = SEARCH_LOG_RESULT_UNKNOWN) {
$today = _search_log_get_time();
$keys = _search_log_normalize_keys($keys);
if (!$keys || !$module || !$language) {
return;
}
// If search_log_preprocess is enabled, the default is successful search.
if (!$result && \Drupal::config('search_log.settings')
->get('search_log_preprocess')) {
$result = SEARCH_LOG_RESULT_SUCCESS;
}
if ($qid = \Drupal::database()
->query("SELECT qid FROM {search_log} WHERE q = :q AND module = :module AND language = :language AND day = :day", array(
':q' => $keys,
':module' => $module,
':language' => $language,
':day' => $today,
))
->fetchField()) {
\Drupal::database()
->update('search_log')
->fields(array(
'result' => $result,
))
->expression('counter', 'counter + :counter', array(
':counter' => $counter,
))
->condition('qid', $qid)
->execute();
}
else {
\Drupal::database()
->insert('search_log')
->fields(array(
'q' => $keys,
'module' => $module,
'language' => $language,
'day' => $today,
'counter' => $counter,
'result' => $result,
))
->execute();
}
}