Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Would it be possible (or useful) to have a Rabbit Hole setting to hide from the core search results?
Comment | File | Size | Author |
---|---|---|---|
#20 | hide_from_search_results-1468302-20.patch | 2.05 KB | BWPanda |
#18 | hide_from_search_results-1468302-18.patch | 2.32 KB | BWPanda |
Comments
Comment #1
olofbokedal CreditAttribution: olofbokedal commentedThat would absolutely be useful.
Don't know right away how to solve it, but I'll look into it.
Comment #2
no2e CreditAttribution: no2e commentedUsually you'd control the search index with its own display under 'Manage Display'.
Should such a Rabbit Hole setting take control of or overwrite this display?
Comment #3
olofbokedal CreditAttribution: olofbokedal commentedI can't think of the best solution from the top of my head. I don't want to add any settings since this would clutter the interface a bit.. But at the same time, I don't want to mess with the display settings.
I'll figure something out. Feel free to discuss any solutions in the mean time :)
Comment #4
aleksey.tk CreditAttribution: aleksey.tk commentedI'm not sure that it is a useful addition, as:
1. It will clutter the interface (i agree with ojahansson)
2. Normally you're doing this kind of thing in different places, settings, etc.
Comment #5
olofbokedal CreditAttribution: olofbokedal commentedAfter some really heavy thinking, I've came up with the brilliant idea that this wouldn't need an extra setting in the interface. We could be quite certain that if a visitor shouldn't be able to view the node, it should automatically be removed from the search results.
I haven't looked at the Search module, so I don't know how to accomplish this, but it shouldn't be impossible.
Comment #6
olofbokedal CreditAttribution: olofbokedal commentedOk, I've created an (ugly) solution.
I couldn't find any clean way to alter the search results. It seems that the only clean way is to modify the query before it is executed, which seems, well, way more difficult than it should be.
So, I've implemented
template_preprocess_search_results()
which will alter the variables before thesearch-results.tpl.php
prints the results.The nodes are indeed being removed, but this isn't a solution that I'm proud of, but it works.
There are no extra configurations necessary.
I think this should be evaluated and tested on more sites before this could be ported to Drupal 6. So I'll mark this as fixed for now, but anyone's free to re-open this if any errors occurs.
http://drupalcode.org/project/rabbit_hole.git/commit/24b71b2
Comment #8
leenwebb CreditAttribution: leenwebb commentedThis code works fine on my site, but I extended it a bit so if the page is redirecting the search result shows up with a listing going to the redirected page. My use case is that some of my content types are only displayed in Views and anyone trying to look at the node directly gets redirected to the appropriate view. I want the same thing to happen for search results.
In the search_results function ~line 315:
Not sure if this should become part of the official module (other use cases might not work as well) but I figured I'd put it up here in case someone else needs the same thing.
Comment #9
awolfey CreditAttribution: awolfey commentedI think #8 is better than simply removing the results, which would probably confuse or break the pager.
Also the search config module may be the way to go.
Comment #10
olofbokedal CreditAttribution: olofbokedal commentedI won't implement the solution that #8 suggests, since it won't remove the node from the search results. The main use case for Rabbit Hole, is to remove the view page for a node. And if a user isn't able to view a node, showing it among the search result with the other content on the site doesn't make any sense.
I weren't aware of the Search Config module though, but that could definitely solve the problem in a better way. I'll open this issue again and look into it.
Comment #11
awolfey CreditAttribution: awolfey commentedYes, look at how search config alters the query.
Comment #12
olofbokedal CreditAttribution: olofbokedal commentedSome issues and suggestions regarding searches has been reported, for example #1599198: Non-regular behaviors throw off search results.
This clearly means that the solution implemented today doesn't work. The best way would probably be to alter the search query in some way. Until this has been done, please keep all the search related bugs in this issue. And as always, feel free to provide patches etc =)
Comment #13
mpdonadioCopying this over from the other issue, so everything is in one place.
I suspect that the module can implement hook_query_alter() to exclude the non-default content types from search. Custom Search does this:
The $excluded_types would just need to be changed to be all of the types that aren't using default behavior. I may have time to roll up a patch for this.
I am not sure the best way to apply this to per-node settings.
Comment #14
olofbokedal CreditAttribution: olofbokedal commentedVersion 2.0 has just been released, and the current solution has been removed because it didn't work properly. So if you absolutely need the current solution, don't upgrade.
The next step will be to find a solution to this issue.
Comment #15
Mark_L6n CreditAttribution: Mark_L6n commentedWould it work to add options to 'published'?
For example, instead of just 'published' or 'unpublished', as of now, there could be 'unpublished except for Views', etc.
Comment #16
olofbokedal CreditAttribution: olofbokedal commentedThat's not the purpose of this module. The published/unpublished state comes from Drupal core.
If you'd like to filter nodes in Views, you need to configure your view in an appropriate way. But that's a whole other issue.
Comment #17
13rac1 CreditAttribution: 13rac1 commentedUse http://drupal.org/project/custom_search to hide content types from search results.
Comment #18
BWPanda CreditAttribution: BWPanda commentedHere's a patch that prevents hidden content types from being displayed in search results.
It does this by implementing hook_query_alter() (copied from these posts), so this should be better than previous solutions described above.
I know it was decided above that there doesn't need to be any configuration needed for this feature, but I disagree - some people might want their redirected nodes displayed in search results so that users are still redirected when clicking on them...
I've therefore added a simple checkbox to the Search Settings page (enabled by default) that toggles this feature.
Finally, as a new variable was created for the search settings page, I've had to add an uninstall function to remove that variable.
Let me know what you think.
Comment #19
olofbokedal CreditAttribution: olofbokedal commentedThis is probably the best approach. There's one thing that needs to be fixed though.
This will check the Rabbit Hole settings for a content type, but what if a node overrides the content type default? Is it possible to respect that using a query alter? Maybe we need to have access to the results in order to prevent certain nodes from being displayed, rather than an entire content type.
Comment #20
BWPanda CreditAttribution: BWPanda commentedHere's an updated patch for the latest 2.x-dev version (patch from #18 wouldn't apply), however it doesn't address the issue raised in #19 - that still needs fixing.
Comment #21
yannickooMissing punctuation.
I guess that it's not difficult to get this working. We should iterate the node ids instead of content types so in the
$hidden
array we would store the node ids.Comment #22
BWPanda CreditAttribution: BWPanda commentedThat's the only way I thought to do it, however I wonder what the performance implications would be iterating through each and every node whenever a search is performed, especially on sites with thousands of nodes...
The other reason I didn't tackle #19's issue is because it would make sense to do the same for other entities RH supports (e.g. users) and that seems like a much bigger task.
Comment #23
DedMoroz CreditAttribution: DedMoroz commentedUnfortunately #20 doesn't work. If I select checkbox "Allow these settings to be overridden for individual entities" in the setting of content type and override Rabbit Hole settings for individual node it won't remove that node from index.
ps: For the whole content type it works.
Comment #25
mlncn CreditAttribution: mlncn at Agaric for Drutopia, Teachers with GUTS, Vermont Housing Finance Agency, MASS Design Group commentedRabbit Hole briefly had this feature but currently does not.