使用 Drupal 6 和 Views 2 将多种内容类型组合成单个搜索结果

发布于 2024-08-29 02:20:42 字数 1799 浏览 5 评论 0原文

我需要为我的 Drupal 6 站点创建一个稍微高级的搜索功能。我在两种内容类型之间存在一对多关系,需要在尊重这种关系的情况下搜索它们。

为了让事情更清楚......

我有内容类型 TypeX 和 TypeY。 TypeY 有一个节点引用 CCK 字段,将其与 TypeX 的单个节点相关联。因此,TypeY 的许多节点引用 TypeX 的同一节点。

我想使用 Views 2 为这些节点创建搜索页面。我希望每个搜索结果都是 TypeX 的一个节点,以及引用它的 TypeY 的所有节点。我知道我可以只对各个结果进行主题化,并使用视图将 TypeY 的节点添加到 TypeX 的单个节点...但这不会允许用户实际搜索 TypeY...它只会搜索 TypeX 并仅显示TypeY 的一些节点随之而来。

无论如何,是否可以让搜索考虑两种内容类型的节点中的内容,但将 TypeY 结果合并到 TypeX 的“父”节点中?

在数据库术语中,似乎我需要进行联接,然后按搜索词进行过滤。但我不知道如何在视图中执行此操作。

感谢我能得到的任何帮助!

'**** 编辑 '****

为了确保这一点清楚,这是我正在尝试执行的操作的直观示例...

_____________________________________________________________________________________
|Type X Node                           |Type Y Node                                  |
|                                      |                                             |
| Content in node of TypeX that gets   |Has a node reference that points to the node |
| searched by the view...              |of TypeX. This content gets searched too!    |
|                                      |_____________________________________________|
|                                      |Type Y Node                                  |
|                                      |                                             |
|                                      |Another TypeY node with a node reference to  |
|                                      |to the TypeX node. This gets searched too!   |
--------------------------------------------------------------------------------------

这将是搜索视图的单个结果。它们在所有三个节点中的内容将被视图中的“搜索:术语”过滤器考虑。因此,如果我搜索“这也被搜索了!”,我会得到上述结果。或者,如果我搜索“TypeX 节点中的内容”,我会得到与上面相同的搜索结果。

我知道我可以搜索 TypeX 并使用另一个视图在结果显示中加载 TypeY 节点,但它不会搜索 TypeY 节点中的内容。

有什么想法...除了推出我自己的搜索功能(目前不是我想做的事情)吗?

I need to create a somewhat advanced search functionality for my Drupal 6 site. I have a one-to-many relationship between two content types and need to search them, respecting that relationship.

To make things more clear...

I have content types TypeX and TypeY. TypeY has a node reference CCK field that relates it to a single node of TypeX. So, many nodes of TypeY reference the same node of TypeX.

I want to use Views 2 to create a search page for these nodes. I want each search result to be a node of TypeX, along with all the nodes of TypeY that reference it. I know I could just theme the individual results and use a view to add the nodes of TypeY to the single node of TypeX... but that won't allow users to actually search TypeY... it would only search TypeX and merely display some nodes of TypeY along with it.

Is there anyway to get the search to account for content in nodes of both content types, but merge the TypeY results into the "parent" node of TypeX?

In database terms, it seems like I need to do a join, then filter by the search terms. But I can't figure out how to do this in Views.

Thanks for any help i can get!!!

'**** EDIT '****

To make sure this is clear, here's a visual example of what I'm trying to do...

_____________________________________________________________________________________
|Type X Node                           |Type Y Node                                  |
|                                      |                                             |
| Content in node of TypeX that gets   |Has a node reference that points to the node |
| searched by the view...              |of TypeX. This content gets searched too!    |
|                                      |_____________________________________________|
|                                      |Type Y Node                                  |
|                                      |                                             |
|                                      |Another TypeY node with a node reference to  |
|                                      |to the TypeX node. This gets searched too!   |
--------------------------------------------------------------------------------------

This would be a single result from the search View. They content in all three nodes would be considered by the Search : Terms filter in the view. So if I searched for "This gets searched too!", I would get the above result. Or, if I searched "Content in node of TypeX", I'd get the same search result above.

I know I could search for TypeX and load up the TypeY nodes in the result display using another view, but it wouldn't search the content in the TypeY nodes.

Any ideas... short of rolling my own search functionality (not something I'd like to do at the moment)?

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

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

发布评论

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

评论(2

屋顶上的小猫咪 2024-09-05 02:20:42

哇,只是哇。我终于找到了解决这个问题的优雅方法。我简直不敢相信事情竟然如此简单!!!

我不会把这个解决方案归功于...我偶然发现了一篇很棒的博客文章,它完全回答了这个问题(甚至不再看了!)。这篇文章的作者是戴维,他是我的新英雄

文章在这里: http://www.drupalcoder.com/story/667-improving-search-results-when-working-with-node-references-in-drupal

他还写了一篇后续文章,甚至简化了流程更多的!! http://www.drupalcoder.com/story/696-a-better-alternative-for-improving-search-results-when-working-with-node-references-in-dru

事实证明,编写 CCK 的好人已经考虑过对引用节点的内容建立索引。在编辑内容类型的“显示字段”部分中,单击“搜索”选项!它允许您确定在对父节点建立索引时应如何对引用的节点建立索引...并且您可以将其设置为完整节点。这将索引引用节点的完整内容,作为索引父节点的一部分。剩下要做的唯一一件事(Davy 解释说)是确保每当引用节点的内容发生更改时都会重新索引父节点。

Wow, just wow. I finally found an elegant solution to this problem. I can't believe how simple it turns out to be!!!

I won't take credit for the solution... I stumbled upon a great blog post that answered this question completely (wasn't even looking anymore!). The article is by a guy name Davy, and he's my new hero.

The article is here: http://www.drupalcoder.com/story/667-improving-search-results-when-working-with-node-references-in-drupal

He also wrote a follow up article that simplifies the process even more!! http://www.drupalcoder.com/story/696-a-better-alternative-for-improving-search-results-when-working-with-node-references-in-dru

It turns out the good folks that wrote CCK had already thought of indexing a referenced node's content. In the Display Fields section of editing a content type, click on the Search option! It lets you determine how the referenced node should be indexed when the parent node is indexed... and you can set it to full node. This will index the full contents of the referenced node as part of indexing the parent node. The only thing left to do (which Davy explains) is to make sure the parent node gets reindexed whenever a referenced node's content changes.

属性 2024-09-05 02:20:42

如果您可以将您的视图扩展到搜索两种内容类型的地步,我认为这实际上确实成为一个主题问题。您可以覆盖视图的各种主题模板,并以特定方式组织返回的节点数组。您还可以在输出期间简单地从列表中省略内容类型 Y,并将内容类型 X 节点主题化以列出 CCK 节点引用字段中的节点(这与您提到的类似,但您仍然将内容类型 Y 保留在视图查询并在输出期间省略它)。可能会有一些性能影响,具体取决于每个内容类型 X 节点的内容类型 Y 节点的数量。

我认为无论你最终做什么,这都将是一个主题问题,尽管是一个复杂的问题。

Provided you can get your view to a point where it is searching both content types, I think this actually does become a theme issue. You could override the various theme templates for the view and organize the returned array of nodes in a particular way. You could also simply omit content type Y from the list during output and theme the content type X node to list the nodes from the CCK node reference field (this would be similar to what you mentioned, but you'd still leave content type Y in the view query and omit it during output). There might be some performance implications depending on the amount of content type Y nodes per content type X nodes there are.

I think no matter what you end up doing this will be a theme issue albeit a complex one.

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