By enky on
hi all,
is there a way to exclude nodes of a specific nodetype
from being indexing by the search module?
thanks,
enky
hi all,
is there a way to exclude nodes of a specific nodetype
from being indexing by the search module?
thanks,
enky
Comments
At the theme level
There may be other ways to do this but I have done it at the theme level before. In the example code below I've re-themed the _search_item() function with phptemplate in order to filter out image node types. Just place the folowing code between the
in your template.php file for the theme you're using. If there is not template.php file in that folder; create one.You can see I did more than just filter out the display of image nodes. I also reformatted how the search results were displayed. If you want to get really fancy, you can theme the display of each result differently by node type.
Also, by simply changing that first if statement to read
You could tell Drupal to only return results from that 'image' node type.
The one caveat to this method is that if you have node types 'foo' and 'bar' and are filtering out node type 'foo'... if the user's search finds only a result that matches a 'foo' type and none that match 'bar' it will display an empty result as opposed to letting the user know that there were no matches to the search. There is probably a work-around but I've not explored it yet.
Eric Lawrence
Developer/UX Designer
http://squaretone.com
hacking the node module
thanks ericelbow, i will try your solution,
will it be safe hacking the node.module to not to show certian nodetypes
on the search results?
enky
www.electros.in/blog/venkatesh
avoid hacking modules
I would avoid hacking modules whenever possible... especially core modules like node.module. When it comes time for security updates it will be painful to go back in and re-hack the updated module. When possible, use theming overrides instead like the one above.
One of the things that makes Drupal so great is how easily it allows developers to make modules themable. The example above takes advantage of the powerful theming engine - phptemplate in this case. If you use an override in your theme it will most likely still work if you upgrade your drupal site later and if you do something to mess it up you can just change themes until you fix it.
Check out this entry in the handbook on themeable functions in Drupal: http://drupal.org/node/11811
Eric Lawrence
Developer/UX Designer
http://squaretone.com
at theme level II
I first used squaretone's theme level based suggestion - but I have actually a second function in my phptemplate that is there for styling the results page - so I put the NOT-statement there.. which might also reduce the 'load' a bit cause I'm loading the 'theme('search_item', $entry, $type)' only when I have my 'other' content types....
here it comes:
greetings, till..
ps: I just realized that of course the content type IS case sensitive:
--> 'image' vs. 'Image'
___________________________
my pictures: www.bilderbook.org
___________________________
Here's how I've done it
I don't want customers in my basic CRM system to be found by regular users to the site. Hence, in one of my modules I've implemented this code (note, it may be important for my module to come after node.module in the module list):
And to remove the customer checkbox from the advanced search options, add this to your module:
Following the next cron run, the customers are no longer shown in the search results.
Jake
---
School and university yearbooks and Drupal web services, London
Works for me
Using hook_update_index works for me! Thanks for the tip. By the way, I don't think it matters what order the modules are called for this. It appears this is just dropping the specified nodes from the index. It also appears to be called *after* the index is rebuilt by cron (most likely for just this reason.)
hope this works
I'm hoping this will work for me too.
Can that function be put in a module on its own, and is this example for 4.7?
Also, how would the query be written to remove multiple content types?
My sql knowledge is a bit basic.
Mark
search_config
The search_config module is currently testing a patch with this exact feature.
See http://drupal.org/node/170605
You can help test by trying the dev module http://drupal.org/node/175520
Work for Drupal 6.16
Thanks for the solution. It simply work
Hmm...
I think this is wrong. It looks like this causes the search status to never reach 100%.
Change the while loop code:
NancyDru
Here's a good solution to
Here's a good solution to this http://drupal.org/node/111744
Bevan/