One of the best ways of improving user experience on your WordPress websites is to have a speedy and accurate search. While the default search can be quite effective on websites with limited amounts of data, it’s speed can become problematic (slow) as traffic and data increases. This is why, in this case, you should replace your WordPress search with a high performance search engine. But where do you start? Vespa is an easy choice, since it is probably the one with the best price to performance ratio.
What is Vespa.ai ?
While the default WordPress search (and many other search plugins such as Relevanssi or Ivory search) use simple SQL queries to find matching posts in the WP database, Vespa is optimized for information retrieval tasks.
As you can see in the chart above, a search engine is a far more scalable solution when there is high traffic and amount of data (in this case, WPSolr is a search plugin that makes use of Vespa among others).
So it is no surprise that you would want to equip your website with a Vespa for little to no extra cost.
Integrate a locally installed Vespa search engine into your WordPress
1. Install Vespa and WordPress (using Docker)
We are going to use docker containers to host the different applications. To install the docker engine, use the following link : https://docs.docker.com/engine/install/.
Also, don’t forget to install docker-compose.
Create the following “docker-compose.yml” file :
version: "3.8"
services:
vespa:
image: vespaengine/vespa
volumes:
- vespa-volume:/opt/vespa/
ports:
- '8080:8080'
- "19071:19071"
networks:
- frontend-wpd
wp:
image: wordpress:php8.2-apache
volumes:
- wp-volume:/var/www/html
ports:
- 80:80
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
networks:
- backend-wpd
- frontend-wpd
db:
image: mysql:latest
volumes:
- db-volume:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
networks:
- backend-wpd
networks:
backend-wpd:
frontend-wpd:
volumes:
wp-volume:
db-volume:
vespa-volume:
Make sure that the WordPress & Vespa containers are in the same network so they can communicate with eachother.
The volumes or bind mounts will save the data on your host machine. This ensures that there will be no critical data loss if anything happened to the container.
2. Add locally hosted Vespa to your WordPress using WPSolr Free
WPSolr is a WordPress search plugin that powers up WordPress search using fast, accurate and scalable search engines. This means it can integrate Vespa into any WordPress wesbite.
Since this is a locally installed Vespa server, you can use the free version : WPSolr Free.
You can search for WPSolr in the WordPress plugins catalogue.
Click on the install and activate buttons for the WPSolr plugin.
Once you have installed and activated the WPSolr Free plugin, you can configure it.
To do that you first need to open the WPSolr settings page.
Create the Vespa.ai index
To add your WordPress data to your Vespa search engine, you first need to create an index. You can do that directly from WPSolr.
This portion will teach you how to create your index on your locally installed Vespa server.
Open the indexes tab in the WPSolr dashboard.
Create a new index.
Create the index by doing the following :
- Select Vespa.ai search engine.
- Select the name of the index in the Vespa search engine.
- Set the Vespa urls for the admin and container clusters :
- if the WordPress server is a container in the same docker network as Vespa, you need to enter the name of the service (the one in the docker-compose.yml file). For this example, it should be “vespa”.
- if the WordPress is on a separate server than Vespa, you need to enter the ip address or hostname of the Vespa server.
- Select if you want to install a vectorizer for your Vespa server. This will enable AI search. Select the “sentence-transformers/all-MiniLM-L6-v2” in the drop-down list.
You can now save your index.
Index your data
Once you have created your index, you can click on “2. Define your search” tab.
Click on the “2.2 Data” tab.
Select the data types you want to index. You can do that by simply checking the boxes.
Click on the “3. Send your data” tab.
Check the boxes of the data you selected previously. You can then click on the “Index selected post types” button to index the data.
Configure your search
This section will focus on replacing the WordPress search with WPSolr search powered by your Vespa search engine.
Click on the “2. Define your search” tab.
Select the index you created previously. In this example, “local_vespa”.
Select the archives to replace with WPSolr search. This means that the filtering sorting, etc… of content in the search pages and homepage will be handled by WPSolr and Vespa.
Since you have selected “Search archive”, it should now be used whenever your use a search bar.
Enable AI search
If you want to enable Vespa AI search, you will need to have installed a text vectorization model (“sentence-transformers/all-MiniLM-L6-v2”) in the “0. Connect your indexes” phase of the setup process.
If that is true, in the “2. Define your search” tab, select the search type of your choosing from a drop-down list.
Here are your options :
- Text search only : Only use the default keyword search. Disables AI search.
- Text Vector search only : Enables full AI search.
- Text Hybrid search : Combines multiple search algorithms to improve the accuracy and relevance of search results (keyword search + AI search).
3. Add Facets and Ajax search to your WordPress
WPSolr Free can also add Ajax (live) search and facets powered by Vespa to your WordPress websites.
Learn how to add ajax search using WPSolr.
Learn how to add facets using WPSolr.
Conclusion
It is a good idea to integrate search engines like Elasticsearch and Vespa into WordPress to deliver a faster, more scalable and accurate search. You can do precisely that using WPSolr which can integrate a host of search engines into your WordPress and Woocommerce websites.