Restrict Search To Certain Content Types Only

Problem:

On a Drupal site, I want to restrict the search to a certain content type only. To avoid creating confusion for the user, I also want this to happening in the background (ie hidden). I also to not want to the advanced search turn on since it would expose everything to the user...

This post is interesting: Custom search box for a specific content type

But exposes everything...

Solution:

The only way I found to do this is to modify the node.module file by adding the text in red (located around line 839 in Drupal 5.1)

/**
* Implementation of hook_search().
*/
function node_search($op = 'search', $keys = NULL) {
.../...
 case 'search':
// Build matching conditions
list($join1, $where1) = _db_rewrite_sql();
$arguments1 = array();
$conditions1 = 'n.status = 1 AND n.type = \'directory_entry\'';

if ($type = search_query_extract($keys, 'type')) {

.../...

Note: You should maintain a file like "my_changes.txt" were you log all your changes to Drupal core files, in order to be able to quickly redo these changes when you upgrade Drupal. You should only make changes to Drupal core files when no other alternatives are available (which is rare).