WordPress has built-in search functionality. However, this search functionality is not very good for websites with many articles. I enhance our on-site search with a simple and lightweight WordPress plugin called Relevanssi Light. Relevanssi Light is mostly set-it and forget-it. It uses full-text indexes that already exist in the WordPress-powered site’s server and delivers better results than the default search for a site like this one with many articles and words. However, there have been times when I want to quickly find a specific article that I wrote but our improved search is not quite up to the task. See for example my recent short posts about a typo and subsequently finding what I was looking for. These niggles, combined with my not being entirely satisfied with how our search handled a query I was testing, inspired me to look into extending our search functionality.
(Aside: I first tried Relevanssi Light way back in 2021. It did not seem like it was doing anything and that prompted me to switch to the much more robust Relevanssi plugin. It was not doing anything – but that was because our database was using InnoDB tables instead of MyISAM tables. After I updated to MyISAM I tested Relevanssi Light again and determined that it was good enough for our use-case, especially given how much lighter it is than the full Relevanssi plugin.)
Relevanssi Light differs from its more robust cousin, Relevanssi, in that it does not have any options in the WordPress admin area other than one to process all posts. The plugin’s behavior is instead modified by filter hooks which are explained in its documentation. These hooks can be added to the active theme’s functions.php file or as custom plugins. I added one to include SEO meta descriptions from our SEO plugin, The SEO Framework, to Relevanssi Light’s search. When I decided that I had some more demanding search use-cases, I decided to test another special option: Activating boolean search mode.
By default, Relevanssi Light is in natural language mode. The plugin documentation explains what this means:
In Natural language mode there are no special operators and searches consists of simple keywords.
Conversely, boolean mode allows the searcher to use special operators to refine the search term. The documentation notes that natural language mode is default because “it’s the better choice for a large majority of cases,” but I determined that The New Leaf Journal, with well over 1,000 (often long) articles and shorter posts, may not be one of the majority of cases. But you never know, so I decided to try activating boolean mode to test. As provided by the documentation, boolean mode is activated with a simple filter hook:
add_filter( 'relevanssi_light_boolean_mode', '__return_true' );
The benefit of boolean mode is that searchers can use special operators to make more specific queries against our full text index. I referred to the resource recommended in the Relevanssi Light documentation for a list of all of the available special operators.
I tested some queries and found that it is possible for me to do some significantly more targeted searches, especially with the + and – operators and the double quotes. I have not tested the other operators yet (those may be too granular for ordinary New Leaf Journal searches), but just having the first three is convenient – even granting I am still getting the hang of how they work. My testing indicates that if you perform a search without any special operators, the results are the same as our natural language results.
I will keep the boolean search enabled for now and likely continue to do so unless I run into a problem. If you want to try it, give it a spin and let me know if you run into anything that can be improved.