Creating custom search facets with the Apache Solr Facet Builder module
Search facets are a way to let your users filter search results in interesting ways. Some facets included with Apache Solr are filtering by content author or by content type. The Apache Solr Facet Builder module allows you to create your own facets, describing each filter option using the Views UI. This article lists the steps to set up custom faceted search filters with this module.
As an example, imagine you want to filter your site by it's various sections: 'About Us', 'Articles', 'News' and 'Events', but these sections are not accurately described by any of the available Apache Solr facets.
- Install and enable the Apache Solr Facet Builder module as well as the Views and Views UI modules (You will also need to enable and set up Apache Solr).
- Create a new View to represent your facet type (eg: 'Filter by Section').
- Set the name under Basic Settings of the Default display to the name of your facet type. In our example the name would be 'Section'.
- Create one or more displays in the view of type 'facet'. Each of these facets will represent a different option in your facet type. In our example we might create 'About Us', 'Articles', 'News', 'Events'.
- Override the filters in each facet display and use them to specify what content should appear in each facet. For our example lets say 'About Us' contains all content of type Page with the taxonomy term 'About', 'Articles' contains any node of type 'Blog Post' or 'Article', 'News' is any Article with the 'Article' taxonomy term and 'Events' is any node whose 'Event Date' field is not empty. You can check if each facet contains the appropriate content by using the Preview function of the Views UI. You may also add arguments to your facets as long as they have some sort of default argument handling.
Your new facet filter will be available to Apache Solr and will act like any other available facet. You will need to enable it in the Apache Solr settings as you would any other new filter:
- Go to the Enabled filters tab of the Apache Solr module settings (admin/settings/apachesolr/enabled-filters) and enable your new facet (in our example it will be called 'Apache Solr Facet Builder: Filter by Section (view_name)'
- Enable the facet block for your new facet at admin/build/blocks
Your new facet block should show up now when you perform a search with Solr on your Drupal site.
Help improve this page
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion