When the user uses the standard search box, instead of relying on the user to notice the "Search" tab next to the standard Drupal "Content" tab, we should allow the admin to tell ApacheSolr to display the Apachesolr Search tab.

In apachesolr.module:

1) Added setting 'apachesolr_default_search' ( radios with options "ApacheSolr Search" and "Drupal Search")
2) added a block of code to form_alter to display selected "default search" results tab.

Comments

JacobSingh’s picture

@RobertDouglass & @drunkenmonkey,

Can one of you guys take a look at this? I feel it is really important to foster adoption.

Best,
Jacob

robertdouglass’s picture

Project: Apache Solr Search » Search configuration

The approach is good but I think it should be part of the http://drupal.org/project/search_config module. (Actually, I think it should be part of core).

robertdouglass’s picture

Title: Display ApachSolr results (Search tab) when searching from the Drupal search block » Choose which search implementation should be default (including search box)
pahariwalla’s picture

StatusFileSize
new2.11 KB

1) Added option "Default Search" to Advanced search configuration. Presents radios - one for each module implementing hook_search (except search_config), setting new variable "search_config_default_search"

2) Modified hook_form_alter to present the appropriate tab on search results.

JacobSingh’s picture

Status: Needs review » Needs work

This is great! Works perfectly. Only one suggestion:

Improve the documentation inline on them form. Right now, it's a little sparse, it's a little hard to describe I suppose, but something a little more verbose might help. Really nice though!

Also, check for style things like spaces after commas, etc... It's not terribly important, but worth a scan

pahariwalla’s picture

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

How's this? (it's in the attached patch)

Which tab on the search results will be presented by default. The standard Drupal installation defaults to node_search ("Content" tab). This option allows you to default to the "User" tab or any other tab from contributed search modules, e.g. Apachesolr which implements a tab called "Search" tab to display its results

JacobSingh’s picture

Looks good to me! I'm not rechecking the patch, but I assume it is fine. Any other reviewers?

canen’s picture

It looks OK but I'll see if I can apply it later and do some actual testing.

robertdouglass’s picture

I think #base is a deprecated property:

+  if ($form['#base'] == 'search_box_form') {

Doesn't $form_id have the information you're looking for?

robertdouglass’s picture

Favored Drupal coding style is to use full-word variable names with underscores separating words:

+        '#options' => $imparr,

should become

$implementor_array = 

But really, that code can be rewritten:

+      $implementors = module_implements('search', false, false);
+      unset ($implementors[array_search('search_config', $implementors)]);
+      foreach($implementors as $imp) {
+        $imparr[$imp] = $imp;
+      }

becomes

+      $searches = drupal_map_assoc(module_implements('search', false, false));
+      unset ($searches['search_config']);

And finally, I'd prefer this:

+      $description = t('Which tab on the search results will be presented by default.
+      The standard Drupal installation defaults to node_search ("Content" tab). This option allows you to default to the "User" tab
+      or any other tab from contributed search modules, e.g. 
+      Apachesolr which implements a tab called "Search" to display its results');

(added t(), as opposed to t($descriptions) later in the form)

robertdouglass’s picture

Status: Needs review » Needs work
robertdouglass’s picture

pahariwalla’s picture

StatusFileSize
new2.34 KB

Once again thanks Robert for taking the time and keeping all things groovy.

Re: #base .. good eye. Deprecated in Drupal 6 (http://drupal.org/node/144132#base ) .

I've changed the condition logic to use $form_id instead of $form['#base']
"search_theme_form" for search box form
"search_form" for search results form

It seems to work fine. Being new to Drupal , I'm a little concerned about a form name containing the word "theme".... (jacob helped me with this piece)
@JacobSingh: comments?

Also in the patch are suggested changes to the array variable naming/handling and $description string translation

pahariwalla’s picture

Status: Needs work » Needs review
canen’s picture

StatusFileSize
new2.07 KB

Did a quick test, on a mostly clean install, and things seem to work as expected. There is a possible minor usability issue though. The search block will use the assigned default search and depending on what that is the initial search results might be a little surprising as there is no way to indicate that you will be searching "users", for example, instead of "content" from the search block. This is even more evident if the default search is "user" and the person does not have access to search users. All search results return empty. I don't think it will be much of an issue in practice though.

I cleaned up the patch at a little but mostly for style fixes. I also removed the $mod variable since it wasn't needed. If someone else could test and let me know how it goes I'll gladly commit it.

pahariwalla’s picture

i'll look for your style fixes - much appreciated.

Re: user experience - good point. it can get even crazier, as described in #267833: Add Fallback to default drupal search option

JacobSingh’s picture

Status: Needs review » Reviewed & tested by the community

Works great!

canen’s picture

Status: Reviewed & tested by the community » Fixed

Fixed in #141753.

Thanks.

canen’s picture

Status: Fixed » Closed (fixed)

New release out with the feature added. Thanks again everyone.

Closing.

pahariwalla’s picture

My pleasure. As I'm pretty new at Drupal, it sure feels nice to have a patch evaluated, accepted and now implemented. Now I think I'll give myself a pat on the back.

Great thanks to all involved and to you @canen for getting to this so quickly.