WordPress built in search system
When it comes to WordPress search, both developers and users are not big fans of the built-in search system. The former finds it hard to customize and make it suitable for their specific needs, whilst the latter tend to complain about overall slow performance when searching for specific word, especially when the number of posts present in the database is large.
Unfortunately, WordPress search is slow by its nature since it can only use SQL queries and it is not designed for full-text searches.
On top of this, the built-in search system is very limited from a functional point of view. It just literally searches in the database and returns results, adding anything other than this to your site, for example filtering system, which requires extra development effort. WordPress offers some hooks which let you modify the default search query. It also gives you control over basic parameters such as post type in which you want to search etc.
Fortunately, as usually in WordPress, we can make use of one of many WordPress plugins out there. These customize default WordPress search behaviour, make it configurable and make search results more relevant. Some of the plugin incorporate AJAX which improves user experience to some extent and boost perception of speed, as page reload is no longer the case. With the aim of custom code and search plugins you can make more out of WordPress search.
For small brochure sites, when you need to help your users navigate through a dozen or so pages, the built-in search system is enough.
At a certain point though, WordPress search plugins and your MySQL database will not be able to handle it anymore. Remember that the bigger your database is, the more time it will take to execute your search queries. With tens of thousands of posts or products in the database, it is a matter of time when your client or your users will start complaining that search is not good enough and you need to do better. It is not surprising, as with such a high volume of content in database, the importance of well performing search is much bigger.
When you need more than MySQL powered search. You should start looking for alternative search engines known for their speed, scalability, and stability. One of the most well-known alternatives is “Elasticsearch”, a service from AWS. You can integrate it with WordPress thanks to the “Elasticpress” plugin. I used to work with “Elasticpress” on a few occasions and I found it pretty hard to customize. Especially when a client required to customize a relevance algorithm, which isn’t something that can be controlled in the plugin settings page. Using this stack also involves certain amount of DevOps work which can sometimes be a challenge as well.
During one of my recent projects, I had an opportunity to work with just another alternative search engine that you can integrate with WordPress. This was a huge and astonishing discovery!
“Algolia” is a powerful, hosted search API that helps to create fast and relevant search experiences in your application. When it comes to WordPress, it can be integrated with your sites by using a plugin called “WP Search with Algolia”. Indexing your content is fast and easy (an index is the place where the data used by a search engine is stored). However, might require some preparation work, e.g., you might want to just synchronize specific post types. Plugin comes with a bunch of hooks which are there to make this happen.
When it comes to mentioned project, main assumptions of the project were as follows:
- it must work in WordPress multisite install (separate content indexes for each site)
- support for auto-complete feature (also known as auto-suggest)
- instant search experience (search results should reload as you type in)
- searching two independent sources of data at the same time (federated search)
- filtering by various taxonomies
- sort by date (and date ranges), relevance, alphabetically
- support for pagination and infinite scroll
- support for highlighting
- full control over feel & look
- admin should be able to manage relevance and other settings in Algolia dashboard (rather than let the controll be in WordPress or within code)
Plugin “WP Search with Algolia” offers two modes: Use of Algolia in backend and use of Algolia with InstantSearch.js. The latter option is where all the magic happens, and it allows to achieve all the goals outlined above.
Apart from all mentioned features, Algolia offers much more. One of the things I like a lot about Algolia is that you can manage all these amazing and robust features within the Algolia dashboard.
Other features worth mentioning are:
- Analytic tools to understand your user behaviour
- A/B testing
- Custom ranking which helps in building your own search algorithm
- Synonyms support and dynamic synonyms suggestion
- Users’ personalization
- It is language-agnostic
Live demo together with some code samples of the search application built with Algolia and InstantSearch.js can be seen here.
WordPress and Algolia summary