function search_data($keys = NULL, $type = 'node') {
// $keys 需要搜索的关键字
// $type 搜索的类型
  if (isset($keys)) {
    if (module_hook($type, 'search')) {
      //寻找对应module中的hook_search并调用返回结果
      $results = module_invoke($type, 'search','search', $keys);
      if (isset($results) &&is_array($results) && count($results)) {
        if (module_hook($type, 'search_page')){
          // 结果以module中的hook_search_page呈现
          return module_invoke($type,'search_page', $results);
        }
        else {
          // 结果以search_results呈现
          return theme('search_results',$results, $type);
        }
      }
    }
  }
}

 

从以上代码可以得知,只要在module中实现hook_ssearch,就可以实现自定义搜索功能。如果有需求,可以在module实现hook_search_page来定制结果输出模板。

相关文章:

  • 2021-05-19
  • 2021-05-30
  • 2022-02-03
  • 2022-12-23
  • 2021-11-20
  • 2021-12-06
  • 2021-04-25
猜你喜欢
  • 2021-11-12
  • 2021-03-31
  • 2021-07-19
  • 2023-02-11
  • 2021-08-04
  • 2021-06-09
  • 2021-08-31
相关资源
相似解决方案