简体   繁体   English

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

[英]Combining multiple content types into a single search result with Drupal 6 and Views 2

I need to create a somewhat advanced search functionality for my Drupal 6 site. 我需要为我的Drupal 6网站创建一个稍微高级的搜索功能。 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. 我有内容类型TypeX和TypeY。 TypeY has a node reference CCK field that relates it to a single node of TypeX. TypeY具有节点引用CCK字段,该字段将其与TypeX的单个节点相关联。 So, many nodes of TypeY reference the same node of TypeX. 因此,TypeY的许多节点都引用TypeX的相同节点。

I want to use Views 2 to create a search page for these nodes. 我想使用Views 2为这些节点创建搜索页面。 I want each search result to be a node of TypeX, along with all the nodes of TypeY that reference it. 我希望每个搜索结果都是TypeX的一个节点,以及所有引用它的TypeY的节点。 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. 我知道我可以仅对单个结果进行主题设置,并使用视图将TypeY的节点添加到TypeX的单个节点中...但是那将不允许用户实际搜索TypeY ...它只会搜索TypeX并仅显示TypeY的一些节点。

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? 无论如何,是否有要使两种内容类型的节点中都包含内容的搜索,但是将TypeY结果合并到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. 或者,如果我搜索了“ TypeX节点中的内容”,则上面的搜索结果相同。

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. 我知道我可以搜索TypeX并使用另一个视图在结果显示中加载TypeY节点,但是它不会搜索TypeY节点中的内容。

Any ideas... short of rolling my own search functionality (not something I'd like to do at the moment)? 有什么主意...除了推出自己的搜索功能(目前还不想做)之外?

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 文章在这里: 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 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. 事实证明,编写CCK的好人已经考虑过索引引用节点的内容。 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. 剩下要做的唯一一件事(戴维解释)是确保每当引用节点的内容发生更改时,父节点都将重新索引。

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). 您还可以在输出过程中从列表中简单地省略内容类型Y,并在主题中指定内容类型X节点以从CCK节点引用字段中列出节点(这与您提到的内容类似,但是您仍将内容类型Y保留在视图查询,并在输出过程中将其忽略)。 There might be some performance implications depending on the amount of content type Y nodes per content type X nodes there are. 可能会有一些性能影响,具体取决于每个内容类型X节点的内容类型Y节点的数量。

I think no matter what you end up doing this will be a theme issue albeit a complex one. 我认为,无论您最终要做什么,这都是一个主题问题,尽管很复杂。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM