Would it be possible (or useful) to have a Rabbit Hole setting to hide from the core search results?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

olofbokedal’s picture

That would absolutely be useful.

Don't know right away how to solve it, but I'll look into it.

no2e’s picture

Usually 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?

olofbokedal’s picture

I 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 :)

aleksey.tk’s picture

I'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.

olofbokedal’s picture

After 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.

olofbokedal’s picture

Status: Active » Fixed

Ok, 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 the search-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

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

leenwebb’s picture

This 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:

		switch($action){
			case RABBIT_HOLE_PAGE_REDIRECT:
				if (isset($node->rabbit_hole_action) && $node->rabbit_hole_action != RABBIT_HOLE_USE_DEFAULT) {
				  // Get the redirect path and response from the node.
				  $redirect_path = token_replace($node->rabbit_hole_redirect, array('node' => $node));
				}
				else {
				  // Get the redirect path and response from the content type.
				  $redirect_path = token_replace(variable_get('rabbit_hole_redirect_' . $node->type, '<front>'), array('node' => $node));
				}
				$results[$delta]['link'] = url($redirect_path);
				break;
				
			case RABBIT_HOLE_PAGE_NOT_FOUND:
			case RABBIT_HOLE_ACCESS_DENIED: 
				unset($results[$delta]);
				break;
		}

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.

awolfey’s picture

I 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.

olofbokedal’s picture

Status: Closed (fixed) » Active

I 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.

awolfey’s picture

Yes, look at how search config alters the query.

olofbokedal’s picture

Some 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 =)

mpdonadio’s picture

Copying 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:

function custom_search_query_alter(QueryAlterableInterface $query) {
  if ($query->hasTag('node_access') && $query->hasTag('pager')) {
    $excluded_types = array_filter(variable_get('custom_search_' . variable_get('custom_search_delta', '') . 'node_types_excluded', array()));
    if (!empty($excluded_types)) {
      $tables = $query->getTables();
      foreach ($tables as $table) {
        if ($table['table'] == 'search_index') {
          $query->condition('n.type', $excluded_types, 'NOT IN');
        }
      }
    }
  }
}

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.

olofbokedal’s picture

Version 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.

Mark_L6n’s picture

Would 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.

olofbokedal’s picture

That'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.

13rac1’s picture

Use http://drupal.org/project/custom_search to hide content types from search results.

BWPanda’s picture

Status: Active » Needs review
FileSize
2.32 KB

Here'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.

olofbokedal’s picture

This 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.

BWPanda’s picture

Version: 7.x-1.x-dev » 7.x-2.x-dev
Status: Needs review » Needs work
FileSize
2.05 KB

Here'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.

yannickoo’s picture

  1. +++ b/rabbit_hole.module
    @@ -718,3 +718,50 @@ function rabbit_hole_schema_fields() {
    +    // Get search queries
    

    Missing 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.

BWPanda’s picture

We should iterate the node ids instead of content types

That'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.

DedMoroz’s picture

Issue summary: View changes

Unfortunately #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.

  • olofjohansson committed 24b71b2 on 8.x-1.x
    Issue #1468302 by gregrenner: Hide nodes from cores search results.
    
    
mlncn’s picture

Version: 7.x-2.x-dev » 2.x-dev

Rabbit Hole briefly had this feature but currently does not.