Facets are a great tool to help guide your users to the information they are looking for. Its a way of narrowing down the items that are visible on the screen. They perform a similar function to exposed filters in Views, but are more flexible, and performant.
The Search API project comes with another extension module that integrates the Search API with the Facet API, the Search Facets module. Search Facets provides the ability to create facets on any search executed anywhere in Drupal. So, in this video, I will you show how to install and enable Search Facets and configure facet blocks.
Install Module
Enable Module
- Go to "Modules" (admin/modules) and enable:
- Search facets
- Facet API
- (Save Configuration)
Configuring Facet API
- Go to "Configuration = > Search and Metadata => Search API" (admin/config/search/search_api)
- Node Index
- Click the dropdown arrow
- Choose "Facets"
Here we see a list of all of the fields that we are able to create a facet of. Each enabled facet will be displayed in a separate block. For performance reasons, you should only enable facets that you intend to have available to users on the search page. Let's enable a few fields as facets:
- [x] Date created
- [x] Content type
- [x] Author » Name
- (Save configuration)
Now we need to enable the facet blocks.
Enable facet blocks
- Go to "Structure => Blocks" (admin/structure/block)
- Scroll down to Disabled and place the following block in the "Sidebar second" region
- Block: Facet API: Search service: Node index : Author » Name
- Block: Facet API: Search service: Node index : Content type
- Block: Facet API: Search service: Node index : Date created
- (Save blocks)
Now when we go to our home page and perform a search, we'll see that in the second sidebar of the results page, we have blocks to:
- Filter by author - which limits the search results by author and shows the number of results for that author
- Filter by content type - which limits the search results by content type
- Filter by date created - which lets us filter content to only that which has been created on a specific date.
In the following videos, we will continue to take a look at additional modules that extend features of the Search API module to build out the search functionality of our site.