Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
How can I stop specific CCK fields from showing up in search results?
I have a simple drop box for the edited status of a node with the options 'Draft, To be edited, Edited' and so on. As you might guess, this is not shown on the final published node. Unfortunately, whenever you search for words near the beginning of the node, it'll return something like this:
Original Node Title Goes Wild
Status: No changes; ready Here begins the node's written content...
I'd rather it didn't. Is this possible?
Comments
Comment #1
meatbites CreditAttribution: meatbites commentedI found a way to get exactly what I'm after, but I was forced to modify node.module.
Basically, you need to disable indexing of the CCK field and stop the search result from showing the field as text padding. Unfortunately, hacking core seems to be the only option for this.
Modified node_search function (near the end of case 'search'):
Modified node_update_index function:
So, I guess this is a feature request.
Comment #2
kardave CreditAttribution: kardave commentedHey, this feature's opposit is what i need :)
I would like hidden CCK field to show up in search results.
I use CCK fields for subtitles, and IDs for big amount imported stories.
These fields are set to hidden, but shown by my custom theme, except the imported stories' previous IDs.
I made this old id field just to let visitors find the old articles. (search404 module).
Until I can't set CCK fields to have indexed or not, I must do the known CSS hide trick.
(set the fiels to visible, but hide by css)
Thanks your work so much!
K. David
Comment #3
TimeBandit CreditAttribution: TimeBandit commentedYou could consider using the Views Fast Search module to help modify search: http://drupal.org/project/views_fastsearch
Then use phptemplate_views_fastsearch_display function in template.php and you won't have to modify node.module.
example (after installing and setting up fast search):
I also changed the results to an ordered list so you may want to use the original function from views_fastsearch.module...
Comment #4
deltab CreditAttribution: deltab commented+1
Comment #5
nally CreditAttribution: nally commentedHas anyone made any progress with this issue?
Presumably, having the search system ignore certain fields could make for a lighter, faster search.
Also, can anyone with specific search expertise mention anything on the possibility of having a search index for each role?
Also, in particular, are we still only talking about D5?
Comment #6
TimeBandit CreditAttribution: TimeBandit commentedI did the following in a more recent project. I don't use fastsearch any longer, and this is for Drupal 6. It basically disregards the actual search result ($snippet variable) and looks at the item's body['#value']. Then I strip out carriage returns, spaces, yadda. Your mileage may vary... you may need to strip other stuff out of the result.
Put this in search-result.tpl.php in your theme. Of course, I have extraneous code and commented-out code so clean it up as you need to:
Comment #7
nally CreditAttribution: nally commentedThanks TimeBandit.
I'm interested in the possibility of preventing (specific, certain) CCK fields from being indexed at all.
Is it true that your solution filters search hits out at theme time? I'm looking for something that would keep that node out of the search result set in the first place by preventing that field from being in the search index at all.
(I'm also trying to get that to work with Solr integration.)
Comment #8
Gerhard Killesreiter CreditAttribution: Gerhard Killesreiter commentedCCK has a setting for this:
Go to your content type, then "display fields", then "search", and then you can chose whether fields should be excluded during indexing and/or display.
Comment #10
ceci123 CreditAttribution: ceci123 commentedI tried this solution and it doesn't work. See My configuration.
Am I don't it right?