Hi,
I brought to the developer of the FuzzySearch module that there is a hook in TopSearch module that allows other modules to send their data as well, but he could not find it. Can you please refer to this issue?
Thanks.

Comments

z.stolar’s picture

Title: Fuzzy Search » Fuzzy Search implementation of hook_top_searches
Category: feature » support
Status: Active » Fixed

Please refer to the function top_searches_top_searches in top_searches.module
Let me know if this is sufficient.

VTM’s picture

Project: Top Searches » Fuzzy Search
Version: 6.x-1.0-rc3 » 6.x-1.4
Status: Fixed » Needs review

#awolfey
Can you review?

awolfey’s picture

Project: Fuzzy Search » Top Searches
Version: 6.x-1.4 » 6.x-1.1

Yes, I saw that function, but it's not a hook. It's an api function. It looks like it might be implementing its own hook_top_search, but that is never invoked.

What I would suggest for the top searches module is to implement hook_watchdog because that, with only a small piece of code, is like to to gain access immediately to most search modules, rather than needing each search module to call top_search_top_search().

Additionally, hook_watchdog gives you access to everything you need to create some kind of flood or gaming prevetion: user object, IP address, timestamp, uri, etc.

Not tested:

<?php
function top_searches_watchdog($log_entry) {
    // Check what the search modules use for $type and add them here.
    $modules = array('fuzzysearch', 'search', 'etc.'); 
    if (in_array($log_entry['type'], $modules)) {
      
      // You may have to do some wrangling to get the keys for all search modules. 
      //This is what you would do for fuzzysearch.
      $keys = $log_entry['variables']['%query']; 
      
      // You could pass $user or anything else from $log_entry that you need.
      top_searches_process_keys($keys); 
    }
}
?>

I'm going to move this to the top searches queue. This is really the way to do it I think.