Multiple Search Tabs Per Module

Rob Loach - March 26, 2008 - 22:16
Project:Drupal
Version:7.x-dev
Component:search.module
Category:feature request
Priority:normal
Assigned:Unassigned
Status:active
Description

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.....

hook_search:

<?php
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....

#1

robertDouglass - April 10, 2008 - 13:44

Related issue that suggests the path and the searches available should be returned as structured data:
http://drupal.org/node/237747

 
 

Drupal is a registered trademark of Dries Buytaert.