Step-by-step guide to setting up Apache Solr for WooCommerce

Table of Contents


Apache Solr is an open-source search platform that can handle large and complex data sets. With its powerful features and robust functionality, it has become a popular choice for those looking to implement a search engine in their web applications. In this post, we will guide you step-by-step through the process of setting up Apache Solr for WooCommerce. Additionally, we will show you how to integrate Apache Solr with PHP client embedded in HTML code tags.

Step-by-step guide to setting up Apache Solr for WooCommerce

Before we begin, make sure you have the following requirements:

    • An Apache web server


    • WooCommerce plugin installed and activated in your WordPress installation


    • PHP version 5.6+


Let’s get started:

Step 1: Installing Apache Solr

The first step is to install Apache Solr on your server. You can download the latest version of Apache Solr from the official Apache Solr website. Extract the downloaded file into a folder that you can access from the command line.

Step 2: Configuring Apache Solr

After installing Apache Solr, configure it by following the steps below:

    • Navigate to the solr-{{version}}/example/solr directory


    • Create a new directory called “woocommerce”


    • Copy the contents of solr-{{version}}/example/solr/collection1 directory to the newly created woocommerce directory


Step 3: Configuring WooCommerce

Now, let’s configure WooCommerce to use Apache Solr for search capabilities.

    • Go to WooCommerce > Settings > Products > Display and select “Shop” as the “Shop Page Display” option


    • Next, go to the “Advanced” tab and enable the “Custom product search” option


    • Scroll down to the “Custom product search endpoint” option and enter the URL of your Apache Solr instance followed by “/solr/woocommerce/select”


Step 4: Indexing Products

Next, the products need to be indexed using Apache Solr. Run the following command:

curl -X POST -H 'Content-Type: application/json' --data-binary '@products.json' 'https://localhost:8983/solr/woocommerce/update?commit=true'

Assuming you have the list of all the products in a JSON file called ‘products.json’.

Step 5: Searching Products

The final step is to search for products using Apache Solr. Use the following code snippet:

$client = new SolrClient(array(
    'hostname' => 'localhost',
    'port'     => 8983,
    'path'     => '/solr/woocommerce'
$params = array(
    'q'        => 'product_name:blue',
    'fl'       => 'id,product_name,price',
    'sort'     => 'price asc'
$query = new SolrQuery();
$resp = $client->query($query);
print_r(json_decode($resp->getRawResponse(), true));

Once you’ve implemented the above steps, Apache Solr should be set up and running properly for WooCommerce.

How WPSOLR can help

WPSOLR is a popular plugin for WordPress and WooCommerce that can drastically simplify the process of setting up Apache Solr for WooCommerce. WPSOLR integrates seamlessly with WooCommerce and provides a straightforward way to configure, index, and search products using Apache Solr. Additionally, the plugin offers many advanced search features that can take the search capabilities of your WooCommerce website to the next level.


In this post, we’ve shown you a step-by-step guide to setting up Apache Solr for WooCommerce. By following these steps, you can enable powerful search capabilities on your WooCommerce website. Using the provided PHP client embedded in HTML code tags, you can easily set up searching products. Additionally, we mentioned WPSOLR as a solution that can help you implement Apache Solr in your WooCommerce website even more easily and offer advanced search functionality.

Read more related content