Demystifying Solr for WordPress Search on Pantheon

Made on

A WordPress SOLR search solar eclipse
ESA's PROBA-2 View of Europe's Solar Eclipse” by NASA Goddard Photo and Video is licensed under CC BY 2.0.

WordPress’s default search works fine for small blogs, but not larger sites.

WordPress’s built-in database queries become a bottleneck for thousands of posts, complex content types, or features like faceted search and relevance ranking.

Apache Solr solves these problems by replacing WordPress’s MySQL-based search with a dedicated search engine designed for exactly this purpose. On Pantheon, Solr is available as a managed add-on for all plans except Basic, making it straightforward to implement without managing your own search infrastructure.

This guide explains Solr and why you’d use it instead of default WordPress search, how to implement it on Pantheon, and how to measure its impact with Google Tag Manager and Google Analytics/GA4.

What is Apache Solr?

Apache Solr is an open-source search platform built on Apache Lucene. It’s enterprise-grade search software used by companies like Netflix, Apple, and Instagram to power their search functionality.

Unlike WordPress’s default search (which uses MySQL LIKE queries), Solr is purpose-built for full-text search. It creates an index of your content, analyzes text intelligently, and returns results ranked by relevance – similar to how Google ranks search results.

History and background:

Solr was created by CNET Networks in 2004 to handle search for their technology news sites. They needed something more powerful than database queries for searching thousands of articles. In 2006, CNET donated Solr to the Apache Software Foundation, where it became a top-level Apache project.

The “Solr” name doesn’t stand for anything – it was chosen because it’s short, unique, and related to “search” conceptually (like “solar” powers things with light, Solr powers sites with search).

How Solr differs from WordPress search:

WordPress default search uses SQL queries like:

sql

SELECT * FROM wp_posts 
WHERE post_title LIKE '%keyword%' 
OR post_content LIKE '%keyword%'
ORDER BY post_date DESC

This approach:

  • Searches for exact text matches only
  • Doesn’t understand word relationships (singular vs. plural, synonyms)
  • Can’t rank by relevance (just sorts by date)
  • Gets slower as content grows
  • Hits your database on every search

Solr indexes your content separately:

  • Understands word stems (“running” matches “run”)
  • Ranks results by relevance (how well they match the query)
  • Returns results in milliseconds, even with thousands of documents
  • Doesn’t impact your WordPress database
  • Enables faceted search (filter by category, tag, date, custom fields)

Why Use Solr for WordPress?

Most WordPress sites don’t need Solr. The default search works fine for blogs with a few hundred posts. But Solr becomes valuable in specific scenarios.

When Solr Makes Sense

Large content libraries:
Sites with 5,000+ posts, custom post types, or multiple content types benefit from Solr’s speed and relevance ranking. A university with 10,000 course pages, news archive, faculty profiles, and research papers needs better search than MySQL can provide.

E-commerce and catalogs:
WooCommerce stores with hundreds or thousands of products need faceted search – filtering by price, brand, size, color, availability. Solr makes this fast and practical.

Job boards and directories:
Sites where users search and filter by multiple criteria (location, salary range, experience level, job type) need Solr’s faceting capabilities.

News and publishing sites:
Publications with years of archived content need relevance ranking to surface the most useful articles, not just the newest ones.

Membership and community sites:
Forums, knowledge bases, and membership sites with extensive user-generated content benefit from Solr’s ability to search across post types, taxonomies, and custom fields.

Key Benefits of Solr

Faceted search and filtering:
Users can refine results by clicking filters – like Amazon’s left sidebar. “Show me WordPress plugins, written in the last year, tagged with ‘security’, by authors I follow.” This requires zero custom code.

Relevance ranking:
Solr scores results based on how well they match the query. Articles with your search term in the title rank higher than those with it buried in the content. You can boost certain fields (title more important than body) or recent content.

Performance:
Solr handles searches across millions of documents in milliseconds. It doesn’t slow down as your content grows because it uses inverted indexes optimized for text search.

Custom field search:
Search Advanced Custom Fields (ACF), custom taxonomies, post meta, basically anything you can index. A real estate site can search properties by bedrooms, bathrooms, square footage, and neighborhood without custom database queries.

Better matching:
Solr understands stemming (run, running, runs all match), synonyms (car = automobile), and stop words. Searches feel more natural and forgiving than exact text matching.

When NOT to Use Solr

Small sites under 1,000 posts:
The complexity isn’t worth it. WordPress default search is fine, or use a plugin like SearchWP or Relevanssi.

Simple search requirements:
If you just need basic keyword search sorted by date, don’t add Solr’s complexity.

Basic plan on Pantheon:
Solr isn’t available on Pantheon’s Basic plan. You’d need to upgrade or use an external Solr service.

No technical resources:
Solr requires initial setup, schema configuration, and ongoing maintenance.

How Solr Works: Core Concepts

Before implementing, understand these fundamental concepts.

Index vs. Database

WordPress stores content in MySQL tables. Solr creates a separate index – a specialized data structure optimized for search.

Think of it like a book’s index: instead of reading every page to find mentions of “WordPress,” you look in the index which tells you exactly which pages contain that word. Solr’s index includes:

  • Every word in your content (title, body, custom fields)
  • Where those words appear
  • How often they appear
  • Relationships between words

Schema

The schema defines what fields Solr indexes and how to treat each field. Default Solr Power schema includes:

  • post_title – searchable, stored, boosted (most important)
  • post_content – searchable, stored
  • post_date – sortable, facetable
  • categories – facetable
  • tags – facetable
  • author – facetable

You can customize the schema to add custom fields, change boost values, or modify how text is analyzed.

Documents

In Solr terminology, each indexed item is a document. For WordPress, each post, page, or custom post type becomes one Solr document with fields mapping to WordPress data.

Facets

Facets are the filters you see on search results (like Amazon’s left sidebar). Solr counts how many results match each facet value:

  • Category: News (45), Tutorials (32), Reviews (18)
  • Date: This Week (12), This Month (89), This Year (234)
  • Author: John (67), Jane (54), Mark (43)

Users click facets to refine results without running new searches.

Commits

When you add/update/delete content in WordPress, Solr doesn’t update its index immediately. Changes must be committed before they appear in search results.

On Pantheon, Solr commits happen:

  • Every 2 minutes for uncommitted changes
  • Every hour via WordPress cron
  • Manually via WP-CLI or plugin actions

You can enable auto-commit (commits immediately on every change) but this impacts performance. Pantheon recommends keeping auto-commit disabled.

Free consultation

Or need WordPress support? We’ve completed 50+ migrations and can help you avoid the common pitfalls.

Implementing Solr on Pantheon: Step by Step

Pantheon provides Solr 3.6 as a managed service. Here’s how to set it up.

Step 1: Enable Solr Add-On

Via Pantheon Dashboard:

  1. Navigate to your Pantheon Site Dashboard
  2. Go to Settings > Add Ons
  3. Click “Add” under “Apache Solr Index Server”
  4. Wait 2-3 minutes for Pantheon to provision Solr containers

Via Via Terminus:

bash

terminus solr:enable 

Pantheon creates a separate Solr instance for each environment (Dev, Test, Live). Credentials are managed automatically – you don’t need to configure connection details.

Step 2: Install Solr Power Plugin

Install and Activate the Solr Power plugin via Terminus:

bash

terminus wp <site>.<env> -- plugin install solr-power --activate

Or install manually:

  1. Download from https://wordpress.org/plugins/solr-power/
  2. Upload to /wp-content/plugins/solr-power/
  3. Activate via WordPress Admin

Important: Solr Power is developed by Pantheon specifically for their Solr service. Don’t use generic Solr plugins – they won’t work with Pantheon’s configuration.

Step 3: Configure Indexing Options

Go to Settings > Solr Power > Indexing tab.

Select post types to index:

  • Posts
  • Pages
  • Custom post types (products, events, etc.)
  • Attachments usually not needed

Select taxonomies to index:

  • Categories
  • Tags
  • Custom taxonomies

Custom ACF: By default, Solr Power doesn’t index custom fields. To index ACF or post meta:

  1. Create /wp-content/uploads/solr-for-wordpress-on-pantheon/schema.xml
  2. Add custom field definitions
  3. Go to Solr Power > Actions
  4. Click “Repost schema.xml”

Example schema modification for ACF fields:

xml

<!-- Add to schema.xml -->
<field name="event_date" type="date" indexed="true" stored="true"/>
<field name="event_location" type="text" indexed="true" stored="true"/>

Then use the solr_build_document filter to add custom field data:

php

add_filter('solr_build_document', 'add_custom_fields_to_solr', 10, 2);

function add_custom_fields_to_solr($doc, $post_info) {
    if (get_post_type($post_info->ID) === 'event') {
        $doc->addField('event_date', get_field('event_date', $post_info->ID));
        $doc->addField('event_location', get_field('event_location', $post_info->ID));
    }
    return $doc;
}

Step 4: Index Your Content

Go to Settings > Solr Power > Actions tab.

Click “Execute” next to these actions:

  1. Delete All – Clear any existing index
  2. Index Searchable Post Types – Index all posts/pages/CPTs
  3. Optimize Index – Improve search performance

For large sites, indexing can take time so Pantheon recommends using Terminus for better reliability:

bash

# Index via Terminus
terminus wp <site>.<env> -- solr index

# Check index status
terminus wp <site>.<env> -- solr info

# Optimize index
terminus wp <site>.<env> -- solr optimize

Indexing considerations:

For sites with 10,000+ posts, index in batches to avoid timeouts:

php

// Add to wp-config.php or mu-plugin
define('SOLR_POWER_BATCH_SIZE', 500); // Default is 500

Step 5: Configure Search Behavior

Go to Settings > Solr Power > Results tab.

Results per page:
Set how many results to show (default: 10)

Boost fields:
Control which fields matter most for relevance:

  • Title: 3x (default)
  • Content: 1x (default)
  • Tags: 2x
  • Categories: 2x

Higher boost = more important in ranking.

Sort order:

  • Score (relevance) – default
  • Date (newest first)
  • Title (alphabetical)
  • Custom (via code)

Step 6: Enable Facets (Optional)

Facets allow users to filter search results. Enable them under Settings > Solr Power > Facets.

Enable AJAX faceting:

Enable AJAX Facet Search Support

  • Set AJAX Div ID (where results appear): primary or main

Select facets to display:

  • Categories
  • Tags
  • Author
  • Post Type
  • Date (by year, month, or day)

Add the Solr facet widget to your sidebar (Appearance > Widgets).

For custom facet display in your theme:

php

<?php
// Display facets in search results template
if (is_search() && function_exists('solr_facets')) {
    echo '<div class="search-facets">';
    solr_facets();
    echo '</div>';
}
?>

Step 7: Test Search Functionality

  1. Go to your site’s search page
  2. Enter a test query
  3. Verify results come from Solr (check for relevance ranking)
  4. Test facets (if enabled)
  5. Verify new content appears in results within 2-3 minutes

To confirm Solr is active, check Settings > Solr Power > Info:

  • Ping status should show “Solr is responding”
  • Number of documents should match your indexed content count

Advanced Configuration

Custom Search Templates

Solr Power works with WordPress’s default search templates. To customize, create search.php in your theme:

php

<?php
/**
 * Solr-powered search template
 */
get_header();
?>

<div class="search-results-container">
    <?php if (have_posts()) : ?>
        
        <header class="search-header">
            <h1>Search Results for: <?php echo get_search_query(); ?></h1>
            <p>Found <?php echo $wp_query->found_posts; ?> results</p>
        </header>
        
        <aside class="search-facets">
            <?php
            // Display facets if Solr Power is active
            if (function_exists('solr_facets')) {
                solr_facets();
            }
            ?>
        </aside>
        
        <main class="search-results">
            <?php while (have_posts()) : the_post(); ?>
                <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
                    <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
                    
                    <div class="meta">
                        <?php echo get_the_date(); ?> | <?php the_category(', '); ?>
                    </div>
                    
                    <div class="excerpt">
                        <?php the_excerpt(); ?>
                    </div>
                    
                    <!-- Solr returns relevance score -->
                    <?php if (isset($post->solr_score)) : ?>
                        <div class="relevance-score">
                            Relevance: <?php echo round($post->solr_score * 100); ?>%
                        </div>
                    <?php endif; ?>
                </article>
            <?php endwhile; ?>
            
            <?php the_posts_pagination(); ?>
        </main>
        
    <?php else : ?>
        <p>No results found for "<?php echo get_search_query(); ?>"</p>
    <?php endif; ?>
</div>

<?php get_footer(); ?>

Boosting Recent Content

Boost newer content in search results:

php

add_filter('solr_power_query', 'boost_recent_posts');

function boost_recent_posts($query_params) {
    // Boost posts from the last 30 days
    $query_params['bq'] = 'post_date:[NOW-30DAY TO NOW]^2.0';
    return $query_params;
}

Search Specific Custom Fields

Create a custom search form that searches specific fields:

php

add_filter('solr_power_query', 'search_event_location', 10, 2);

function search_event_location($query_params, $query) {
    // If searching on events archive, search event_location field
    if (is_post_type_archive('event') && !empty($query)) {
        $query_params['q'] = 'event_location:' . $query;
    }
    return $query_params;
}

Exclude Posts from Search

Prevent specific posts from appearing in Solr results:

php

add_filter('solr_power_index_post', 'exclude_posts_from_solr', 10, 2);

function exclude_posts_from_solr($should_index, $post_id) {
    // Don't index posts with "exclude_from_search" meta
    if (get_post_meta($post_id, 'exclude_from_search', true)) {
        return false;
    }
    return $should_index;
}

Solr for WooCommerce Implementation

WooCommerce’s default product search works fine for small shops, but struggles with larger catalogs. Solr transforms WooCommerce search into an Amazon-like experience with faceted filtering, relevance ranking, and fast performance regardless of catalog size.

When WooCommerce Needs Solr

Performance bottlenecks:
WooCommerce product search queries the wp_posts table joined with wp_postmeta (for product attributes, prices, SKUs). With 5,000+ products and multiple attributes per product, these queries become slow. Solr indexes everything once and returns results in milliseconds.

Missing features:
Default WooCommerce search doesn’t support:

  • Filtering by price ranges
  • Multi-attribute filtering (size AND color AND brand)
  • Search by SKU or custom product fields
  • Relevance ranking (title matches vs. description matches)
  • Stock status filtering
  • Facet counts (“23 products under $50”)

Solr enables all of these without custom code.

User expectations:
Customers expect Amazon-style filtering. When they search “running shoes,” they want to filter by:

  • Price: $50-$150
  • Brand: Nike, Adidas, New Balance
  • Size: 10.5
  • Color: Blue, Black
  • In Stock only

Without Solr, you’d need to build this filtering system from scratch using complex MySQL queries and custom code, or work something out with FacetWP / AJAX Search Pro.

Configuring Solr for WooCommerce

After enabling Solr and installing Solr Power, configure it for WooCommerce products.

Step 1: Index Product Post Type

Go to Settings > Solr Power > Indexing:

  1. Check “Products” under post types to index
  2. Include product categories and tags
  3. Enable custom field indexing (critical for WooCommerce)

Step 2: Index WooCommerce Product Data

WooCommerce stores product data in custom fields (post meta). You need to tell Solr which fields to index.

Create a custom schema that includes WooCommerce fields:

xml

<!-- Add to schema.xml -->
<field name="_price" type="float" indexed="true" stored="true"/>
<field name="_regular_price" type="float" indexed="true" stored="true"/>
<field name="_sale_price" type="float" indexed="true" stored="true"/>
<field name="_sku" type="string" indexed="true" stored="true"/>
<field name="_stock_status" type="string" indexed="true" stored="true"/>
<field name="product_cat" type="string" indexed="true" stored="true" multiValued="true"/>
<field name="product_tag" type="string" indexed="true" stored="true" multiValued="true"/>
<field name="pa_color" type="string" indexed="true" stored="true" multiValued="true"/>
<field name="pa_size" type="string" indexed="true" stored="true" multiValued="true"/>

Then use the solr_build_document filter to add WooCommerce data to the Solr index:

php

add_filter('solr_build_document', 'index_woocommerce_fields', 10, 2);

function index_woocommerce_fields($doc, $post_info) {
    // Only for products
    if (get_post_type($post_info->ID) !== 'product') {
        return $doc;
    }
    
    $product = wc_get_product($post_info->ID);
    
    if (!$product) {
        return $doc;
    }
    
    // Price fields
    $doc->addField('_price', $product->get_price());
    $doc->addField('_regular_price', $product->get_regular_price());
    $doc->addField('_sale_price', $product->get_sale_price());
    
    // SKU
    if ($product->get_sku()) {
        $doc->addField('_sku', $product->get_sku());
    }
    
    // Stock status
    $doc->addField('_stock_status', $product->get_stock_status());
    
    // Product categories
    $categories = wp_get_post_terms($post_info->ID, 'product_cat', array('fields' => 'names'));
    foreach ($categories as $category) {
        $doc->addField('product_cat', $category);
    }
    
    // Product tags
    $tags = wp_get_post_terms($post_info->ID, 'product_tag', array('fields' => 'names'));
    foreach ($tags as $tag) {
        $doc->addField('product_tag', $tag);
    }
    
    // Product attributes (color, size, etc.)
    $attributes = $product->get_attributes();
    foreach ($attributes as $attribute) {
        if ($attribute->is_taxonomy()) {
            $taxonomy = $attribute->get_taxonomy();
            $terms = wp_get_post_terms($post_info->ID, $taxonomy, array('fields' => 'names'));
            foreach ($terms as $term) {
                $doc->addField($taxonomy, $term);
            }
        }
    }
    
    return $doc;
}

Step 3: Upload Schema and Reindex

  1. Upload schema.xml to /wp-content/uploads/solr-for-wordpress-on-pantheon/
  2. Go to Solr Power > Actions
  3. Click “Repost schema.xml”
  4. Click “Index Searchable Post Types”

Wait for indexing to complete. Large catalogs (10,000+ products) may take 15-30 minutes.

Creating WooCommerce Facets

Enable faceted filtering for WooCommerce attributes.

Configure facets in Solr Power:

Settings > Solr Power > Facets:

  1. Enable AJAX Facet Search Support
  2. Set AJAX Div ID to main or primary (your shop’s content container)
  3. Select facets:
    • Product Categories (product_cat)
    • Product Tags (product_tag)
    • Price Range (custom implementation)
    • Attributes (color, size, brand)
    • Stock Status (_stock_status)

Create custom price range facets:

Solr doesn’t support dynamic price ranges out of the box. Create fixed price ranges:

php

add_filter('solr_power_query', 'add_price_range_facets', 10, 2);

function add_price_range_facets($query_params, $query) {
    // Only on product searches
    if (!is_post_type_archive('product') && !is_tax('product_cat')) {
        return $query_params;
    }
    
    // Add price range facet queries
    $query_params['facet.query'] = array(
        '_price:[0 TO 50]',
        '_price:[50 TO 100]',
        '_price:[100 TO 250]',
        '_price:[250 TO 500]',
        '_price:[500 TO *]'
    );
    
    return $query_params;
}

Display facets on shop pages:

Create a custom template for WooCommerce search/shop pages with facets:

php

<?php
/**
 * Template: woocommerce/archive-product.php with Solr facets
 */

get_header('shop');

// Display Solr facets
if (function_exists('solr_facets')) {
    echo '<aside class="shop-facets">';
    echo '<h3>Filter Products</h3>';
    
    // Stock status facet
    echo '<div class="facet-group">';
    echo '<h4>Availability</h4>';
    echo '<ul>';
    echo '<li><a href="' . add_query_arg('fq', '_stock_status:instock') . '">In Stock</a></li>';
    echo '<li><a href="' . add_query_arg('fq', '_stock_status:outofstock') . '">Out of Stock</a></li>';
    echo '</ul>';
    echo '</div>';
    
    // Price range facet
    echo '<div class="facet-group">';
    echo '<h4>Price</h4>';
    echo '<ul>';
    echo '<li><a href="' . add_query_arg('fq', '_price:[0 TO 50]') . '">Under $50</a></li>';
    echo '<li><a href="' . add_query_arg('fq', '_price:[50 TO 100]') . '">$50 - $100</a></li>';
    echo '<li><a href="' . add_query_arg('fq', '_price:[100 TO 250]') . '">$100 - $250</a></li>';
    echo '<li><a href="' . add_query_arg('fq', '_price:[250 TO 500]') . '">$250 - $500</a></li>';
    echo '<li><a href="' . add_query_arg('fq', '_price:[500 TO *]') . '">Over $500</a></li>';
    echo '</ul>';
    echo '</div>';
    
    // Standard Solr facets (categories, attributes)
    solr_facets();
    
    echo '</aside>';
}

// WooCommerce product loop
if (woocommerce_product_loop()) {
    woocommerce_product_loop_start();
    
    if (wc_get_loop_prop('total')) {
        while (have_posts()) {
            the_post();
            wc_get_template_part('content', 'product');
        }
    }
    
    woocommerce_product_loop_end();
}

get_footer('shop');
?>

Search by SKU and Product Attributes

Enable SKU search so customers can search by product codes:

php

add_filter('solr_power_query', 'enable_sku_search', 10, 2);

function enable_sku_search($query_params, $query) {
    // Only on product searches with a query
    if (empty($query) || (!is_post_type_archive('product') && !is_search())) {
        return $query_params;
    }
    
    // Search in SKU field in addition to title and content
    $query_params['qf'] = 'post_title^3 _sku^2 post_content^1';
    
    return $query_params;
}

Now searching for “ABC123” will find products with that SKU.

Boost In-Stock Products

Prioritize in-stock products in search results:

php

add_filter('solr_power_query', 'boost_in_stock_products', 10, 2);

function boost_in_stock_products($query_params, $query) {
    if (!is_post_type_archive('product') && !is_search()) {
        return $query_params;
    }
    
    // Boost in-stock products 2x higher
    $query_params['bq'] = '_stock_status:instock^2.0';
    
    return $query_params;
}

Filter Out-of-Stock Products

Optionally exclude out-of-stock products from search results:

php

add_filter('solr_power_query', 'hide_out_of_stock_products', 10, 2);

function hide_out_of_stock_products($query_params, $query) {
    if (!is_post_type_archive('product') && !is_search()) {
        return $query_params;
    }
    
    // Only show in-stock products
    $query_params['fq'][] = '_stock_status:instock';
    
    return $query_params;
}

Product Variations

WooCommerce variable products (t-shirts with multiple sizes/colors) need special handling.

Option 1: Index parent product only (simpler)

Default behavior – search finds the parent product, variations display on product page.

Option 2: Index each variation separately (better for specific searches)

php

add_filter('solr_power_index_post', 'index_product_variations', 10, 2);

function index_product_variations($should_index, $post_id) {
    // Index product variations (by default they're excluded)
    $post_type = get_post_type($post_id);
    if ($post_type === 'product_variation') {
        return true;
    }
    return $should_index;
}

Then customers searching “blue t-shirt size large” will find that specific variation.

WooCommerce Search Widget

Replace WooCommerce’s default product search with Solr-powered search:

php

add_filter('get_product_search_form', 'solr_product_search_form');

function solr_product_search_form($form) {
    $form = '<form role="search" method="get" class="woocommerce-product-search" action="' . esc_url(home_url('/')) . '">
        <label class="screen-reader-text" for="woocommerce-product-search-field">Search for:</label>
        <input type="search" id="woocommerce-product-search-field" class="search-field" placeholder="Search products..." value="' . get_search_query() . '" name="s" />
        <input type="hidden" name="post_type" value="product" />
        <button type="submit" value="Search">Search</button>
    </form>';
    
    return $form;
}

Solr Power automatically intercepts this search and uses Solr instead of MySQL.

Related Products with Solr

Use Solr’s “More Like This” feature for related products:

php

function get_solr_related_products($product_id, $limit = 4) {
    // Connect to Solr
    $solr_options = solr_options();
    $solr = new SolrPower_Api();
    
    // Query for similar products
    $query = new SolrQuery();
    $query->setQuery('id:' . $product_id);
    $query->setRows(0);
    
    // More Like This parameters
    $query->addParam('mlt', 'true');
    $query->addParam('mlt.fl', 'post_title,post_content,product_cat,product_tag');
    $query->addParam('mlt.mindf', '1');
    $query->addParam('mlt.mintf', '1');
    $query->addParam('mlt.count', $limit);
    
    $results = $solr->query($query);
    
    if (!empty($results['response']['docs'])) {
        return $results['response']['docs'];
    }
    
    return array();
}

// Use in single product template
$related = get_solr_related_products(get_the_ID(), 4);
if (!empty($related)) {
    echo '<div class="related-products">';
    echo '<h2>You May Also Like</h2>';
    foreach ($related as $product) {
        // Display product...
    }
    echo '</div>';
}

Performance Tips for WooCommerce

Batch index products:

For stores with 10,000+ products, index in batches to avoid timeouts:

bash

# Index 500 products at a time
terminus wp <site>.<env> -- solr index --batch-size=500 --post-type=product

Optimize frequently:

WooCommerce product updates (inventory changes, price updates) trigger frequent re-indexing. Optimize monthly:

bash

terminus wp <site>.<env> -- solr optimize

Cache facet queries:

Enable caching for facet counts (they don’t change often):

php

add_filter('solr_power_query', 'cache_facet_queries', 10, 2);

function cache_facet_queries($query_params, $query) {
    // Cache facet results for 1 hour
    $query_params['facet.cache'] = 'true';
    return $query_params;
}

Tracking WooCommerce Search with GTM

Track product searches separately from content searches:

php

<?php
// On WooCommerce product search results
if (is_search() && get_query_var('post_type') === 'product') {
    $search_query = get_search_query();
    $results_count = $wp_query->found_posts;
    ?>
    <script>
    window.dataLayer = window.dataLayer || [];
    dataLayer.push({
        'event': 'productSearch',
        'searchTerm': '<?php echo esc_js($search_query); ?>',
        'searchResults': <?php echo intval($results_count); ?>,
        'searchType': 'solr_woocommerce'
    });
    </script>
    <?php
}
?>

Track product clicks from search results:

php

<a href="<?php echo esc_url(get_permalink()); ?>" 
   onclick="dataLayer.push({
       'event': 'productSearchClick',
       'productName': '<?php echo esc_js(get_the_title()); ?>',
       'productId': '<?php echo esc_js(get_the_ID()); ?>',
       'searchTerm': '<?php echo esc_js(get_search_query()); ?>',
       'resultPosition': <?php echo $wp_query->current_post + 1; ?>
   });">
    <?php the_title(); ?>
</a>

Troubleshooting WooCommerce-Specific Issues

Products not appearing in search:

  1. Verify product post type is indexed: Settings > Solr Power > Indexing
  2. Check product visibility: Products set to “hidden” won’t index
  3. Verify custom fields are in schema and indexed
  4. Check if product is excluded from search in WooCommerce settings

Facets not showing accurate counts:

  1. Reindex all products after schema changes
  2. Check that facet fields are multiValued="true" for attributes
  3. Clear Solr cache: terminus wp <site>.<env> -- solr commit

Slow product searches:

  1. Reduce facets (each adds query overhead)
  2. Optimize index: terminus wp <site>.<env> -- solr optimize
  3. Check for expensive boost queries
  4. Consider caching facet results

SKU searches not working:

  1. Verify _sku field is in schema
  2. Check that solr_build_document filter is adding SKU data
  3. Verify SKU field is included in qf parameter (query fields)

Real-World WooCommerce Results

Outdoor gear retailer (3,000 products):

  • Implemented Solr with facets for category, price, size, color
  • Search usage increased 40%
  • Search-to-conversion rate improved 28%
  • Page load time reduced from 2.3s to 0.8s

Fashion boutique (8,000 products):

  • Added Solr with SKU search and attribute filtering
  • Customer service inquiries about finding products dropped 35%
  • Average order value increased 15% (better product discovery)
  • Mobile search performance improved dramatically

Industrial supplies B2B (15,000 products):

  • Solr search by manufacturer part numbers
  • Faceted filtering by specifications (voltage, material, dimensions)
  • Sales team efficiency improved – faster product lookups
  • Customer self-service increased 50%

Measuring Search Performance with GTM and GA4

Track search behavior to understand how users interact with Solr-powered search.

What to Track

Search queries:
What terms are users searching for?

Result counts:
Do searches return results, or are users hitting dead ends?

Click-through rate:
Do users click results, or refine their search?

Null results:
Which searches return zero results? These indicate content gaps.

Facet usage:
Which filters do users apply?

Search-to-conversion:
Do users who search convert better than those who don’t?

GTM Implementation

Step 1: Create Data Layer Variables

In GTM, create these Data Layer Variables:

  • searchTerm – Variable Name: dlv – Search Term
  • searchResults – Variable Name: dlv – Search Results Count
  • facetsApplied – Variable Name: dlv – Facets Applied

Step 2: Add Tracking Code to Search Template

Add to your search.php template:

php

<?php
// Push search data to dataLayer
if (is_search() && have_posts()) {
    $search_query = get_search_query();
    $results_count = $wp_query->found_posts;
    $facets_applied = isset($_GET['fq']) ? $_GET['fq'] : 'none';
    ?>
    
    <script>
    window.dataLayer = window.dataLayer || [];
    dataLayer.push({
        'event': 'search',
        'searchTerm': '<?php echo esc_js($search_query); ?>',
        'searchResults': <?php echo (int)$results_count; ?>,
        'facetsApplied': '<?php echo esc_js($facets_applied); ?>'
    });
    </script>
    
    <?php
}

// Track null results
if (is_search() && !have_posts()) {
    $search_query = get_search_query();
    ?>
    
    <script>
    window.dataLayer = window.dataLayer || [];
    dataLayer.push({
        'event': 'searchNullResult',
        'searchTerm': '<?php echo esc_js($search_query); ?>'
    });
    </script>
    
    <?php
}
?>

Step 3: Create GTM Triggers

Create two Custom Event triggers:

  1. Trigger Name: “Search” – Event Name: search
  2. Trigger Name: “Search Null Result” – Event Name: searchNullResult

Step 4: Create GA4 Events

Create two GA4 Event tags:

Search Event:

  • Tag Type: GA4 Event
  • Event Name: search
  • Event Parameters:
    • search_term{{dlv - Search Term}}
    • results_count{{dlv - Search Results Count}}
    • facets_applied{{dlv - Facets Applied}}
  • Trigger: Search

Null Result Event:

  • Tag Type: GA4 Event
  • Event Name: search_null_result
  • Event Parameters:
    • search_term{{dlv - Search Term}}
  • Trigger: Search Null Result

Step 5: Track Result Clicks

Add click tracking to search results:

php

<a href="<?php the_permalink(); ?>" 
   onclick="dataLayer.push({
       'event': 'searchResultClick',
       'searchTerm': '<?php echo esc_js(get_search_query()); ?>',
       'resultPosition': <?php echo $wp_query->current_post + 1; ?>,
       'resultTitle': '<?php echo esc_js(get_the_title()); ?>'
   });">
    <?php the_title(); ?>
</a>

GA4 Analysis

In GA4, create custom reports to analyze search:

Top Search Terms:
Reports > Engagement > Events > search
View by search_term parameter

Null Searches:
Reports > Engagement > Events > search_null_result
Identify terms that need content

Search Depth:
Create a funnel:

  1. Search performed
  2. Result clicked
  3. Goal conversion

Facet Usage:
Reports > Engagement > Events > search
View by facets_applied parameter to see which filters users prefer

Troubleshooting Common Issues

Solr Not Responding

Symptom: Ping status shows “Solr is not responding”

Solutions:

  1. Verify Solr add-on is enabled in Pantheon Dashboard
  2. Wait 2-3 minutes after enabling for containers to provision
  3. Check that Solr Power plugin is activated
  4. Clear Pantheon’s Redis cache: terminus redis:clear <site>.<env>

New Posts Not Appearing in Search

Symptom: Recently published content doesn’t show in results

Cause: Solr hasn’t committed the changes yet (commits every 2 minutes or hourly via cron)

Solutions:

  1. Wait 2-5 minutes for auto-commit
  2. Force a commit via Terminus: terminus wp <site>.<env> -- solr commit
  3. Enable auto-commit (not recommended for production):

php

// Add to wp-config.php
define('SOLR_AUTOCOMMIT', true);

Search Returns No Results

Symptom: All searches return “No results found”

Solutions:

  1. Check index status: Settings > Solr Power > Info
  2. Verify documents are indexed: Number of Documents > 0
  3. Reindex: Settings > Solr Power > Actions > Index Searchable Post Types
  4. Check that post types are set to “public” and “exclude_from_search” is false

Facets Not Displaying

Symptom: Facet widget appears but shows no filters

Solutions:

  1. Verify AJAX Div ID matches your theme’s content container
  2. Check that facets are enabled: Settings > Solr Power > Facets
  3. Ensure faceted taxonomies have terms assigned to posts
  4. Rebuild index after changing facet settings

Schema.xml Errors

Symptom: “Missing post_date_iso field” error

Cause: Custom schema.xml missing required fields

Solution:
Don’t modify core schema fields. Only add new custom fields. If you must modify schema:

  1. Download default schema from Solr Power plugin
  2. Make changes carefully
  3. Repost schema: Settings > Solr Power > Actions > Repost schema.xml
  4. Reindex all content

Slow Search Performance

Symptom: Search takes several seconds to return results

Solutions:

  1. Optimize index: terminus wp <site>.<env> -- solr optimize
  2. Reduce facets (each facet adds query overhead)
  3. Limit results per page (fewer than 50)
  4. Check if auto-commit is enabled (disable it)
  5. Review custom boost queries for complexity

Solr vs. Alternatives

Solr vs. Default WordPress Search

FeatureWordPress DefaultSolr
Setup ComplexityNoneMedium
Relevance RankingNoYes
Faceted SearchNoYes
Performance (1,000 posts)FineFaster
Performance (10,000+ posts)SlowFast
Custom Field SearchLimitedExcellent
Cost (Pantheon)FreeIncluded (Pro+)

Solr vs. Relevanssi

Relevanssi is a popular WordPress plugin that improves search without external services.

Relevanssi pros:

  • Works on any host
  • No external dependencies
  • Good relevance ranking

Solr pros:

  • Faster at scale (10,000+ posts)
  • Better faceting
  • Offloads search from database
  • More customizable

Use Relevanssi if you can’t use Solr. Use Solr if you need facets or have 5,000+ posts.

Solr vs. SearchWP

SearchWP is a premium WordPress search plugin ($99-$299/year) that improves search without external infrastructure.

SearchWP pros:

  • Simple setup (install plugin, configure, done)
  • Works on any hosting (no Solr server required)
  • Excellent PDF/document search
  • Search custom fields and taxonomies easily
  • Good WooCommerce integration
  • Lower barrier to entry

Solr pros:

  • Dramatically faster with large datasets (50,000+ posts/products)
  • True faceted search built-in
  • Offloads search from database (better overall site performance)
  • Scales to millions of documents
  • More customizable for complex requirements

Solr vs. Algolia

Algolia is a hosted SaaS search service.

Algolia pros:

  • Incredibly fast (sub-50ms searches)
  • Beautiful pre-built UI components
  • Typo tolerance
  • Instant results as you type

Solr pros:

  • Free/included on Pantheon
  • Data stays on your server
  • More customizable
  • No per-search costs

Use Algolia for user-facing apps where search speed is critical. Use Solr for cost-effective search on content-heavy sites.

Maintenance and Management

Regular Index Optimization

Run quarterly (or when experiencing slow searches):

bash

terminus wp <site>.<env> -- solr optimize

Optimization merges index segments for better performance.

Monitor Index Health

Check monthly via Settings > Solr Power > Info:

  • Document count matches expected post count
  • Ping status is “responding”
  • No error messages

Handle Deleted Content

When you delete posts, Solr automatically removes them from the index on next commit. No manual action needed.

Updates and Schema Changes

After major content changes (new custom post types, ACF field additions):

  1. Update schema.xml if needed
  2. Repost schema via Solr Power > Actions
  3. Reindex: terminus wp <site>.<env> -- solr index

Performance Monitoring

Watch these metrics:

  • Search response time (should be under 500ms)
  • Failed searches (null results > 20% suggests content gaps)
  • Index size (shouldn’t exceed available Solr memory)

Conclusion

Apache Solr transforms WordPress search from a basic database query into an enterprise-grade search experience. For sites with large content libraries, complex filtering needs, or performance requirements beyond what MySQL can deliver, Solr provides the speed and features users expect.

On Pantheon, Solr is straightforward to implement as a managed add-on. The Solr Power plugin handles the technical integration, letting you focus on configuration and customization rather than server management.

Start simple: enable Solr, index your content, and let relevance ranking improve results. Then layer on facets, custom field search, and advanced relevance tuning as your needs grow. Track search behavior with GTM and GA4 to understand what users search for and how to improve their experience.

The initial setup takes a few hours, but the ongoing benefits – faster searches, better results, and happier users – compound over time. If your WordPress site has outgrown default search, Solr is worth the investment.


Knihter specializes in WordPress development on Pantheon, including search implementation, performance optimization, and analytics integration. Contact us for help. We help agencies and enterprises build WordPress sites that scale.

FAQ

Is Solr worth the complexity for my WordPress site?

If your site has under 1,000 posts and simple search needs, probably not. Solr makes sense for sites with 5,000+ posts, multiple content types, or when you need faceted search and relevance ranking. Evaluate based on your content volume and user requirements.

Does Solr work with WooCommerce?

Yes. Solr indexes WooCommerce products just like posts. You can create facets for product categories, attributes, price ranges, and stock status. This enables Amazon-style filtering that significantly improves the shopping experience. See the comprehensive “Solr for WooCommerce: Complete Implementation” section for detailed setup instructions, code examples, and real-world results.

How much does Solr cost on Pantheon?

Solr is included free with Pantheon’s Performance (Small, Medium, Large, XL) and Elite plans. It’s not available on the Basic plan. There’s no per-search cost or usage limits.

Will Solr slow down a WordPress site?

No. Solr offloads search from a WordPress database, actually reducing database load. Search queries hit Solr’s separate index instead of running MySQL queries. This typically makes searches faster and reduces overall site load.

What happens if Solr goes down?

WordPress automatically falls back to default database search. Users will still get search results, just without Solr’s relevance ranking and facets. On Pantheon, Solr downtime is rare due to their managed infrastructure.

Can I use Solr for multilingual sites?

Not really… Solr 3.6 on Pantheon supports single-language search. For multilingual sites, you’d need separate Solr cores per language or consider alternatives like Algolia or WPML’s search integration.

How often does Solr index new content?

By default, Solr commits new content every 2 minutes or when WordPress cron runs (hourly on Pantheon). You can enable auto-commit for immediate indexing, but this impacts performance. For most sites, the 2-minute delay is acceptable.

Can I search custom post types and ACF fields?

Yes. Configure which post types to index in Solr Power settings. For ACF fields, you’ll need to create a custom schema.xml and use the solr_build_document filter to add field data to the index.

Does Solr help with SEO?

Indirectly. Better on-site search improves user engagement (lower bounce rates, longer sessions), which are positive signals for SEO. Tracking null searches also reveals content gaps you should fill.

What’s the difference between Solr 3.6 and Solr 8?

Pantheon provides Solr 3.6 for WordPress (and Solr 8 for Drupal 9+). Solr 8 is newer with more features, but Solr 3.6 handles WordPress search needs well. The Solr Power plugin is designed specifically for Solr 3.6.

Can I migrate from default search to Solr without downtime?

Yes. Enable Solr, index your content, then activate the plugin. Solr Power automatically takes over search queries. If you need to roll back, just deactivate the plugin – WordPress reverts to default search immediately.