Skip to main content

How to configure long tail search

The Long-tail search expressions ensures correct search results for words containing dashes or other non-alphabetic symbols. It also allows you to automatically correct common errors customers make in complex product names.

By default, Magento only indexes exact product labels, making products with variations or errors harder to find.

Long-tail search expressions recognizes patterns and corrects common errors in real time during reindex and search.

example
  • Canon PowerShot SX500 ISCanon PowerShot SX-500IS
  • SX500 ISSX500IS (removes spaces)
  • SX-500ISSX500IS (removes -)

This allows searches to find products using different name variations.

To set new long-tail condition navigate to System -> Search Management -> Configuration -> Mirasvit Extensions -> Search ultimate -> Query handling and processing -> Wildcard and query adjustments and find Long-tail search expressions option.

  1. Set Match expression

    tip

    Parsing is used both during the indexing process for search indexing and when processing search phrases.

    For example use match expression like:

    /([a-zA-Z0-9]*[\-\/][a-zA-Z0-9]*[\-\/]*[a-zA-Z0-9]*)/

  2. Set Replace expression

    Example

    Use /[\-\/]/ to replace - in the search request.

  3. Set Replace char

    Example

    Use an empty value to simply remove the - from the query.

For more information on configuring Long-tail search expressions, check our article How to Enhance the Search by SKU in Magento 2 with Long Tail Search


Examples

Here are some of the most useful long-tail search cases, implemented as corresponding rules.

Automatically remove '-' symbol from product names

Create a rule with the following parameters:

  • Match expression: /[a-zA-Z0-9]-[a-zA-Z0-9]/
  • Matched text: SX500-123, GLX-11A, GLZX-VXV, GLZ/123, GLZV 123, CNC-PWR1
  • Replace expression: /-/
  • Replace char: empty
  • Result text: SX500123, GLX11A, GLZXVXV, GLZ/123, GLZV-123-123, CNCPWR1
Automatically remove '-' and '/' symbols from product names

Create a rule with the following parameters:

  • Match expression: /[a-zA-Z0-9]*[ \-\/][a-zA-Z0-9]*/
  • Matched text: SX500-123, GLX-11A, GLZX-VXV, GLZ/123, GLZV 123, CNC-PWR1
  • Replace expression: /[ \-\/]/
  • Replace char: empty
  • *Result text: SX500123, GLX11A, GLZXVXV, GLZ123, GLZV123, CNCPWR1
Automatically make solid all products names with separators

Create a rule with the following parameters:

  • Match expression: /[a-zA-Z0-9]*[-\/][a-zA-Z0-9]*([-\/][a-zA-Z0-9]*)?/
  • Matched text: SX500-123, GLX-11A, GLZX-VXV, GLZ/123, GLZV-123-123, CNC-PWR1
  • Replace expression: /[-\/]/
  • Replace char: empty
  • Result text: SX500123, GLX11A, GLZXVXV, GLZ123, GLZV123123, CNCPWR1
Automatically fix misspelled product's name

Create a rule with the following parameters:

  • Match expression: /([a-zA-Z0-9]*[\- ][a-zA-Z0-9]*[\-][a-zA-Z0-9]*)/
  • Matched text: VHC68B-80, VHC-68B-80, VHC68B80
  • Replace expression: /[- ]/
  • Replace char: empty
  • Result text: VHC68B80

Moving Long-tail expressions from M1 to M2

Long-tail expressions used in Search Ultimate for M1 and M2 differ slightly.

warning

In M1 extension, you can enter one or more expressions, separated by the | character. In M2 extension, this is not possible.

Consider the following expression for Search Sphinx in M1:

Example
  • Match expression: /[a-zA-Z0-9][ -/][a-zA-Z0-9]([ -/][a-zA-Z0-9]*)?/|/[a-zA-Z]{1,3}[0-9]{1,3}/
  • Replace expression: /[ -/]/|/([a-zA-Z]{1,3})([0-9]{1,3})/
  • Replace char: $1 $2

It actually contains two separate regex patterns to match, with respective separate expressions for replacement:

  • /[a-zA-Z0-9][ -/][a-zA-Z0-9]([ -/][a-zA-Z0-9]*)?/
  • /[a-zA-Z]{1,3}[0-9]{1,3}/

You either need to reformat the expression to match as a single expression or rewrite the rule as a set of two:

This rule will implement the first part of the original M1 expression.

  • Match expression: /[a-zA-Z0-9][ -/][a-zA-Z0-9]([ -/][a-zA-Z0-9]*)?/
  • Replace expression: /[ -/]/
  • Replace char: $1 $2