Advanced Site Search Capabilities with Relevanssi
Introduction
The search features in WordPress CMS involve limitations like no prioritization of content type for search results, inability to search for attachments, and no customization of the interface. These limitations can be tackled with different plugins. Relavanssi is one such plugin that can offer the above features and is integrated with the FacetWP plugin to achieve faceted search. Read further to know about the above-mentioned plugins and the integration process in detail.
Why Relevanssi?
The search feature that ships with the WordPress CMS is quite limited. For eg. it doesn’t search attachments, it cannot prioritize which content to show first and it doesn’t permit you to customize the look-feel of the search results. To get around these limitations, there is a robust marketplace for WordPress search plugins such as SearchWP, Jetpack Search and others. Relevanssi is widely considered the leader in this space.
The Use case
The client is an insurance company and had the following types of content (all of which were modeled as Custom Posts):
- Employees
- Experts
- Insight Articles that were written by Experts
- News Publications that mentioned Experts
- 3rd Party News Mentions
- Leadership Team
- Specialty Products
- Practice Areas
- Offices
In addition to these, there were regular WordPress entities such as:
- Pages
- Media
- PDFs
When a user searched on the site, there were several requirements:
- We had to show relevant content from the various post types along with the # of results in each category
- There were different weights for these content types. For eg. Specialties were weighted more than regular pages and were required to show up higher in the search results.
- “Faceted” search was requested. As the user clicked on different categories, we had to filter the results accordingly. The users could also remove their selections to go back to earlier states of the search parameters (as shown above)
- We had to exclude certain post types in the search results
- The user could sort the search results alphabetically or chronologically
- We had to highlight the search term within the search results.
- We had to enable synonyms. For example, when the user searched for say “Commercial Property”, we were supposed to search for “Real Estate” as well.
- Finally, the user could filter the search results based on the publish date (Past week, Past month etc)
Getting Started with Relevanssi
After installing the Relevanssi plugin, you can navigate to the dashboard :
After doing the basic setup, you can index all the content. There are quite a few options here, in terms of what you want to include in the search vs. not.
As mentioned in the use case, the client wanted certain post types to show up higher. (For eg. specialties should be weighted higher than say insight articles). To achieve this in Relevanssi, you can navigate to the “Searching” tab. Here you will be able to assign weights as required:
There are many other options that allow you to tune your search results carefully.
Finally, you can configure synonyms for search terms as well
Combining Relevanssi with Faceted Search
The client’s requirements needed for us to show Relevanssi search results in a Faceted search mode.
To achieve this, we used the FacetWP plugin along with Relevanssi. For our detailed article on how to use FacetWP, go here.
Install FacetWP and when you go to create a “New Facet”, select “Search” as the Facet Type
And then select Relevanssi as the Search Engine
Now configure the query to point to the different post types that need to be searched for, and also any posts that shouldn’t be included in the search. (see below)
At this stage, you can define how you want the query results to show up:
These steps will now result in the search page showing up as desired:
The final step involved building the “Sort By” functionality. We built a simple PHP function to enable this capability as shown below:
Summary:
Site search — that lets users search for content on a website — is commonly requested, yet is hard to do well. We discussed the Relevanssi search plug-in and how it helps to deliver relevant results and enables a customized user experience on a WordPress site. We also reviewed how to integrate it with FacetWP to enable faceted display of the search results.