I am creating a search similar to the example shown below: enter image description here

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.


  • The filters you describe what are they? Are they i.e. entity reference fields on all nodes you search for? Is the search form available on all your pages or only the search page? Jun 19 '14 at 8:13
  • The filters will be taxonomy terms (countries) which are attached to the search type entities. The search form will be displayed on searchpage (homepage) and results pages.
    – davewilly
    Jun 19 '14 at 8:17

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.

  • Thanks. Sounds like a good approach. I have currently chosen the apachesolr route opposed to search API/Search API solr, so perhaps a little more investigation is required into the adv/disav of each.
    – davewilly
    Jun 19 '14 at 8:48
  • After some further digging, I have gone with your suggestion and am now using Search API and Search API Solr. Thanks
    – davewilly
    Jun 19 '14 at 9:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.