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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Anonymous’s picture

I 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?

Steven’s picture

Sorry, that was me.

Eric Scouten’s picture

Actually, 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:

  • node's creation date, not the last updated date
  • node's teaser, not the text near the search term match
  • thumbnail for image nodes

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:

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.

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.

Eric Scouten’s picture

Component: page.module » node.module

Correcting version & component tags. Not sure how it got the wrong info to begin with.

killes@www.drop.org’s picture

Doesn't apply anymore.

Eric Scouten’s picture

Status: Active » Needs review

Updating patch. (It's just a one-liner, BTW... can it be that hard to figure out if node.module changes again?)

Eric Scouten’s picture

FileSize
788 bytes

Once again... in unidiff format.

Crell’s picture

Status: Needs review » Closed (fixed)

Patch 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.