WordPress is a powerful CMS that currently powers 40% of the websites worldwide. It can allow the users to build fully functioning websites in minutes and provides a default search. But how effective is this default search. Short answer : not a lot. In this guide, you will learn about the inner workings of this WordPress search and how you could improve it.
How does default WordPress search work ?
Default WordPress search works using SQL. While it is convenient since no further setup is needed, it has a few downsides :
1. Can be slow
The default search can be slowed down for a few reasons :
- Running on the same hardware : since both your WordPress applications and database run on the same hardware, using you MySQL database for search can have negatively effect your websites performance and vice versa.
- default SQL is not optimized for information retrieval : while search engines are designed to scale horizontally and vertically as data volume and traffic increases, the wordpress SQL database can stuggle to keep up because of it’s unoptimal architecture. This is because search engines make use of inverted indexes whereas using SQL, the WordPress search loops through each and every item in the ever-increasing wp_posts table.
2. Irrelevant results
The default search will not deliver accurate results since they are fetched using this simple SQL query :
SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts WHERE 1=1
AND (((wp_posts.post_title LIKE '%shirt%') OR (wp_posts.post_excerpt LIKE '%shirt%') OR (wp_posts.post_content LIKE '%shirt%')))
AND ((wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private'))
OR (wp_posts.post_type = 'page' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private')) OR (wp_posts.post_type = 'attachment' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private'))
OR (wp_posts.post_type = 'e-landing-page' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private')) OR (wp_posts.post_type = 'product' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private')))
ORDER BY wp_posts.post_title LIKE '%shirt%' DESC, wp_posts.post_date DESC LIMIT 0, 10;
As we can see, this will return items that contain the word “shirt”. But this means that only full-text search works with default search. To have more accurate results, oftentimes partial or fuzzy search are used. This means that if a user searched for the word “tee shirt”, none of the posts that include the word “shirt” only, would be taken into account.
Additionally, the default WordPress search lacks scoring functionality. Scoring is integral to search engines as it represents the relevance of items or documents, determining their ranking in the search results. Unlike SQL searches, where results are typically either present or absent, the scoring mechanism assigns a score to each document, dictating its position in the results list based on relevance rather than mere inclusion.
3. Lack of customization
Usually professional and successful websites will offer customization to it’s users. The default WordPress search offers zero customization.
Firstly, it is important that only the correct posts or post-types are searchable. For example, an e-commerce would want their search to only include products. And they could also want out-of-stock products to be hidden. This is not possible with default WordPress search. As you can see in the SQL query above, it searches indiscriminately for all the public items in wp_posts table.
You could also need facets. Facets, also called filters, are front-end components that the users can interact with to display precisely the items they want to see based on their taxonomies and fields. Very prominent in e-commerce websites, they greatly improve user experience and engagement. For more information on facets, you should check out our guide.
How to measure your WordPress search speed using Query monitor
Query monitor is a developer tool for wordpress and tracks database queries. You can use this to time your search queries and page load.
In the image above, we can view the following data :
- Page load time (0.2978 seconds) : This indicates the total time to compute the data and load the page.
- Memory usage (17.4MB) : Indicates the server memory used to load the page.
- Database queries time (0.0246s) : This takes into account the total time all of SQL queries executed in the back-end.
- HTTP API calls (none) : Indicates the time of execution of any and all API calls by your server.
Using this window, you can see the total time on the bottom right (0.0028s) and each individual query is displayed. The search query that was responsible for retrieving the relevant items can be seen in the center and took 0.0015 seconds.
How to improve your WordPress search
To improve the WordPress search, you could make use of WordPress search plugins. They can greatly improve both search accuracy (relevancy) and speed.
You could check out our top 8 WordPress search plugins list but if you truly want an enterprise grade search experience for your WordPress or Woocommerce website, WPSolr is really the only solution.
WPSolr is a WordPress search & recommendations plugin that offers everything you would want and need : WordPress search, ajax live search, facets (or filters) and even AI based recommendations.
All of these features are powered by world-class search engines that can deliver keyword, AI, image or personalized search, whichever one you need.