Table of contents :

Phrase Matching for Better WooCommerce Search

100-days-of-vespa-ai-woocommerce-021

Table of contents :

Phrase matching helps WooCommerce search distinguish between products whose words are present individually and products whose names contain the customer’s intended wording. A search for wireless charging stand should usually rank “Wireless Charging Stand for iPhone” above a product that mentions “wireless accessories” and “desktop phone stand” in separate parts of its description.

For agencies, phrase matching is most useful when product catalogs contain repeated attributes, long descriptions, variations, and similar SKUs. It can improve relevance without forcing every query to behave like an exact product-name lookup.

What phrase matching does

A phrase query requires the query terms to occur next to one another and in the same order within the matched text field. This is different from a normal multi-term query, where each term may occur anywhere in the field.

  • Normal term matching: “black leather wallet” can match text containing “black travel accessory” and “leather wallet”.
  • Phrase matching: “black leather wallet” favors text containing those three consecutive terms in that order.
  • Exact matching: a product identifier such as a SKU may need a dedicated normalized field and an exact-match ranking signal rather than a phrase query.

Phrase matching still uses the field’s linguistic processing. Case normalization, tokenization, stemming, and language-specific analysis can affect what is considered a matching term. It should therefore be tested with the languages and product naming conventions used by the store.

Prepare WooCommerce product fields

Start by deciding which fields should participate in phrase matching. Product names and selected attributes are usually more valuable than the full description. A fieldset can make the searchable scope explicit:

field title type string {
    indexing: index | summary
    index: enable-bm25
}

field short_description type string {
    indexing: index | summary
    index: enable-bm25
}

field product_text type string {
    indexing: index | summary
    index: enable-bm25
}

fieldset product_text {
    fields: title, short_description, product_text
}

The exact schema depends on the document model used by the agency, but the important design choice is to keep the product title available as its own field. This allows a title phrase to receive more weight than the same phrase in a long description.

When importing WooCommerce data, build product_text from controlled content such as the product title, short description, relevant attributes, category names, and variation labels. Avoid blindly concatenating every HTML description and metadata value. That can create accidental phrases that do not represent how customers identify the product.

Send a phrase query through YQL

Vespa’s userInput query operator can parse user input, including quoted phrases. A search request can use a query parameter for the visitor’s text:

yql=select * from sources * where userInput(@user-query)&user-query="wireless charging stand"

When the query parser receives the quoted text as a phrase, Vespa can build a phrase item in the query tree. The phrase is then evaluated against the indexed fields selected by the query configuration or fieldset.

For an endpoint that receives a normal WooCommerce search parameter, construct the request server-side rather than concatenating unchecked input into YQL. URL-encode the user’s value and pass it as the value of the user-query parameter. This keeps the query structure separate from the visitor’s search text.

Combine phrases with flexible matching

A phrase-only query can be too restrictive. Customers may enter punctuation, omit a word, use a different spelling, or remember only part of a product name. A practical search experience combines phrase relevance with a less strict fallback.

One approach is to parse the input into a phrase candidate and individual terms, then use a ranking expression that rewards phrase proximity while still allowing ordinary term matches. Another approach is to issue a phrase-focused query first and broaden the query when too few results are returned.

For example, a request for usb c laptop charger could use the complete phrase as the primary candidate, then allow products containing the important terms in a different order. The fallback should not be treated as equivalent: a product matching the complete phrase should receive a clear ranking advantage.

Use ranking to favor the product title

Phrase presence is a relevance signal, not necessarily the complete ranking strategy. A phrase in a product title normally indicates stronger intent than the same phrase in a description. Separate fields make this distinction possible.

A rank profile can combine BM25 scores with field-specific phrase or proximity signals. The exact rank features depend on the deployed Vespa schema, but the design can follow this pattern:

rank-profile ecommerce inherits default {
    first-phase {
        expression: 3 * bm25(title) + bm25(product_text)
    }
}

Use query-time annotations or separate query terms when the application needs to boost a title phrase specifically. Validate the resulting ranking with real queries rather than assigning an arbitrary multiplier. A large boost can cause a short but weakly relevant title to outrank a better product with a more complete description.

For exact identifiers, add a normalized field such as sku_normalized and use an exact equality or exact-term signal. Do not rely on phrase matching for values such as ABC-123, because tokenization and punctuation handling may make phrase behavior unsuitable for identifier lookup.

Handle WooCommerce attributes and variations

Variation data often contains the terms shoppers use, such as “women’s trail running shoes” or “64GB midnight”. Include useful variation labels in a searchable field, but preserve the relationship between the parent product and its variations in the document model.

For example, a variation text value might be generated as:

Women’s Trail Running Shoes, Size 9, Color Midnight

This allows a phrase such as trail running shoes to match naturally while still exposing size and color terms. If each variation is indexed as a separate document, ensure that WooCommerce availability, price, stock, and parent-product URLs remain consistent. If variations are embedded in a parent document, test whether the field representation preserves the proximity customers expect.

Do not confuse phrase matching with autocomplete

Autocomplete is usually a prefix-oriented interaction. Phrase matching is more appropriate after the shopper submits a search or pauses long enough for a full search request. A phrase query for wireless charg should not be expected to behave like a completion query for wireless charging stand.

A WooCommerce integration can use separate request modes:

  • Autocomplete: use completion-oriented fields and return a small set of product or query suggestions.
  • Submitted search: use phrase-aware parsing, field weighting, filters, and pagination.
  • Exact lookup: prioritize normalized SKU, barcode, or product-code fields.

Keeping these modes separate prevents phrase logic from making the autocomplete interface feel slow or overly strict.

Test phrase relevance with catalog-specific cases

Create a relevance test set from WooCommerce search logs and merchandising feedback. Include queries where word order matters, queries containing attributes, and queries for products with similar names.

  1. Record the expected products for a query such as waterproof hiking boots.
  2. Compare results for phrase matching, ordinary term matching, and the combined ranking strategy.
  3. Check whether a phrase in a description incorrectly outranks a near-exact product title.
  4. Test singular and plural forms, punctuation, stopwords, accents, and translated product names.
  5. Measure zero-result and low-result queries before enabling phrase boosts globally.

For production monitoring, track search queries, result counts, click-through rate, add-to-cart rate, and conversions by query type. A phrase boost is successful when it improves product discovery without increasing zero-result searches or hiding useful alternatives.

Implementation checklist

  • Keep product titles in a dedicated indexed field.
  • Build a controlled combined field for descriptions, attributes, and variation labels.
  • Use userInput or an equivalent query-tree construction to represent quoted phrases safely.
  • Combine phrase relevance with a flexible term-based fallback.
  • Use dedicated normalized fields for SKU and barcode searches.
  • Apply stronger ranking to title matches than to long-description matches.
  • Test language analysis, punctuation, stemming, and variation indexing with real WooCommerce data.
  • Measure relevance changes using search logs and conversion-oriented metrics.
Trending posts
You might also like