By n1nja on
Hi,
Does anyone know how to hide content from Drupal's search results?
There's some pages that I don't want to be indexed, but still accessible for those who have the link.
I'm thinking it could be done with the robots.txt file, but I'm not sure if it affects Drupal's search feature, since it only mentions search engines like Yahoo.
Any help would be appreciated
Comments
=-=
incorrect advice, misread question
no, not robots.txt
No, robots.txt can be used to tell search engines to ignore certain pages (or even whole sections) in your site.
It has nothing to do with which pages will be returned if you use the "drupal search" feature.
I don't know how to do what you want, but robots.txt is 100% *not* the answer.
thanks, I had a feeling it
thanks, I had a feeling it wasn't.
I'm thinking search.module will need some modifications.
This may help
This post shows how to restrict search to certain node types. Could be just what you're after.
Edit: My original post on how to do this was deleted and I have had several requests for this "fix", so here is how I did it:
Simply edit your search.module file and add the following 2 lines to the do_search() function, after the "$query = search_parse_query($keywords);" line:
This will ensure that the search only returns page or book nodes. Modify the node types as required.
Would like to see this expand
This might be a good add on module for search such that someone could see all node types in the search settings and pick which ones they allow the search module to index.
filter vocabs & c-types in settings
if you want admin to select vocabularies or content-types which would be omitted from the user-view of the advanced search fieldset
try http://drupal.org/project/trip_search
it certainly used to do this at 4.6.
Restricting search to certain node types in 4.6
I got this to work by adding the following single line right at the beginning of the do_search function:
$where .= " AND (n.type = 'page' OR n.type = 'book')";Variable $join already seems to have the INNER JOIN on the {node} table included.
There are probably better ways of doing this e.g. using the SQL search (Trip search) module ...
gpk
----
www.alexoria.co.uk
hide quizzes from drupal search
This worked great to hide quizzes and quiz questions from drupal search. I modified above code to say this...
$join1 = "INNER JOIN {node} n ON n.nid = i.sid";
$where1 = "(n.type != 'quiz' AND n.type != 'multichoice')";
Content Template (contemplate)
Content Template (contemplate) Module for Drupal
by Jeff Robbins | Lullabot | www.lullabot.com
i'm using this one. setting empty template for certain content type do the job.
and i've heard something about "different templates per taxonomy term"?
don't retrieve vs. don't index?
I've been looking for this capability as well, and the patch above does the trick for me. But there's part of me that things it would be better to handle this on the front end and block certain node types from getting into the index in the first place. This would keep the size of the index down, simplify the retrieval calls to the database, etc.
I've made a couple of attempts to do this by defining update_index and nodeapi hooks for the modules I want to keep out, but I've never been able to get it to work. Does this approach make sense? Thoughts?
<noindex> tag or param for hiding content from drupal search?
how about some kind of wrappable html tag or parameter for content not intended for drupal's own search indexing; i'm looking for something like this, since in my case these nodes are allready hidden from anonymous users (spiders, robots) from the start, using taxonomy_access..
something like:
blah blah normal indexable text but alas, what's this, <span noindex>drupal wouldn't index this here text</span> and then back to indexable text..
would be perfect, if it's not somehow allready possible..
or i guess since span isn't a normally allowed html tag, perhaps a custom tag that is stripped when rendered (for better standards compliance)..?
incidentally i'm using drupal 5, but the subject of the original thread is also what i too am after; tho perhaps more accurately "How do you hide some of a node's content from Drupal's search results?"
Reviving this thread to see
Reviving this thread to see if there is a clean way to add the no-index, no-follow, noarchive meta tags per content type?
No Archive Option
I am thinking that something like a "no archive" option would be smart for administrators both on an individual node level and in some administrative way where one can tell search not to index a certain node type.
Anyway, my two cents..
---
Shane Birley
Left Right Minds
http://www.leftrightminds.com
---
Shane Birley
Left Right Minds
https://www.leftrightminds.com
The right way to do it
Below you can find the correct way to force a certain type to be searched without having to modify the core modules. Enjoy, comments in code. In this snippet it forces a certain type, but can be modified to add more criteria if needed that will force content to not be displayed.
sjlacroix, mad props to you
sjlacroix, mad props to you for that bit of code -- it does exactly what I was looking for, and of course it's always good to find solutions that don't involve hacking core. You just saved me quite a bit of time.
great stuff
sjlacroix, thanks! just what I was looking for.
you are great!! thank you
you are great!! thank you very very very much your your code!
Also see
Also see http://www.lullabot.com/articles/hiding-content-drupals-search-system.
gpk
----
www.alexoria.co.uk
gpk
----
www.alexoria.co.uk
Module Available
There is a module available that will now allow you to restrict the results to particular content types - and also hide options from the "advanced search"
http://drupal.org/project/search_config
Also
Also http://drupal.org/project/search_restrict (currently for 5.x and 6.x) is a handy simple module that lets you define, on a per content type basis, which roles can have content of that type included in their search results.. very useful if you want admin to get all results but ordinary users a subset. Of course you could always use node access control to do something similar but there might be situations in which you don't want to do it that way.
gpk
----
www.alexoria.co.uk
Try - search restrict
Try - search restrict module
http://drupal.org/project/search_restrict
(sorry did not see prev. post)
Its that easy
that I needed a whole day to figure out. The important hint I found in the code was
The node_build_content function is "hooked" to hook_nodeapi ($op = 'view'). What does this mean?
To hide (node) content from the search index only a short piece of code in a custom module foo is necessary:
All the text between the tag <noindex> and </noindex> would not be indexed because Drupal's search indexer can't see it. Nevertheless the text is displayed on normal node view.
There is any possibility to code further restrictions and tamper other node fields.