I have a custom node type/module called "summaries" that I'd like to exclude from all search results. I see ways to get my module included in the search api docs, but how do I exclude a specific node->type?

Search http://www.realself.com for Microdermabrasion and the 9th result down you'll see "summaries" - this is only supposed to be visible to editors/admins. The access permissions are setup correctly.

Seems like a nice addition to search, to not just show all things visible, but let admins decide which node types to show via a checkbox ui.

Thanks!
-Greg

AttachmentSize
search_exclude_node.patch1.57 KB

Comments

greg@beargroup.com’s picture

Opened up the search.module and added this to the top of the theme function. Prevents the summaries node type from displaying in search results (could substitute a number of other criteria to exclude). Doesn't prevent it from being indexed of course, & have to remember to upgrade - so not the right solution, but served an immediate need.

function theme_search_item($item, $type) {
  if ($item['type'] == 'summaries') {
	return;		  
  }
robertDouglass’s picture

Each module is responsible for injecting its own content into the search index, thus the node module is responsible for injecting all node content. To do this, the search module calls a hook_update_index to get the content that should be indexed. The node module implementation is, naturally, node_update_index. There you see the query that selects all of the node content for indexing. I simply added a AND != 'mytype' to the query, which you can see in the patch. The patch is against 4.7, but if you study the query just a bit you'll be able to backport it to 4.6. This could also be the basis for the functionality where you exclude content from the search.

In the end, though, I don't see why you would want this. If the content is visible on the site, it seems counterintuitive to not make it searchable. If you need targeted search, I would write a module just to provide that before I hacked node.module with the above patch.

- Robert Douglass

-----
My Drupal book: Building Online Communities with Drupal, phpBB and WordPress

greg@beargroup.com’s picture

Appreciate the patch, works like a charm. I'll go buy a copy of your book! :)

To your comment in 2nd paragraph - My issue is that I have modules that contain reports and special all-up views of content that are not intended for normal registered or unregistered site users. Perhaps this is a feature request, but shouldn't search only include node types in its results that a particular user has access rights to see? Not just everything that is visible, rather everthing visible to the current users access privleges.

robertDouglass’s picture

If it isn't then there is a bug somewhere. Identifying this bug is a better solution than my patch.

- Robert Douglass

-----
My Drupal book: Building Online Communities with Drupal, phpBB and WordPress