Want to learn more about search in Drupal 7? Then check out our online video course called “Build Powerful Search Pages with Views and Search API in Drupal 7“.
In this tutorial, we’ll add faceted search to our custom search page using the Facet API. Luckily for us, Search API and Facet API work brilliantly together so setting up faceted search is pretty easy.
Before we begin, download and enable the Facet API module and then enable the “Search facets” sub-module that ships with Search API. “Search facets” integrates Facet API with Search API.
If you prefer Drush, run the following command:
$ drush dl facetapi $ drush en facetapi search_api_facetapi
In this section, we’ll configure a facet block that will display the Tags vocabulary. This allows users to filter content by clicking on a tag.
1. Go to Configuration -> Search API and click on the edit link within the “Article index” and select Facets from the drop-down.
2. Check the Tags checkbox and click on Save configuration.
At this point, we have just enabled the facet. The next step is to add the facet to a specific region.
1. Go to Structure -> Blocks and place the “Facet API: Search service: Article index : Tags” into the “Sidebar second” region.
Now if you go to
/search-page, you should see a facet block on the right hand side.
If for some reason the facet block is not appearing, try re-indexing the content.
Current Search Block
The final thing we’ll look at in this tutorial is the “Current Search Blocks” sub-module which ships with Facet API. This is a hidden gem that isn’t advertised on the Facet API project page. The sub-module defines a block that displays information about the current search. It’ll make sense once you see it in action.
1. Enable the “Current Search Blocks” module.
2. Go to Structure -> Blocks and add the “Current search: Standard” block into the Highlighted region.
3. Go to the
/search-page and you should see the block above the content area.
If you want to configure the block or define your own, go to Configuration -> “Current search blocks” (admin/config/search/current_search).
As you can see this is a cool sub-module and I plan to write a detailed tutorial about it in the future.
If you have any questions, please leave a comment.