Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
As currently defined node.module's search hook doesn't provide enough information to allow a rich rendering of search results. For instance, in a photographic web site, I'd like the search results to show a thumbnail of each matched image. I can't do this without access to the node object.
The attached one-line patch provides access to the node object in the search results.
Comment | File | Size | Author |
---|---|---|---|
#7 | node.module_10.patch | 788 bytes | Eric Scouten |
node_search_hook.patch | 719 bytes | Eric Scouten | |
Comments
Comment #1
(not verified) CreditAttribution: commentedI assume you want the $node object in theme('search_item').
Another possibility is to change nodeapi('search result') so it can add custom fields to the $item array rather than just being for adding textual information to the result by-line. That way, the image.module could add a 'thumbnail' field, which can be displayed in the theme.
The problem really is: does presentation of the search result belong in the theme or in the modules? I'd like to avoid putting features like search thumbnails in a theme, as a thumbnail adds more information rather than just changing the way something is presented.
The current search API is still a bit of a mess, mostly because I focused on functionality of the content search, and just did a minor cleanup of the API code in my patch. Perhaps more invasive changes are needed to allow truly rich search results?
Comment #2
Steven CreditAttribution: Steven commentedSorry, that was me.
Comment #3
Eric Scouten CreditAttribution: Eric Scouten commentedActually, for the particular site I was designing (not yet visible on the Internet), I needed several pieces of information that were not available to the search hook:
I wouldn't expect the way I'm rendering search results to be desirable for most sites, but it makes sense for this site, and the easiest way to accomplish the desired rendering was to have the theme render the node teaser rather than doing all kinds of image-specific additions.
I suspect I won't be alone in wanting to do node-specific rendering of search results, so it seems reasonable IMHO to add the $node object to the set of information provided for theme('search_item'). The attached patch does exactly that and nothing more.
You wrote:
As a matter of general principle, I agree with your argument that Drupal as a whole is cleaner if the core (or the relevant node module) does the heavy lifting of presenting search results and I am not submitting any theme that would violate that principle. However, if you're saying that Drupal should prevent a site designer from having enough information to override the search results when the default presentation isn't appropriate, then I strongly disagree with you.
Comment #4
Eric Scouten CreditAttribution: Eric Scouten commentedCorrecting version & component tags. Not sure how it got the wrong info to begin with.
Comment #5
killes@www.drop.org CreditAttribution: killes@www.drop.org commentedDoesn't apply anymore.
Comment #6
Eric Scouten CreditAttribution: Eric Scouten commentedUpdating patch. (It's just a one-liner, BTW... can it be that hard to figure out if node.module changes again?)
Comment #7
Eric Scouten CreditAttribution: Eric Scouten commentedOnce again... in unidiff format.
Comment #8
Crell CreditAttribution: Crell commentedPatch no longer applies. I suspect it's irrelevant now anyway since the search module has been so heavily rewritten since this thread was started. Setting to closed. If the problem is still present in the new search module, please reopen with a new patch. Thanks.