|
1 | 1 | --- |
2 | 2 | title: Custom ranking rules |
3 | | -sidebarTitle: Custom ranking rules |
4 | | -description: Custom ranking rules promote certain documents over other search results that are otherwise equally relevant. |
| 3 | +description: Custom ranking rules sort results based on the lexicographical order of a specified attribute. |
5 | 4 | --- |
6 | 5 |
|
7 | 6 | There are two types of ranking rules in Meilisearch: [built-in ranking rules](/learn/relevancy/ranking_rules) and custom ranking rules. This article describes the main aspects of using and configuring custom ranking rules. |
8 | 7 |
|
9 | | -Custom ranking rules promote certain documents over other search results that are otherwise equally relevant. |
| 8 | +Custom ranking rules are lexicographical sorts. They order results based on the value of a specific attribute's alphabetic and numeric value. |
10 | 9 |
|
11 | | -## Ascending and descending sorting rules |
| 10 | +Custom ranking rules do not take search query relevancy into consideration. In the majority of cases you should place a custom ranking after the built-in ranking rules. |
12 | 11 |
|
13 | | -Meilisearch supports two types of custom rules: one for ascending sort and one for descending sort. |
| 12 | +- `attribute_name:asc` sorts results by increasing attribute value. For example, `price:asc` shows a product with `price: 1.00` before a product with `price: 2.00` |
14 | 13 |
|
15 | | -To add a custom ranking rule, you have to communicate the attribute name followed by a colon (`:`) and either `asc` for ascending order or `desc` for descending order. |
| 14 | +- `attribute_name:desc` sorts results by decreasing attribute value. For example, `price:desc` shows a product with `price: 5.00` before a product with `price: 3.00` |
16 | 15 |
|
17 | | -- To apply an **ascending sort** (results sorted by increasing value of the attribute): `attribute_name:asc` |
| 16 | +**The attribute must have either a numeric or a string value** in all documents contained in that index. |
18 | 17 |
|
19 | | -- To apply a **descending sort** (results sorted by decreasing value of the attribute): `attribute_name:desc` |
| 18 | +You can add this rule to the existing list of ranking rules using the [update settings endpoint](/reference/api/settings#update-settings) or [update ranking rules endpoint](/reference/api/settings#update-ranking-rules). |
20 | 19 |
|
21 | | -**The attribute must have either a numeric or a string value** in all of the documents contained in that index. |
| 20 | +<Warning> |
| 21 | +Custom ranking rules are simple lexicographical sorts. They sort results by ascending or descending order and ignore search result relevancy. |
22 | 22 |
|
23 | | -You can add this rule to the existing list of ranking rules using the [update settings endpoint](/reference/api/settings#update-settings) or [update ranking rules endpoint](/reference/api/settings#update-ranking-rules). |
| 23 | +If you want to promote results with matches in certain attributes, add them at the beginning of the [searchable attributes list](/reference/api/settings#searchable-attributes). |
| 24 | +</Warning> |
24 | 25 |
|
25 | 26 | ## Example |
26 | 27 |
|
|
0 commit comments