search_api_stats.module 956 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. /**
  3. * @file
  4. * search_api_stats.module
  5. */
  6. /**
  7. * Implements hook_search_api_query_alter($query).
  8. *
  9. * @param SearchApiQueryInterface $query
  10. * The SearchApiQueryInterface object representing the search query.
  11. */
  12. function search_api_stats_search_api_query_alter(SearchApiQueryInterface $query) {
  13. global $user;
  14. // Assign some object variables to avoid chained member access.
  15. $index = $query->getIndex();
  16. if (!empty($index)) {
  17. $server = $index->server();
  18. }
  19. // Fail out if there's no valid index or server objects to work from.
  20. if (empty($index) || empty($server)) {
  21. return;
  22. }
  23. $log = array(
  24. 's_name' => $server->machine_name,
  25. 'i_name' => $index->machine_name,
  26. 'timestamp' => REQUEST_TIME,
  27. 'uid' => $user->uid,
  28. 'sid' => session_id(),
  29. 'keywords' => trim(drupal_strtolower($query->getOriginalKeys())),
  30. 'filters' => '',
  31. 'sort' => '',
  32. );
  33. drupal_write_record('search_api_stats', $log);
  34. }