Table of Contents
Finding specific products or services on large websites can be frustrating, especially when the search functionality lacks filtering. A poorly organized search function can quickly turn a promising shopping experience into a frustrating one.
Without a clear way to filter and refine results, users may abandon their search, leading to lost sales and brand reputation. So, how do you make it simple for users to find what they need? The answer is, using Drupal Facets.
In this blog, we’ll help you learn how Drupal development experts set up and use facets to enhance the search functionality. So, let’s dive in!
What is Faceted Search?
Faceted search is a technique used to enhance the search functionality on websites. Faceted search allows users to filter and refine search results based on a list of predefined categories or attributes. These categories, called facets, are based on the metadata associated with the content. Common facets include content type, tags, categories, author, date, and price range.
- Multiple Criteria Selection: Users can refine their search results by applying multiple facets (e.g., filtering products by brand, price range, and color simultaneously).
- Real-Time Updates: With AJAX support, faceted search dynamically updates results without reloading the page.
- Hierarchy Support: Some systems support hierarchical facets (e.g., filtering by “Electronics” and then narrowing down to “Mobile Phones”).
In Drupal, Faceted Search is implemented using the Facets module in conjunction with the Search API. These two modules enable developers to add faceted search on their website, enhancing the overall filtering functionality of the website.
How Does Faceted Search Work?
Faceted search works by allowing users to refine their search results based on specific attributes of the items they are searching for. This is done by displaying a list of facets on the search results page, which are clickable filters that can be used to narrow down the results.
Here’s a simple example of how faceted search works:
- A user starts by entering a search query into a search engine.
- The search engine returns a list of results that match the query.
- The user can then refine the results by clicking on one or more facets.
- The search engine then updates the results to only show items that match the selected facets.
- This process can be repeated until the user has found the results they are looking for.
Now, let’s understand it with a real world example. Let’s say you are searching for a new pair of shoes on an eCommerce website. You could use the facets to filter the results by brand, color, size, price, and other attributes. This would allow you to quickly find the shoes that you are looking for without having to sift through a large number of results you are not interested in.
In general, faceted search works by allowing users to filter their search results based on specific attributes of the items. This is done by displaying a list of facets on the search results page, which are clickable filters that can be used to narrow down the results.
Prerequisites for Implementing Drupal Faceted Search
Here are the prerequisites for setting up a faceted search using Drupal Facets:
- Drupal Core: Ensure you have a working Drupal 10 installation.
- Facets Module: Provides the core functionality for faceted search.
- Search API Module: Allows you to create custom search indexes and query backends.
- Views Module: It is used to create custom displays of content, including search results.
- Search Backend (Optional): To use advanced functionality, install a backend like Apache Solr or Elasticsearch for robust indexing and querying.
- Web Server: A compatible server setup (e.g., Apache, Nginx).
- Database: Properly configured database (MySQL/MariaDB/PostgreSQL).
By having these prerequisites in place, you’ll be equipped to start building faceted search experiences on your Drupal website.
Looking to build a robust Drupal site with enhanced search functionality?
How to Install and Set Up Drupal Facets Module?
Faceted search is a robust feature that improves user experience by providing dynamic filtering options for search results. Follow these steps to install and configure the Facets module in Drupal:
Step 1: Installing the Drupal Facets
Run the following command to install the Facets module:
composer require drupal/facets
Alternatively, you can do it manually Download the module from Drupal.org Facets project page. Once downloaded, go to Manage > Extend, search for “Facets,” and enable it along with any related dependencies.
Step 2: Configuring the Facets Module
Before configuring the facet you need to create the facets. Here are the steps you may follow:
- Navigate to Configuration > Search and Metadata > Facets (/admin/config/search/facets).
- Click Add Facet and enter:
- Name: A descriptive label for your facet.
- Data Source: The search index created using the Search API.
- Field: Select the field you want to use for filtering (e.g., taxonomy terms, authors).
- Choose a widget type for displaying the facet (e.g., checkboxes, links, dropdown).
Step 3: Place the Facet Blocks
Each facet creates a corresponding block in the Block Layout interface. To place it in block and configure it:
- Navigate to Structure > Block Layout (/admin/structure/block).
- Locate the facet blocks (e.g., “Facet: Tags”) and assign them to a region (e.g., sidebar).
- Set block visibility conditions to ensure facets appear only on relevant pages (e.g., search results).
Step 4: Test and Adjust
Navigate to the search results page to verify the facet functionality. If necessary, rebuild the Search API index to reflect changes. To make changes, you can go to Configuration > Search and Metadata > Search API and select Rebuild Index.
By following the above steps you can have a basic setup of Drupal Facets module. If you want to build a website with dynamic functionality, get in touch with our Drupal development company.
Using Drupal Facets for Implementing Faceted Search
Faceted search enables users to dynamically filter search results based on various fields or categories, making navigation efficient and intuitive. Here’s a stepwise guide to set up faceted search in Drupal using the Facets module.
Step 1: Enable the Modules
Start by ensuring the necessary modules are installed and enabled to facilitate the creation of a faceted search. Install and enable the Facet module and Search API module using Composer or Drupal’s admin UI.
composer require drupal/facets drupal/search_api
Enabling these modules sets the foundation for creating faceted search in Drupal.
Step 2: Creating Content Types
Create the content types that you want to include in the faceted search. You can use default content types or create new ones.
- Navigate to Structure > Content types and click on Add content type.
- Provide a name and description for your content type.
- Add the fields you want to include in the faceted search.
- Save the content type.
Defining content types ensures that the relevant data is available for indexing and searching.
Step 3: Configure the Search Server
Set up a search server to manage and execute queries for your faceted search.
- Go to Configuration > Search and Metadata > Search API.
- Add a new search server (e.g., Apache Solr or Database search) and configure it as needed.
- Save the configuration.
Configuring the search server ensures that your content is indexed efficiently.
Step 4: Configuring the Search Index
Create and configure a search index to process the content for searching and filtering.
- Navigate to Configuration > Search and metadata > Search API.
- Click on Add index.
- Provide a name for your index (e.g., data_index).
- Select Content as your datasource.
- Choose the content types (bundles) you want to index.
- Select the server you created (e.g., data server).
- Enable the Index items immediately option.
- Save the configuration.
Configuring the search index ensures that only relevant content is indexed, improving search performance.
Step 5: Add Fields for Indexing
Add the fields that you want to include in the search index. These fields will be used for filtering in the faceted search.
- Navigate to Configuration > Search and metadata > Search API.
- Select your index (e.g., data_index) and go to the Fields tab.
- Click on Add fields and select the fields you want to index.
- Save the configuration.
Adding fields for indexing ensures that the relevant data is available for faceted search filters.
Step 6: Index the Content
Start the indexing process to populate the search index with your content. This step makes the content searchable.
- Navigate to Configuration > Search and metadata > Search API.
- Select your index (e.g., data_index) and go to the View tab.
- In the Start Indexing Now section, click on Index Now.
- Monitor the progress bar to ensure all items are indexed.
Indexing the content ensures that all relevant data is available for searching and filtering.
Step 7: Create a View
Create a view to display the search results to your users. This view will be the frontend of your faceted search.
- Navigate to Structure > Views > Add new view.
- Provide a name for the view.
- Under View Settings, select the index you created.
- Create a page for your search results by checking Create a page.
- Provide a name and path for the page.
- Under Items to Display, select the number of results to display.
- Under Page Display settings, select the format for displaying results (e.g., Unformatted list).
- Save the view.
Creating a view ensures that the search results are displayed in a user-friendly manner.
Step 8: Add Fields to the View
Add the indexed fields to the view to display the relevant data in the search results.
- Go to Structure > Views and edit your view.
- Click on Add next to the Fields section.
- Select the fields you indexed earlier.
- Under Render Settings, select Link to Content to make the results clickable.
- Save the view.
Adding fields to the view ensures that the relevant data is displayed in the search results.
Step 9: Configure the Facets
Configure the facets to create the filters that users can apply to refine their search results.
- Navigate to Configuration > Search and metadata > Facets.
- Click on Add facet.
- Select the view you created as the Facet Source.
- Select the field you want to use for the facet.
- Provide a name for the facet.
- Save the facet.
- Configure the display settings, such as the widget type (e.g., List of links).
- Select Transform entity ID to label to avoid displaying machine names.
- Save the configuration.
Configuring the facets ensures that users can filter search results based on relevant criteria.
Step 10: Place the Facet Blocks
Place the facet blocks in the desired regions of your page to make them accessible to the user.
- Navigate to Structure > Block layout.
- Select the region where you want to place the facet block (e.g., Sidebar).
- Click on the Place block next to the selected region.
- Search for the facet name and click on Place block.
- In the Configure Block section, provide the search page path.
- Give a display name for the block and select Display title if needed.
- Save the block.
Placing the facet blocks ensures that users can easily access and use the filters to refine their search results.
By following the above steps, you can create a robust and user-friendly faceted search experience using the Drupal Facets module. This feature enhances the search functionality on your site, making it easier for users to find the content they are looking for.
Need expert assistance with your Drupal project?
FAQs About Using Drupal Facets
Wrapping Up
Efficient navigation and precise search functionality are essential for enhancing user experience on content-rich websites. Faceted search, enabled by Drupal’s Facets module, allows users to filter and refine search results dynamically, enhancing user experience.
By setting up the required modules with the required configuration, you can have a faceted search on your website. When creating the facets, ensure to keep them relevant to the content of the page. That will make the searching process for users simple and quick.
If you are looking to build a website with dynamic functionality, hire Drupal developers.