I just talked to a client today who's using several node types internally to store information about users; one of these types is accessible to visitors who browse directly to the page, but tends to spam the search results whenever certain common phrases are searched on.

They need to hide specific node types from the search index, and have been running a patched copy of node.module to accomplish this. I'm not sure there's any way to do this without hacking core currently, so I thought I'd roll a quick patch for it.

CommentFileSizeAuthor
search_skip_types.patch1.9 KBeaton

Comments

catch’s picture

This applies cleanly and works for me. I think it's RTBC but wouldn't hurt to have another set of eyes look over it. With node profile modules etc. this would be a very useful thing to have.

nedjo’s picture

Status: Needs review » Needs work

We do indeed need the ability to exclude content from search. We can do so currently through tricky uses of hook_db_rewrite_sql(), but it's clunky due to the non-standard way that node_search() invokes db_rewrite_sql():


list($join1, $where1) = _db_rewrite_sql();

Another non-patch alternative is a theme override that selectively skips rendering, but again this is clunky.

This patch is a good start, but I see two issues:

1. It doesn't provide flexibility. Often we might wish to filter search presentation by other than node type.

2. The approach skips results after they are loaded. Presumably this means (a) unneeded processing to load the skipped result and (b) the number of results will be incorrect, e.g. twenty results will be loaded but only 17 presented, an issue that will affect pagination as well.

So the case needs some more thought. For now, hook_db_rewrite_sql() may be our best tool, See the related issue here:
http://drupal.org/node/54622, "Stop avoiding db_rewrite_sql() in node_search()". If that covers the case, we can mark this new issue as a duplicate.

eaton’s picture

1. It doesn't provide flexibility. Often we might wish to filter search presentation by other than node type.

Agreed, though I have the feeling that doing so would mean monkeying around much, much deeper in the system than anyone wants to at the moment. I wasn't aware of the sql rewrite approach, but I think that it -- combined with some hook_form_alter magic to keep those content types off the advanced search screen -- should help the client do this without hacking core.

douggreen’s picture

With no changes to core today, if you used hook_nodeapi 'search result' and simply set $node to null or something like that, you'd almost get what you want.

Can't you do this with a less intrusive patch by simply adding an argument or changing the returns from hook_nodeapi 'search result'?

robertdouglass’s picture

Version: 6.x-dev » 7.x-dev
catch’s picture

Status: Needs work » Closed (duplicate)

Marking as duplicate of http://drupal.org/node/111744