Hello,
I was wondering if there is a way to avoid some content from being indexed
(like excluding some node types from search).

Thanks in advance
cheers~

Comments

elruy’s picture

I have some content types that should not be displayed independently (only in certain views.) Hence I don't want users to be able to get to those contents via search.
How to avoid indexing them?

Anonymous’s picture

The way I achieved this is by adding a condition in the results theming function. There is however a problem with this approach (see below).

function phptemplate_search_item($item, $type) {
  // Here are the content-type you do not want to see showing up in the search results.
  $nodisplay = array('type1', 'type2');
  
  // will return no output if there is a match
  foreach($nodisplay as $skip) {
    if($item['type'] == $skip) {
      return;  
    } 
  }
  
  // returns $output is the content-type is not in the $nodisplay array
  [... default or cutom item theming code ...]
  return $output;
}

This code goes in phptemplate.php.

So really, it doesn't prevent the indexation but it prevents the results from showing up.

There is one serious caveat to this approach: even if an item is not returned, the search results will count it as an item. So, if you use a pager that displays 10 items per page, you may end up with a page that displays 5 results (5 'hidden'), another 3, another none. If anyone has a solution for this - besides hacking the search module and removing the pager - it would definitely be appreciated!

F

jmlavarenne’s picture

When I use this function (using 5.7), I get only unpublished results for nodes of all type, even if I only specified one type in the array.

Edit - it's because I need to add the theming - output etc ... thanks!

Bevan’s picture

Here's a solution to this with a patch http://drupal.org/node/111744