In short
- The problem: on a growing WooCommerce store, the search box gets slow, misses products shoppers type exactly (SKUs, sizes, brands), and puts the wrong items first. Shoppers who search are often the ones ready to buy, so every empty or irrelevant results page is a lost sale.
- What I do about it: I measure what people actually search for, fix the cheap gaps first (SKU and attribute matching, a narrower query), and only move to a dedicated search index or engine when the catalog and traffic prove the database can't keep up.
- Who this is for: WooCommerce store owners and agencies with catalogs in the thousands of products, and the engineers asked to "make search better" without a budget for a rewrite.
A shopper types a part number from the box in their hand. The store sells that exact part. The results page says "No products were found matching your selection." They leave and buy it somewhere else.
Or the search works, but slowly. Each query takes a second or two, and during a sale, a few dozen people searching at once push the database hard enough that checkout slows down too.
Both problems come from the same place: WooCommerce's storefront search is WordPress's general post search, pointed at products. It was built for blogs. On a store with a real catalog it is slow, blind to the fields shoppers search by, and weak at ranking.
The default search is a full scan with LIKE
When a shopper searches, WooCommerce runs a normal WP_Query with post_type=product and the s parameter. WordPress splits the phrase into terms and, for each term, adds a condition like this across the product title, excerpt and content:
(wp_posts.post_title LIKE '%blue%'
OR wp_posts.post_excerpt LIKE '%blue%'
OR wp_posts.post_content LIKE '%blue%')
Every term must match somewhere, so "blue hoodie large" becomes three of those blocks joined with AND.
The leading % is the expensive part. MySQL can't use a normal index for a pattern that starts with a wildcard, so it reads every candidate product row and compares strings, including long product descriptions full of page-builder markup. On a few hundred products nobody notices. On tens of thousands, with descriptions measured in kilobytes, each search is real work, and it is the kind of work a page cache never sees because every query string is different.
It also misses what shoppers actually type
Speed is the problem engineers notice. The problem that costs money is relevance.
- SKUs aren't searched on the storefront. The admin product list matches SKUs, but the front-end search box does not by default. That is why so many "search by SKU" plugins exist.
- Variation data is invisible. Each variation is its own
product_variationpost with its own SKU and attribute values. A search for a variation SKU or for "XL" won't find the parent product through its title or content. - Taxonomies aren't searched. Categories, tags, brands and attributes (the
pa_*taxonomies) live in term tables, not in the product's text. A shopper searching "Nike running" only finds products that repeat those words in the description. - No typo tolerance, no synonyms, no stemming. "hoody" doesn't find "hoodie". "tee" doesn't find "t-shirt". Plurals only work when the singular happens to be a substring.
- Ranking is crude. WordPress orders search results by a simple relevance rule: full-phrase title matches first, then title matches on all terms, then excerpt and content. There is no weighting by sales, stock or margin, and out-of-stock items can sit at the top.
Before I change any code, I look at what people search for. The cheapest source is the store's own logs or analytics site-search report. I want the top queries, the queries that return zero results, and the share of searches that end in a product view. That list decides the fix far better than catalog size does.
Fix the cheap gaps inside WordPress first
For many stores in the low thousands of products, the right answer is a few targeted changes, not a new system.
Narrow the columns. Since WordPress 6.2, WP_Query accepts a search_columns argument and there is a post_search_columns filter. Dropping post_content from product searches removes the biggest text from the scan and often improves relevance, because long descriptions produce accidental matches.
add_filter( 'post_search_columns', function ( array $columns, string $search, WP_Query $query ) {
if ( ! is_admin() && $query->is_main_query() && $query->is_search()
&& 'product' === $query->get( 'post_type' ) ) {
return [ 'post_title', 'post_excerpt' ];
}
return $columns;
}, 10, 3 );
Whether to drop content is a judgment call per store. If the catalog relies on descriptions for key terms, keep it and fix the speed another way.
Short-circuit exact SKU matches. A shopper who types a SKU wants one product. WooCommerce stores SKUs in the indexed wc_product_meta_lookup table, and wc_get_product_id_by_sku() reads from it. If the whole search phrase is a SKU, I send the shopper straight to the product, falling back to the parent for a variation:
add_action( 'template_redirect', function () {
if ( ! is_search() || 'product' !== get_query_var( 'post_type' ) ) {
return;
}
$term = trim( get_search_query( false ) );
if ( '' === $term || str_contains( $term, ' ' ) ) {
return;
}
$id = wc_get_product_id_by_sku( $term );
if ( ! $id ) {
return;
}
$product = wc_get_product( $id );
if ( $product && $product->is_type( 'variation' ) ) {
$product = wc_get_product( $product->get_parent_id() );
}
if ( $product && $product->is_visible() ) {
wp_safe_redirect( $product->get_permalink() );
exit;
}
} );
That one change often fixes the most painful zero-result searches, the people who knew exactly what they wanted.
Hide what can't be bought. If out-of-stock products shouldn't appear in search, say so in the query rather than filtering after the fact. WooCommerce's "Hide out of stock items from the catalog" setting covers the simple case.
None of this makes the LIKE scan cheaper per row. It makes it scan less and return better answers, which is enough for a surprising number of stores.
A dedicated search index table beats patching the main query
When the catalog grows or the team wants attributes, categories and variation SKUs searchable, I stop bending wp_posts and build a small search index table instead. One row per searchable product, with the text a shopper might type already flattened in:
CREATE TABLE wp_product_search (
product_id BIGINT UNSIGNED NOT NULL PRIMARY KEY,
title VARCHAR(255) NOT NULL,
skus TEXT NOT NULL, -- parent + variation SKUs
terms TEXT NOT NULL, -- categories, tags, brand, attribute values
in_stock TINYINT(1) NOT NULL DEFAULT 1,
total_sales BIGINT NOT NULL DEFAULT 0,
FULLTEXT KEY ft_search (title, skus, terms)
) ENGINE=InnoDB;
A MySQL FULLTEXT index is built for word search: it tokenizes the text and looks words up instead of scanning strings. MATCH ... AGAINST in boolean mode supports prefix matching (hood*), and natural-language mode returns a relevance score I can combine with stock and sales:
SELECT product_id,
MATCH(title, skus, terms) AGAINST ('hood* large' IN BOOLEAN MODE) AS score
FROM wp_product_search
WHERE MATCH(title, skus, terms) AGAINST ('hood* large' IN BOOLEAN MODE)
ORDER BY in_stock DESC, score DESC, total_sales DESC
LIMIT 48;
Then I hand those IDs to WooCommerce with post__in and orderby => post__in, so templates, pricing and visibility rules keep working exactly as before.
Two details matter in practice. InnoDB ignores tokens shorter than innodb_ft_min_token_size (3 characters by default) and words on its stopword list, so short sizes like "XL" and many short SKUs won't match through FULLTEXT. I keep a separate exact-match path for SKUs and short codes. And the index has to be kept current: I update a product's row on woocommerce_update_product and stock changes, and queue a rebuild through Action Scheduler rather than doing heavy work inside the admin save request. I wrote about making those background jobs safe to retry in Action Scheduler patterns for WooCommerce plugins.
This is also roughly what established in-database search plugins do: build their own index tables instead of querying posts directly. Writing it yourself makes sense when you need control over weighting and fields; buying a plugin makes sense when the defaults fit.
Move to a search engine when you need what MySQL can't give
A dedicated engine such as Elasticsearch or OpenSearch (often through ElasticPress), Meilisearch, Typesense or a hosted service like Algolia earns its cost when the store needs things a database index does poorly:
- Typo tolerance and synonyms as a feature, not a project.
- Faceted filtering (size, color, price range, brand) with counts that stay fast as filters combine. Layered navigation on large catalogs is often slower than search itself.
- Search-as-you-type with results in tens of milliseconds, which means a request on every keystroke.
- Merchandising controls for the people running the store: pin a product for a query, boost a brand, bury discontinued stock.
- Multiple languages with proper stemming per language.
The engine doesn't replace WooCommerce as the source of truth. Products, prices and stock still live in the database. The engine holds a copy shaped for search, and that copy can drift. Every integration I'd trust has a clear sync path (event on save, a queue, and a scheduled full reindex) and a fallback to database search if the engine is unreachable, so a search outage degrades results instead of taking the storefront down.
Price is the trap. A sale that starts at midnight, a stock level after a busy hour, or a customer-specific price can be stale in the index. I let the engine choose and order the product IDs, then load prices and stock from WooCommerce for display. Showing a price the checkout won't honor is worse than a slow search.
Trade-offs: when not to build any of this
- Small catalogs don't need it. Under a few thousand products with modest traffic, narrowing columns and adding SKU matching is usually the whole job. A search engine adds a service to host, monitor, secure and pay for.
- A search engine is another system to own. Someone has to notice when sync falls behind, upgrade the cluster, and rebuild the index after a schema change. If nobody on the team will own that, a well-tuned database index is the better choice even if it's less impressive.
- Hosted search bills by usage. Search-as-you-type multiplies requests per shopper. Model the bill against real query volume before committing.
- Plugins that hook every query can hurt. Some search plugins rewrite every
WP_Query, not just searches, or join meta tables in ways that slow the whole store. I audit what a plugin actually runs before installing it on a busy site. The broader version of that audit is in 9 signs your WordPress site needs a plugin audit. - Relevance tuning never ends. Whatever you choose, budget a little time each month to review zero-result and low-click queries. Without that loop, any setup slowly gets worse as the catalog changes.
Search load also lands on the same database that runs checkout. If slow searches are part of a wider slowdown, the causes in why WooCommerce checkout slows down after 50K orders are worth checking alongside.
What I check on a project like this
- Top queries and zero-result queries from site-search analytics or logs, before touching code.
- The actual SQL a storefront search runs, captured with Query Monitor or the slow query log, and how long it takes on production-sized data.
- SKU behavior: does typing a parent or variation SKU land the shopper on the product?
- Which fields are searched: title, excerpt, content, attributes, categories, brands, and whether that matches how shoppers describe products.
- Out-of-stock and hidden products in results, and whether the business wants them there.
- Sync and fallback for any external index: what triggers updates, how a full reindex runs, and what shoppers see if the engine is down.
- Price and stock freshness on results pages, loaded from WooCommerce rather than trusted from the index.
- Search and filter load during peaks, so a sale's traffic spike on search doesn't slow checkout.
The default WooCommerce search is fine until a store depends on it, and then it fails in two ways at once: it gets slower as the catalog grows, and it keeps missing the exact things shoppers type. I start with the search data, fix SKU and field coverage inside WordPress, build a proper index table when the catalog outgrows the main query, and bring in a search engine only when the store needs typo tolerance, facets and merchandising enough to own another system. The right answer is the smallest one that turns zero-result searches into product views.