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 BoostUsing the number-inputs inside the plugin configuration under the adjustments tab, you can change the way the algorithm weighs the relevance score factors.
| Setting | Description |
|---|---|
Recent Sales | Weight for products sold in the configured sales period. |
Sales Margin | Weight for the profit margin of sold products. |
On Sale Boost | Boost for products currently on sale. |
Product Age | Weight for how long the product has been available. |
Total Sales | Weight for the total number of sales. |
Season Sales | Weight for products with high sales during the same season in previous years. |
Stock | Weight 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 weirdly formatted, but it will still work correctly. If you wish to edit it, enable the Editor view again by clicking the </> icon.
The YAML should be structured so that each custom field contains a list of values that its packed with:
A
custom fieldhas the typesingleif there is only one value that can be entered into the Field.
Acustom fieldhas the typemultiif there are multiple values that can be entered into the Field.
| Element | Description |
|---|---|
field_type | Defines the type of custom field. Available types are: "single" or "multi" |
operator | The comparison operator used to evaluate the custom field value. Here, ">" meaning the custom field value must be greater than the defined comparison value as in: custom field value > comparison value. The operators =, !=, <, >, <=, >= can all be used. |
comparison_value | The threshold value to compare against. In this example, the product’s custom field value must be greater than the comparison valu to qualify for the boost. |
boost | The value added to the product’s relevance score when the condition is met. Here, a boost of 5 is applied. |
These elements are used to build a ruleset, a collection of self-defined rules for each custom field
Here's how the type single may be used in YAML:
custom_field_technical_name:
field_type: "single"
ruleset:
example_rule:
operator: ">"
comparison_value: "10"
boost: 5
example_rule2:
operator: "="
comparison_value: "42"
boost: 2000The
example_ruleadds a boost of5to products where thecustom field valueis greater than10.
Theexample_rule2adds a boost of2000to products where thecustom field valueis exactly42.
For a multi type, the YAML structure is slightly different.
| Element | Description |
|---|---|
match (none, any, all) | "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. |
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 (inside []) in the YAML.
Here's an example of how to define a multi type custom field in YAML:
custom_field_technical_name:
field_type: "multi"
ruleset:
example_rule:
match: "any"
comparison_value: ["test_option_1", "test_option_2"]
boost: 3
example_rule2:
match: "none"
comparison_value: ["test_option_3"]
boost: 5The
example_ruleapplies a boost of3to products where thecustom field valuesmatch any of the specified options (test_option_3ortest_option_4).
Theexample_rule2applies a boost of5to products where thecomparison valuesare not in thecustom field.
This is how a complete YAML configuration might look like, combining both single and multi types:
rating_custom_field:
field_type: "single"
ruleset:
example_rule:
operator: ">"
comparison_value: "3.89"
boost: "5"
custom_product_material_composition:
field_type: "single"
ruleset:
example_rule:
operator: "="
comparison_value: "100% Cotton"
boost: "12"
tids_product_customfields_testing:
field_type: "multi"
ruleset:
example_rule:
match: "none"
comparison_value: ["test_option_3", "test_option_4"]
boost: "3"Use Case
Imagine you want to:
- Boost products that have been sold recently.
- Increase the score for items currently on sale.
- Apply a custom rule that boosts products with a specific
custom fieldvalue.
You would:
- Set a high weight for
Recent SalesandOn Sale Boostin 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.