简体   繁体   中英

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. 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)?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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