Creating a Faceted Search View in Drupal 8 using the Search API Modules

Swapnil Pawar
Jul 14, 2017 · 4 min read

Getting Started

Before we begin, download and enable the Facet API , Search API module. In Drupal 8, There are two different search servers available namely :

  1. Database Search.
  2. Apache Solr Search.

In this article, We are going to see about “Database Search” server. Enable the “facets”, “Database Search” that ships with Search API module.

Extend Page

After enabling modules, go to configuration →Under “Search And Metadata” section you’ll find “Search API” section. You’ll find default Database server details and index part. You can edit and use default database server or you can create new database server from scratch. we will see how to create new server.

Search API

Creating Database Server:

On Search API page, Click on the edit link within “Default Content Index”.

Select the datasources from the list which you want to index on database server. Below that, under “configure the content source”, select the “All” option to be indexed. select the bundles whose content you don’t want to index.

Rest of the options keep it as it is and Save.

Edit Index

After that, Click on the “Fields” tab on top. Click on add fields section and add the fields for indexing and click on “done”.

On processor tab, you can select settings related to indexed data search. after you have saved all the changes, click on the “view” tab on top.

on view page, check if index status is showing 100%.if not, scroll down to the section called “Start Indexing Now”. click on the “Index Now” and you data will be index in database.

Index Status

Once you done with indexing, now its time to create facets for your website using indexed data.
For this, I have created a product list using “views” as shown below:

Now we want to show a facet on the left side of the product page as shown below:


Go to configuration →Facets(under Search and Metadata), Click on “Add Facet” , Select the views page for which you want to create facets . Here we are creating for product list.

after that, you’ll get the list of fields which we added using search API. Select the field you want to use for facets. we are going to select “Brand”.

Click “save” and You will get settings for facets where you can customize your facets using Widgets, Sorting and Behaviour .

Once you create facets , Drupal will automatically create a block of the facets. go to structure →Block layout →choose region where you want to add facet.

Click “place block” to add block to that specific region.

At this point, you should have a fully operational Faceted block on your Drupal 8 site.

From here, you can customize the facets further, work on adding more facets (date, author, taxonomy term, etc.) to make the search work exactly as you’d like!

Swapnil Pawar

Written by

Entrepreneur, Alexa Evangelist, AWS Certified, Salesforce Lover & Drupal Developer. Loves Bike Riding, Poems, Avid Reader

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade