I have Apache Solr Search up and running. When I go to the admin page I can see that there is a connection to the solr instance and I can also watch the operations in terminal when a search is executed.

However, when I run a search - it always defaults to the core search (content) and then I have to click on the search tab to bring up the solr results. I have checked my failure settings and it should give an error message rather than default if it was failing.

I assume I am doing something wrong here, but can't figure out how to have the solr results as the default for a given search.

Thanks.

Comments

pwolanin’s picture

The base module does not, at the moment, override the core search block or make apachesolr the defualt - you can do this trivially with a custom module. Tehre is also an open issue to remove the dependence on the core search module, in which case apachesolr would be the default always if search module is disabled. see: http://drupal.org/node/405206

bacchus101’s picture

Thanks.

I did see that post but it did not offer any enlightenment to how to make apachesolr the default. I see that drupal.org has it setup as such and just assumed I was missing something.

you can do this trivially with a custom module.

I've done some searching but can't seem to pinpoint where this implementation is discussed. Are there any recipes out there that I am overlooking? I assume the majority of people would want the apachesolr results to be used if they are using this module.

I did notice with the lucene api module the search box could be hijacked via the settings. Is that the type of approach you are speaking of?

Basically, I don't care for the moment whether core search is enabled or not as long as I can force the default result set to be that of apachesolr. Otherwise, users would always end up using the core search as they would not know to click the search tab.

Edit: I found where this functionality is discussed.

http://drupal.org/node/341290

search.module line 1079

Replace:

/**
 * Process a block search form submission.
 */
function search_box_form_submit($form, &$form_state) {
  $form_id = $form['form_id']['#value'];
  $form_state['redirect'] = 'search/node/'. trim($form_state['values'][$form_id]);
}

with:

/**
* Process a block search form submission.
*/
function search_box_form_submit($form, &$form_state) {
  $form_id = $form['form_id']['#value'];
  $form_state['redirect'] = "search/apachesolr_search/". trim($form_state['values'][$form_id]);
}
bacchus101’s picture

Status: Active » Fixed

My issue has been resolved.

pwolanin’s picture

Don't hack core - you will be sorry when you go to upgrade - you should implement a custom module to change the submit handler via hook_form_alter.

See, e.g., the talk by Gabor and I at Drupalcon in DC.

Here's roughly the entire code of such a module


/**
 * Implementation of hook_form_alter().
 */
function mymodule_form_alter(&$form, $form_state, $form_id) {
  $search_forms = array('search_block_form', 'search_theme_form');
  if (in_array($form_id, $search_forms)) {
    $form['#submit'] = array('mymodule_search_submit');
  }
}

/**
 * Custom form submit handler for the search block.
 */
function mymodule_search_submit($form, &$form_state) {
  $form_id = $form['form_id']['#value'];
  $form_state['redirect'] = "search/apachesolr_search/". trim($form_state['values'][$form_id]);
}
bacchus101’s picture

Ahh, just what I was looking for and it works like a charm.

Thanks.

akolahi’s picture

Category: support » feature
Status: Fixed » Active

any chance of adding this as a sub-module to apachesolr, for us lesser drupalers? :D
Making Apache Solr the default search would be as simple as just enabling this module, along with the others.

Thanks.

pwolanin’s picture

We have a separate issue to separate this module from dependence on core search - in that csae, it would obviously be the default if core search is not enabled. Robert Douglas had preferred to leave core search as default as you see it currently, so he's the one to convince.

akolahi’s picture

yeah i think it's probably a good idea leave core search as default, but i think it would be nice to have the option to make solr the default if one wanted to.

rjbrown99’s picture

Any plans to integrate the module code from post #4 into this module or will we have to roll our own separate module for this? It seems like an easy enough addition and it would be nice to have it as part of the 'official' Apache Solr+Drupal module.

Scott Reynolds’s picture

You can try Core Searches module. http://drupal.org/project/coresearches

the patch provided allows this behavior.

ayalon’s picture

I created a small module for this:

You can download it on my blog:
http://drupal.ayalon.ch/en/apache-solr-default-search

I does mainly the same as described above.

Greets Jon

pwolanin’s picture

Status: Active » Closed (duplicate)