搜索自定义条件

Ale*_*tin 2 drupal drupal-7 drupal-search

如何向默认搜索模块添加条件?

我想在节点中添加一个名为"允许搜索"的复选框字段,未检查的项目将不会显示在搜索结果中.

扩展Drupal 7搜索似乎是我的解决方案,但我无法使其工作; hook_search_execute()没有执行.

你能解释一下为什么会这样吗?

kia*_*uno 6

您需要先在admin/config/search/settings上选择模块,并可能在"Active search modules"中取消选择Node模块.如果未在那里选择模块,则不会调用钩子.

截图

至于调用一个钩子并且没有调用一个钩子的原因,search_get_info()执行的代码(search_menu()调用的函数构建搜索菜单)首先调用每个实现hook_search_info(),然后检查哪些模块搜索集成已启用.由于您的模块未启用搜索集成,hook_search_execute()因此永远不会调用您的模块.

  if (!isset($search_hooks)) {
    foreach (module_implements('search_info') as $module) {
      $search_hooks[$module] = call_user_func($module . '_search_info');
      // Use module name as the default value.
      $search_hooks[$module] += array(
        'title' => $module,
        'path' => $module,
      );
      // Include the module name itself in the array.
      $search_hooks[$module]['module'] = $module;
    }
  }

  if ($all) {
    return $search_hooks;
  }

  $active = variable_get('search_active_modules', array('node', 'user'));
  return array_intersect_key($search_hooks, array_flip($active));
Run Code Online (Sandbox Code Playgroud)