Drupal:hook_search 仅适用于内容类型

发布于 2024-10-15 09:19:36 字数 178 浏览 6 评论 0原文

我想在 Drupal 6 中构建一个自定义搜索模块,用于通过 CCK 进行搜索。我需要用户在其节点 (node.uid=x) 和某种类型 (type='xyz') 之间进行搜索。我想我必须实现 hook_search 但我不知道在哪里放置我的过滤器。谁能帮助我吗?

I would like to build a custom search module in Drupal 6 for searching through CCK. I need the user to search between his nodes (node.uid=x) and of a certain type (type='xyz'). I think I have to implement hook_search but I don't know where to put my filters. Can anyone help me?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

初相遇 2024-10-22 09:19:36

您已经接受了答案(这可能是您的最佳选择),但是还有一些其他方法可以实现此目的。

IIRC,自定义搜索模块将满足您的需求。

您可以将库存 hook_search 函数复制到自定义模块并修改查询。您可以执行以下操作:


// ...
case 'search':
    // Build matching conditions
    list($join1, $where1) = _db_rewrite_sql();
    $arguments1 = array();
    $conditions1 = 'n.status = 1';

    // NEW BIT START
    $allowed = array(
        'content_type_1',
        'content_type_2',
        'content_type_3',
    );

    $types = array();
    foreach ($allowed as $t) {
        $types[] = "n.type = '%s'";
        $arguments1[] = $t;
    }
    $conditions1 .= ' AND ('. implode(' OR ', $types) .')';
    $keys = search_query_insert($keys, 'type');
    // NEW BIT END

这会替换从实际查询字符串中提取类型的位。

您必须添加该位才能重构为特定的n.uid。我最近一直在使用这种方法,而不是自定义搜索,因为从用户的角度来看它更简单。

华泰

You already accepted an answer (which is probably the best option for you), but there are a few other ways to accomplish this.

IIRC, the Custom Search module will work for what you want.

You can copy the stock hook_search function to a custom module and modify the query. You can do something like this:


// ...
case 'search':
    // Build matching conditions
    list($join1, $where1) = _db_rewrite_sql();
    $arguments1 = array();
    $conditions1 = 'n.status = 1';

    // NEW BIT START
    $allowed = array(
        'content_type_1',
        'content_type_2',
        'content_type_3',
    );

    $types = array();
    foreach ($allowed as $t) {
        $types[] = "n.type = '%s'";
        $arguments1[] = $t;
    }
    $conditions1 .= ' AND ('. implode(' OR ', $types) .')';
    $keys = search_query_insert($keys, 'type');
    // NEW BIT END

This replaces the bit that extracts the type from the actual query string.

You would have to add in the bit to restruct to a particular n.uid. I have been using this method lately, rather that Custom Search, because it simpler from the user's perspective.

HTH

帅的被狗咬 2024-10-22 09:19:36

您可以尝试使用公开的过滤器创建视图,这绝对是实现您的想法的最简单方法。

You might try creating a Views with an exposed filter, it's the absolute easiest way to implementing your idea.

云归处 2024-10-22 09:19:36

您也可以尝试使用CCK Facets。但是视图——当然很简单。

Also you can try use CCK Facets. But Views - of course simple.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文