I've looked at apachesolr.api.php, apachesolr.module, apachesolr_search.module, Peter Wolanin's chapter on Solr in The Definitive Guide to Drupal 7, Solr 1.4: Enterprise Search Server, numerous Solr DrupalCon videos, and extensive searches in this issue queue, but I'm stuck. I want to make numerous custom search blocks that each have different filters ("Search within this content type"). I can get to what I want by clicking on my enabled facets -- I just want to have blocks where these are "pre-selected" (and hidden).
I've implemented hook_block_info() and hook_block_view() to create a few custom search boxes doing something along these lines:
function my_module_block_view ($delta = '') {
switch ($delta) {
case 'my_module_search':
$form = drupal_get_form('search_form');
$block['subject'] = t('Search this tab of this content type');
$block['content'] = drupal_render($form);
return $block;
}
}I've altered the form doing something like this:
function my_module_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'search_form') {
$form['#submit'][] = 'my_module_search_form_submit';
return;
}
}That seems to work. But, when I try to do something like this, it fails:
my_module_search_form_submit($form, &$form_state) {
$form_state['values']['filters'][] = array(
'#name' => 'bundle',
'#value' => 'my_value',
);
}I got this format from a hook like this:
function my_module_apachesolr_query_prepare($query) {
dpm($query->getFilters(), 'Filters');
}
It works for me to include $query->addFilter('bundle', 'my_field'); in hook_apachesolr_query_prepare(), but then the filter is always in place. I've also tried making my own search pages with hook_search_info() and hook_search_execute(), but I can't do this for every piece of content. I've also tried this doing something like http://drupal.org/node/963118, but that, too, does not seem to work for me.
I feel like I'm missing something simple here. Any suggestions would be greatly appreciated!
Comments
Comment #1
nick_vhTake a look at the retain filters functionality :
As you can see we are sending various information from the url to the submit function of the form
Then in the submit
We are redirecting with a query argument. So all the filters will be visible in the URL. In your case I would not get the filters from the URL but from your function. And then send these filters to the submit function and you should be able to get what you want?
Comment #2
pwolanin commentedIt seems like you should just make custom search pages that pre-apply a filter?
Note that the search pages can take a wildcard arg such as a content type.