Approach to create a custom search form for an apache solr search I am creating a search similar to the example shown below:


I am looking for the best approach to do this. My current approach is to alter the drupal default search form and add the additional elements, and then use a custom submit handler to pass the search query on to the appropriate solr search path, i.e: /search/courses/funky%20widgets.

An alternative approach would be to create the form from scratch with Form API, which may give me more flexibility, but at this stage I don't know.

It would be great to hear how others would approach this, or if there is a best practice method.

Thanks
I usually use Search API and Search API Solr. And for setting up the site layout I use Panels and Panels everywhere, so my answer will be using those modules. I'm not that familiar with Apache Solr Search but maybe it's doable with that module also. It would be interesting to hear other solutions :)

The fields you want to filter by could be built using Facet API. One thing that's pretty awesome is that the facets are shown depending on the search result. So the facet will only show filters that have results.

The tricky bit is that a facet can only be shown (as far as I know) by a query that has been run. To do this I would create a Search API view that uses you Search API index. Setup a views content pane that shows your search result. Then create a display of the type context in Views.

In your site template (setup using Panels everywhere)
Insert the view by adding a pane where you want the search result to be shown. Add your views context as a context to the panel under Contexts. Then add your facets to the region you want them to show.

Then you probably want some caching on the views context so that it doesn't fire off a query on each page load :)

Another approach as you mention would be building a custom form and redirect the user to the search page /search?q=filter or to the search page and "prefill" the facet on the search page with the filter value (ie /search?facet-argument=X). 

The options in the filter list could be fetched with an entity field query so that you fetch all values for the field you want to filter by. Then cache the result of that for X min/hours so that it doesn't load your site.