Skip to content
TID Relevance Sorting

TID Relevance Sorting

Introduction

The Relevance Sorting Plugin adds a new sorting option to your Shopware product listings: sorting by Relevance. This feature works like any other built-in sorting (e.g., Topseller, Lowest Price) but uses a configurable relevance score.

How It Works

The plugin calculates a relevance score for each product using a built-in algorithm. As the administrator, you can influence how this score is calculated:

  • Adjust the weight of different score factors
  • Use boosts to artificially increase the score for each product individually
  • Define custom rulesets using product custom_fields

Once configured, customers can use “Relevance” as a sorting method in any product listing.

Configuration Options

Weight Adjustments

This is the formula used to calculate the relevance score for each product:

Score =
  (Recent Sales × 4)    +
  (Margin ÷ 10)         +
  Product Age           +
  All-Time Sales        +
  (Seasonal Sales × 4)  +
  Stock                 ±
  Custom-Field Boost    ±
  On Sale Boost         ±
  Manual Boost

Using the number inputs inside the plugin configuration under the adjustments tab, you can change the way the algorithm weighs the relevance score factors.

SettingDescription
Recent SalesWeight for products sold in the configured sales period.
Sales MarginWeight for the profit margin of sold products.
On Sale BoostBoost for products currently on sale.
Product AgeWeight for how long the product has been available.
Total SalesWeight for the total number of sales.
Season SalesWeight for products with high sales during the same season in previous years.
StockWeight for the amount of stock available.

Custom Boost Rules (YAML)

You can define complex boosting logic using the text-editor field in the plugin configuration written in YAML syntax. This allows you to create custom rulesets based on product custom_fields.

Warning

In the Custom Boost Rules field, make sure you are in the Code Editor view when editing the custom rules at all times. You can switch to the Code Editor by clicking the </> icon in the top-right corner of the text field, which should then show a small line number 1. This allows you to enter YAML without formatting issues.

After saving the configuration, the editor will exit the Code Editor view and display the YAML with unusual formatting, but it will still work correctly. To edit it, enable the Code Editor view again by clicking the </> icon.

The YAML should be structured so that each custom_field contains the values it is configured with:

ElementDescription
field_typeDefines the type of custom field. "single" means that the custom_field only contains one value at a time, while "multi" may contain multiple values.
operatorThe comparison operator used to evaluate the custom field value. Here, ">" means the custom_field value must be greater than the defined comparison_value. The operators =, !=, <, >, <=, >= can all be used.
comparison_valueThe threshold value to compare against. The product’s custom_field value must be greater than the comparison_value to qualify for the boost.
boostThe value added to the product’s relevance score when the condition is met. Here, a boost of 5 is applied.

The custom rulesets use the following YAML formats based on the field_type.

Here is how the type single may be used in YAML:

custom_field_technical_name:
    field_type: "single"
    operator: ">"
    comparison_value: "10"
    boost: "5"

This rule adds a boost of 5 to products where the custom_field value is greater than 10.

For a multi type, the YAML structure is slightly different. Instead of the normal comparison_value, you use rules to define the matching criteria:

ElementDescription
match"none" means the rule applies if none of the comparison values match the product’s custom_field value(s). The other options are "any", which applies the rule if at least one value matches, and "all", which applies the rule only if every value matches.
operator (in)Checks whether the product’s custom_field value is present in the specified list of comparison values.
operator (not_in)Checks whether the product’s field value is not present in the specified list of comparison values.
comparison_value (multi)A list (array) of acceptable values for comparison. In this example: ["option_3", "option_4"].

Warning

Ensure that even if there is only one comparison_value, it is still formatted as a list (array) in the YAML.

Here is an example of how to define a multi type custom_field in YAML:

custom_field_technical_name:
    field_type: "multi"
    boost: "3"
    rules:
        match: "any"
        operator: "in"
        comparison_value: ["test_option_3", "test_option_4"]

This rule applies a boost of 3 to products where the custom_field value(s) matches any of the specified options (test_option_3 or test_option_4).

This is how a complete YAML configuration might look, combining both single and multi types:

rating_custom_field:
    field_type: "single"
    operator: ">"
    comparison_value: "3.89"
    boost: "5"

custom_product_material_composition:
    field_type: "single"
    operator: "="
    comparison_value: "100% Cotton"
    boost: "12"

tids_product_customfields_testing:
    field_type: "multi"
    boost: "3"
    rules:
        match: "none"
        operator: "in"
        comparison_value: ["test_option_3", "test_option_4"]

Use Case

Imagine you want to:

  1. Boost products that have been sold recently.
  2. Increase the score for items currently on sale.
  3. Apply a custom rule that boosts products with a specific custom_field value.

You would:

  • Set a high weight for Recent Sales and On Sale Boost in the plugin configuration
  • Define a custom rule in YAML to boost products with that specific custom_field

When customers choose “Sort by Relevance,” the products matching your criteria will appear higher in the listing.