1

I need to modify the search results drupal generates to include selected content from some other D6 sister sites. hook_search seemed like the obvious choice, but when I implement it, it's never invoked with the keywords I'm searching for:

function nmc_xsearch_search( $op = 'search', $keys = NULL ) {

    switch ($op) {

        case 'name':
            return t('Content');
            return $form;

        case 'search':    
            dsm( "Operation: $op | Keys: $keys" );        
                return $results;
    }
}

When I walk through this code in the debugger, my function nmc_xsearch_search() is hit twice. The first time $op = 'name' and $keys = null. The second time $op = 'name' and $keys = '1'.

When I put a breakpoint on node_search it is invoked four times - all before my nmc_xsearch_search() is hit. The last time node_search is hit the provided parameters are: $op = 'search' and $keys = 'my search keywords'.

Basically I want my function to get the same invocation that node_search is getting so that I can access the keywords and modify the results array returned by hook_search. Any ideas?

1
  • To whoever briefly posted a helpful answer: please un-delete it, it was just what I needed.
    – doub1ejack
    Commented Jul 25, 2012 at 20:55

1 Answer 1

0

If you look at search_menu(), you will notice the following code.

  foreach (module_implements('search') as $name) {
    $items['search/' . $name . '/%menu_tail'] = array(
      'title callback' => 'module_invoke',
      'title arguments' => array($name, 'search', 'name', TRUE),
      'page callback' => 'search_view',
      'page arguments' => array($name),
      'access callback' => '_search_menu',
      'access arguments' => array($name),
      'type' => MENU_LOCAL_TASK,
      'parent' => 'search',
      'file' => 'search.pages.inc',
    );
  }

Every module implementing hook_search() gets a menu tab. So, your module will be asked to search only when the users select its tab.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.