The apachesolr_panels module has some limited support for the autocomplete module. However, there are some areas where it could be improved, and are almost necessary in my mind to be useful for some cases. For example, if you specify a filter in you Solr panel page of say 'type:bio' and you only want to display a list of names (like an employee directory for example), you may only want the autocomplete to query against specific fields - like first name and last name of the employees, and not some other text that may be indexed as part of the bio content type.
My proposed solution would require a patch to this module, but also the Apache Solr Autocomplete module. Basically, it comes down to the ability to pass specific query configuration that is input in the Solr Panels config to the autocomplete function that does the search for the autocomplete functionality - apachesolr_autocomplete_suggest(). Basically there are two main Solr Panels parts, the first part is just to be able to collect the necessary Solr parameters to make this possible, so that part involves adding the qf field to apachesolr_panels_apachesolr_result_content_type_edit_form(). The second part is passing that data on in such a way that it can be made available to the Solr autocomplete module and for that I had the idea of putting those values in hidden fields in apachesolr_panels_form_apachesolr_panels_search_form_alter(). Here is the basic idea in code format:
$apachesolr_autocomplete_overrides_value = array();
$apachesolr_autocomplete_overrides_value['fq'] = explode(' ', $form_state['apachesolr_autocomplete_fq']);
$apachesolr_autocomplete_overrides_value['facet_field'] = explode(' ', $form_state['apachesolr_autocomplete_facet_field']);
$apachesolr_autocomplete_overrides_value['qf'] = explode(' ', $form_state['apachesolr_autocomplete_qf']);
$form['basic']['apachesolr_panels_search']['apachesolr_autocomplete_overrides'] = array(
'#type' => 'hidden',
'#id' => 'apachesolr-autocomplete-overrides',
// We use JSON encoding instead of PHP serialize, since otherwise we be
// at risk of user input being injected into the hidden string and
// unserialized.
'#default_value' => json_encode($apachesolr_autocomplete_overrides_value),
);
Then, that json encoded values can be passed to Solr Autocomplete by using the 'extraParams' functionality of jquery-autocomplete library. For example:
extraParams: {
apachesolr_autocomplete_overrides: function() { return $("#apachesolr-autocomplete-overrides").val(); },
},
Of course there is quite a bit more involved on the Solr Autocomplete side of things, but that much code gets the necessary Solr Panels based config into the calls to the autocomplete functions.
Finally, there is the matter of having Solr Panels utilize the qf parameter and for that see this issue http://drupal.org/node/958906.
Comments
Comment #1
kmadel commentedSee my related issue for Apache Solr Autocomplete: http://drupal.org/node/1061260