Exploring Faceted Search: Implementing and Configuring Faceted Search With Views in Drupal 9

20 / Jan / 2024 by Siddhraj Purohit 0 comments

Introduction

Drupal 9, a powerful and flexible content management system, offers a robust solution for implementing faceted search through its Views module. In this blog post, we’ll dive into the process of implementing and configuring faceted search using Views in Drupal 9. Faceted Search allows users to filter and refine search results based on various attributes or facets. These facets can include categories, tags, dates, and any other relevant metadata associated with the content.

Step 1 : For using Facet Search, we will require modules.
Install and enable these two modules:

Facet Module
Search API Module

Step 2 : Add Content-Type and Content
Navigate to Structure >> Content type >> Add content type.
Add Content for the Content type you want to add content.

Step 3 : Configure Search Server
Navigate to Configuration -> Search and Metadata -> Search-API from the admin interface to configure your search server.

Step 4 : Configure the Search Index
Navigate to Configuration -> Search and Metadata -> Search-API -> Index.

Now, give a name to the search index and select content as a datasource. After that, configure the content data source. Here, you can select all the bundles or any specific bundles you want to index for faceted search.

Select your server (created in Step 3). Check “Index items immediately” under index options to index content immediately when you create new content.

Step 5 : Add Fields for Indexing
Navigate to Configuration -> Search and Metadata -> Search API -> Edit your index and select the Fields tab.


Click on the “Add fields” button to Add fields according to your requirement.

Step 6 : Index the Content for Facet Search
Click on the View tab, and under Start Indexing Now, click on Index now.

Step 7 : Create A View
Navigate to Structure -> Views -> Add View.

Add view Name. Under View Settings, choose your index name (created in Step 4).
Create a page and click Save and Edit. Add view fields (add the fields you added for indexing under Step 5).

Step 8 : Create/Configure A Facet
The Facets module extends the Views module to allow the creation of facets for building faceted search interfaces.

Navigate to Configuration -> Search and Metadata -> Facets. Click “Add facet.”


Select facet source as your newly created view from Step 7. Select the field added in Step 5. Add a Name. Click Save. On the next screen, you will see multiple settings for your newly created facet.

From Widget, you can select 4 different widgets (links, drop-down, checkbox, raw result). You can do other settings based on your requirements. Select “Transform entity ID to label” to display the Content Type label instead of ID.

Note: You can add multiple facets, allowing users to refine their search based on various fields.

Step 9 : Placing The Facet Block
Facets can be displayed as blocks, allowing you to place them in different regions of your site.
Navigate to Structure -> Block Layout.

Choose a region based on your requirement and click on Place Block. Search for the newly created facet block and click Place block. Under configure, add the view Path name. Click on Save block.

After all these settings, our Final Result will look like this.

FOUND THIS USEFUL? SHARE IT

Leave a Reply

Your email address will not be published. Required fields are marked *