ApacheSolr search block
vistree - October 26, 2008 - 17:40
| Project: | Apache Solr Search Integration |
| Version: | 6.x-2.x-dev |
| Component: | User interface |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
Jump to:
Description
Hi, how can I create a search block like drupals core search block?
Or is it possible to use the core to run Solr-quries?
Regards
vistree

#1
whether you use the core search block or create a new one, you'll want to set the action of the form to be search/apachesolr_search. The action of the core form is search/node. This means you can probably use form_alter to change the action on that form. Or you can create a new search form in the block.
I'm marking this as a feature request and changing the title because I think the module should either ship with its own block, or hijack the existing one.
#2
That is great. Thank you for reply.
Where can I change the behaviour? In the template.php?
And can you tell me the correct code for this?
Thank your very much!
vistree
#3
Your own custom module is the place where you would implement hook_form_alter. I don't have the exact code for this but you can get a start by reading the API docs: http://api.drupal.org/api/function/hook_form_alter/6
#4
Hey Robert,
Didn't you have me and my dad put this functionality in search_config a couple months ago? (where is is now committed).
Best,
Jacob
#5
Thank you for the link.
My problem is, that I am no programmer and don't know how to create my own module.
I thought that it would be much more easier to generate my own Solr search block, e.g. by adding a "print ... " in a newly created block.
Is there some more information on how to create such a module or block? Or maybe an already existing example?
Regards
vistree
#6
@jacobsingh - I believe you are correct. current dev 5.x-1.4 of search_config module contains that patch (http://drupal.org/project/search_config )
@vistree - after enabling the Search Config module, go to admin/settings/search (Site Configuration | Search Settings). Under "Advanced Search Confuration" you will see "Default Search" which lists of all modules that hook into search. Whichever one you select will cause the Drupal search box to take you to that results tab.
Hope this is what you are looking for.
#7
Yes, that is what I am searching for ;-)
Unfortunately I work with Drupal 6 - where is currently no version of the mentioned module above ;-(
Is there an alternative?
Regards
vistree
#8
Well, not sure if anyone is interested in a followup with this but here's what I did. Dead simple:
Created a block, PHP input filter, with the following code:
<form class="search-form" id="search-form" method="post" accept-charset="UTF-8" action="/path_to_site/search/apachesolr_search/"><input type="text" class="form-text" value="" id="edit-keys-header" name="keys" maxlength="255"/>
<input id="edit-submit" class="form-submit" type="submit" value="Search" />
</form>
Good to go. Substitute the path to your install in the form action.
Hope that helps.
#9
This is great and works well. It is what I was still looking for - thank you!!
Regards
vistree
#10
This is still valid as a feature request since it would be useful if the module provided its own search block.
#11
@David Lesieur - we are planning code to decouple this module from it's dependence on core search, in which case we will certainly provide a separate search block.
#12
I think we should suggest an interim solution [Apache Search Block] in module Documentation.
#13
The way the search_theme_form ($search_box variable in the page.tpl.php file) actually goes to the search page is through a redirect in the submission, so we have to add a submission, then redirect it. (May be a more efficient way, but this works)
<?php
/**
* Implementation of hook_form_alter()
*/
function custommodule_form_alter(&$form, $form_state, $form_id) {
// Search Form (top right), change action to apachesolr
if ($form_id == 'search_theme_form') {
// We need to add a submit, because the search form redirects to a specific place
$form['#submit'][] = 'custommodule_search_submit';
}
}
/**
* Implementation of form submit function
*/
function custommodule_search_submit($form, &$form_state) {
$form_id = $form['form_id']['#value'];
$form_state['redirect'] = 'search/apachesolr_search/'. trim($form_state['values'][$form_id]);
}
?>
#14
see: http://drupal.org/node/405206
#15
Code from #13 doesn't work for me. Using Drupal 6.13 and solr 6.x-dev 12th of august.
While custommodule_form_alter() is called, the custommodule_search_submit() is not... So is $form['#submit'][] correct?
P.S. I changed back from duplicate, because it hasnt been committed to the august 12th dev version either. And nowhere is the real solution patched.
#16
I agree that it's not a duplicate, and it's one of the tasks that we need to handle to totally decouple from search.module. But there is no patch, it's an active issue, and it is for 6.2.
#17
I have "Make Apache Solr Search the default:" set to Enable, which is supposed to redirect the Search Block. But it doesn't work... Only for normal form on /search page
#18
#19
#20
Solution found! It's an incompatibility with search_config.module! They do this:
function search_config_form_submit($form, &$form_state) {$form_id = $form['form_id']['#value'];
$type = $form['module']['#value'];
$form_state['redirect'] = 'search/apachesolr_search/'. trim($form_state['values'][$form_id]);
}
Which overrides apache_solr's redirect... I'm just going to deactivate this module. Rather use Solr at all than have this extra.
#21
subscribing
#22
I think this is solved? Closing out