Comments

elliotttf’s picture

Here's a first cut of a patch to do this.

elliotttf’s picture

Wow, added some stuff I didn't mean to there. Here's a cleaner patch, sorry about that...

elliotttf’s picture

Title: Allow other modules to return search results » Allow other modules to return search results on solr failure
Version: 6.x-2.x-dev » 7.x-1.x-dev
StatusFileSize
new2.3 KB

I have re-rolled the patch for D7 in regards to the updated roadmap.

pwolanin’s picture

Status: Needs review » Needs work

Interesting idea.

At least a minor problem, I think, with this line:

drupal_goto('search/' . $search_module . '/' . drupal_encode_path($querystring));

The path may not be the name of the module, and if you are passing in a query string, there is an array form of the arguments to drupal_goto()

elliotttf’s picture

Status: Needs work » Needs review
StatusFileSize
new2.43 KB

I've rolled another patch that will account for search modules using alternate paths (I wasn't aware of this change in the API, learn something new every day :)).

I don't think arguments are included in the $querystring variable. If you look where apachesolr_failure() is called you can see only the keys variable is being passed, not the full query array:

<?php

/**
 * Implementation of hook_search_execute().
 */
function apachesolr_search_search_execute($keys = NULL, $conditions = NULL) {
  // ...
  catch (Exception $e) {
    watchdog('Apache Solr', nl2br(check_plain($e->getMessage())), NULL, WATCHDOG_ERROR);
    apachesolr_failure(t('Solr search'), $keys);
  }
}
?>
pwolanin’s picture

This needs to be fixed:

+          drupal_goto('search/' . $search_info['path'] . '/' . drupal_encode_path($querystring));

At the least it needs to use drupal_goto() correctly. It should ideally pass the full query string in also.

pwolanin’s picture

Status: Needs review » Needs work

2 other fixes:

$options['show_' . $module . '_results'] = t('Show @name search results', array('@name' => strtolower($search_info['title'])));

should just be:

$options[$module] = t('Show @name search results', array('@name' => strtolower($search_info['title'])));

and:

+  $options['show-no-results'] = t('Show no results');

Then you can just look in the array by key, rather than using a foreach here:

+      foreach (search_get_info() as $module => $search_info) {
elliotttf’s picture

Status: Needs work » Needs review
StatusFileSize
new2.48 KB

Rerolled with changes as requested with the exception of drupal_goto(). I'm not actually sure what the problem you're referring to is. The code is essentially the same as what was already in the module:

- drupal_goto('search/node/' . drupal_encode_path($querystring));
+ drupal_goto('search/' . $search_info['path'] . '/' . drupal_encode_path($querystring));
pwolanin’s picture

Status: Needs review » Needs work

Yes, I'm saying that code even though already in the module needs to be improved and should also pull in other query arguments and pass an array to drupal_goto()

Other parts look improved, though the logic at the end isn't quite right.

+      // If we're failing over to another module make sure that it's still enabled.
+      if (module_exists($fail_rule)) {
+        $hook_search_info = $fail_rule . '_search_info';
+        $search_info = $hook_search_info();

Should be like:

$search_info = search_get_info();
if (isset($search_info[$fail_rule])) {
  ...
}

Since a module can be enabled generally but DISABLED for search thanks to my changes in the 7.x core search API.

see: http://api.drupal.org/api/drupal/modules--search--search.module/function...

elliotttf’s picture

Should we create a new issue for the drupal_goto() change? I'm happy to implement it here but it's kind of out of scope for what this issue was originally trying to provide.

pwolanin’s picture

In general it would be nice to get it all in one, but since the drupal_goto() part might be relevant to Drupal 6 versions, feel free to create a separate follow-up issue if you prefer.

elliotttf’s picture

Status: Needs work » Needs review
StatusFileSize
new2.47 KB

For cross reference, I've created a new issue for the drupal_goto() array here: http://drupal.org/node/1105584

Here's a re-rolled patch with the above changes.

pwolanin’s picture

'show_error' and 'show_no_results' could, in theory, be valid module names.

Perhaps we should change them to use dash, space, or some other separator?

elliotttf’s picture

Good point! Here's another patch with namespaced variables for show_error and show_no_results.

pwolanin’s picture

ok, looking better - we should probably also add a little update function for good measure.

elliotttf’s picture

Patch with update hook to reset variables based on new naming conventions.

pwolanin’s picture

ok, looking close, but in the update function, it would be better to have e.g. NULL as the default for the variable_get() call and not set anything if it wasn't set already.

elliotttf’s picture

pwolanin’s picture

Testing it out locally - one problem is that the 'title' returned by hook_search_info() is the title of the tab, not the name of the module, e.g. as presented on http://api.drupal.org/api/drupal/modules--search--search.admin.inc/funct...

pwolanin’s picture

Status: Needs review » Fixed
StatusFileSize
new4.72 KB

committed this revised patch.

elliotttf’s picture

Version: 7.x-1.x-dev » 6.x-2.x-dev
Status: Fixed » Patch (to be ported)

Originally I needed this functionality for a client that's on D6, so marking as patch to be ported, will upload a port shortly.

elliotttf’s picture

Status: Patch (to be ported) » Needs review
StatusFileSize
new3.61 KB

I'm not sure the way I'm showing the module name is optimal but it seems to be the closest thing to system_get_info() in D6 that we can get without having to parse all the info files from all the modules (when really we're only interested in the search modules).

pifantastic’s picture

Status: Needs review » Reviewed & tested by the community

Tested elliotttf's patch and everything works correctly:

  • The update hook ran correctly
  • search results are failing over correctly
  • "On Failure" select box in apachesolr admin is clear.
jpmckinney’s picture

Status: Reviewed & tested by the community » Needs work
+  $fail_rule = variable_get('apachesolr_failure', 'apachesolr:show_error');
...
+        drupal_goto('search/' . $fail_rule . '/' . drupal_urlencode($querystring));

This will send users to 'search/apachesolr:show_error/...'. Not sure how this got RTBC.

elliotttf’s picture

Status: Needs work » Reviewed & tested by the community

Actually, that case is caught above:

 function apachesolr_failure($search_name, $querystring) {
-  $fail_rule = variable_get('apachesolr_failure', 'show_error');
+  $fail_rule = variable_get('apachesolr_failure', 'apachesolr:show_error');
 
   switch ($fail_rule) {
-    case 'show_error':
+    case 'apachesolr:show_error':
       drupal_set_message(t('The Apache Solr search engine is not available. Please contact your site administrator.'), 'error');
       break;
-    case 'show_drupal_results':
-      drupal_set_message(t("%search_name is not available. Your search is being redirected.", array('%search_name' => $search_name)));
-      drupal_goto('search/node/' . drupal_urlencode($querystring));
-      break;
-    case 'show_no_results':
+    case 'apachesolr:show_no_results':
+      // Do nothing.
       return;
+    default:
+      // If we're failing over to another module make sure the search is available.
+      if (module_exists($fail_rule)) {
+        drupal_set_message(t("%search_name is not available. Your search is being redirected.", array('%search_name' => $search_name)));
+        drupal_goto('search/' . $fail_rule . '/' . drupal_urlencode($querystring));
+      }
+      break;
   }

The only time 'default' is reached is if a search module is selected as the failover, not one of the two predefined apachesolr cases. Additionally, the default case checks to make sure that the fail rule is a valid module before firing the drupal_goto().

jpmckinney’s picture

My bad. Looks fine.

nick_vh’s picture

Version: 6.x-2.x-dev » 6.x-1.x-dev

The 6.x-2.x version has been deprecated. Moving this to 6.x-1.x-dev

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 1080652-allow_modules-20.patch, failed testing.

pwolanin’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev

Any features against 7.x first.

nick_vh’s picture

Status: Needs work » Closed (won't fix)

This was added to the D7 version. Closing this one since the backport will include this functionality