Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
As it is right now, you can't define multiple search types per module, you must have a seperate module for every search type you'd like.....
function hook_search($op = 'search', $keys = null) {
switch ($op) {
case 'name':
return t('content');
case 'reset':
variable_del('node_cron_last');
return;
case 'search':
$find = do_search($keys, 'node', 'INNER JOIN {node} n ON n.nid = i.sid '. node_access_join_sql() .' INNER JOIN {users} u ON n.uid = u.uid', 'n.status = 1 AND '. node_access_where_sql());
$results = array();
foreach ($find as $item) {
$node = node_load(array('nid' => $item));
$extra = node_invoke_nodeapi($node, 'search result');
$results[] = array('link' => url('node/'. $item),
'type' => node_invoke($node, 'node_name'),
'title' => $node->title,
'user' => theme('username', $node),
'date' => $node->changed,
'extra' => $extra,
'snippet' => search_excerpt($keys, check_output($node->body, $node->format)));
}
return $results;
}
}
We can only declare one search type....
Comments
Comment #1
robertDouglass CreditAttribution: robertDouglass commentedRelated issue that suggests the path and the searches available should be returned as structured data:
http://drupal.org/node/237747
Comment #2
jhodgdonI think this is a great idea, but it will need to wait until Drupal 8.
Comment #3
cpliakas CreditAttribution: cpliakas commentedJust an FYI, I am doing work on this in my D8 sandbox at #1262140: Allow for a module to define multiple search pages and indexes. Once it is ready for a patch, I will post here.
Comment #4
jhodgdonThis frequently-requested feature is taken care of by
#2003482: Convert hook_search_info to plugin system