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? Apache Solr is an easy choice, since it is probably the one with the best price to performance ratio.
What is Solr ?
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, Solr 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 Solr among others).
So it is no surprise that you would want to equip your website with a Solr for little to no extra cost.
Integrate a locally installed Solr server into your WordPress
1. Install Solr
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 :
services:
solr:
image: solr:latest
ports:
- 8983:8983
And start the container using :
docker-compose up -d
You can check if the the container was correctly created using :
docker ps
Using the downloaded certificate, you can now connect to the Solr service.
For more complete instructions about Solr installation, check out our documentation.
Setup WordPress (Optional)
If you don’t already have an active WordPress server, you can set it up locally.
Simply edit the previously created “docker-compose.yml” file with the following modifications :
version: '3.9'
services:
wp:
image: wordpress:php8.2-apache
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:5.7
environment:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
networks:
- backend-wpd
solr:
image: solr:latest
ports:
- 8983:8983
networks:
- frontend-wpd
networks:
frontend-wpd:
backend-wpd:
Make sure that the WordPress & Solr server are in the same network so they can communicate with eachother.
If this is a production configuration, you should use volumes or bind mounts to 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 Solr 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 Solr into any WordPress wesbite.
Since this is a locally installed Solr 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 Solr index
To add your WordPress data to your Solr server, 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 Solr server.
Open the indexes tab in the WPSolr dashboard.
Create a new index.
Create the index by doing the following :
- Select Solr search engine.
- Enter the name of the index that will be displayed in the WPSolr settings.
- Set the scheme as http.
- Set the Solr host :
- if the WordPress server is a container in the same docker network as Solr, you need to enter the name of the service (the one in the docker-compose.yml file). For this example, it should be “Solr”.
- if the WordPress is on a separate server than Solr, you need to enter the ip address or hostname of the Solr server.
- Set the port of the Solr.
- Set the path of the index on the Solr server.
You can now save your index. A set of instructions to configure the Solr server should appear like so :
First, you should install unzip on the solr server (will be used later) :
docker exec -u 0 -it <em>your_solr_container</em> bash -c "apt update; apt install unzip"
Then you can open a shell in the container :
docker exec -it your_solr_container /bin/bash
Inside it you can then execute the following commands :
mkdir /var/solr/data/configsets
cd /var/solr/data/configsets
curl -L -o solr.zip https://www.dropbox.com/s/aqbhhv4dw41hrmx/wpsolr-v9-0.zip?dl=0
mkdir -p solr_index/conf
unzip solr.zip -d solr_index/conf
We created the solr_index directory because this is what we set for the path when creating the index.
You can then click on the save once again to have a fully working directory.
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 Solr server.
Click on the “2. Define your search” tab.
Select the index you created previously. In this example, “local_solr”.
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 Solr.
Since you have selected “Search archive”, it should now be used whenever your use a search bar.
3. Add Facets and Ajax search to your WordPress
WPSolr Free can also add Ajax (live) search and facets powered by Solr to your WordPress websites.
Learn how to add ajax search using WPSolr.
Learn how to add facets using WPSolr.
Integrate Cloud Hosted Solr (SearchStax) into your WordPress
1. Create a managed Solr deployment in SearchStax.
1 – Signup for a free trial at SearchStax Solr Cloud Manager
2 – Navigate to your SearchStax dashboard
3 – Click on menu “Cloud Manager”
4 – Click on button “Create Deployment -> Solr”
5 – Set the new deployment parameters
- Set a name to your deployment
- Select a Cloud Provider (where your nodes/VMs will be deployed): Amazon Web Service, Microsoft Azur, Google Cloud
- Select a region (depends on the selected Cloud Provider)
- Select a deployment type: Dedicated Node (one node), Dedicated Cluster (several nodes)
- Select a plan (the size of each node/VM)
- Select the Solr version
- Create the deployment nodes
6 – Wait until the deployment is completed
7 – Click on the deployment to change its settings
8 – Copy the deployment endpoint url
9 – Create a user/password to secure the cluster
9.1 Select authentication menu
9.2 Enable authentication: (1) then (2)
9.3 Add user/password: (1) Click on button “Add User”, (2)(3) set user/password, (4) Select role “Admin” to be able to create new indexes, (5) Click on button “Add”
9.4 New user/password is created
2. Add fully managed Solr to your WordPress using WPSolr Search
Adding Elastic Cloud to your WordPress requires the premium WPSolr Search. You can easily start a free trial here.
Once you have started your trial you will receive 2 critical items : your license key and your WPSolr zip file.
You can upload the zip file and install WPSolr from the “Add plugins” page :
Once you have installed WPSolr Pro, you can open the WPSolr settings :
To use WPSolr, you need to activate the license :
In the license pop-up window, simply enter the license key and click on the activation button :
Then, in the WPSolr settings, you can create your first index :
Create the SearchStax Solr index from WPSOLR admin
- (1), (2), then (3) to edit a new index
- (4) Select “Apache SolrCloud” among index types
- (5) Select “SearchStax” among Hosting Services
- (6) Set a name for you index, visible in WPSOLR admin
- (7) Set a name for your index, visible in SearchStax Solr admin (only letters and “_”, no whitespaces)
- (8) Paste the SearchStax deployment endpoint url
- (9) Set in how many shards (“pieces”) the index will be distributed (1 for a one node deployment)
- (10) Set how many times each shard will be copied (1 for a one node deployment)
- (11) Set max shards per node/VM
- (12) Paste the searchStax authentication user/password (if defined)
- (13) Create the index
Once you have created your Solr cloud index, the rest of the process is pretty much the same as with the locally installed Solr server. From then on, you can add search, live search and facets powered by Solr quite easily.
Conclusion
It is a good idea to integrate search engines like Elasticsearch and Apache Solr 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.