How bucket sort works in Meilisearch
When you search, Meilisearch doesn’t score documents with a single number. Instead, it applies ranking rules sequentially, sorting documents into buckets at each step.Example: Searching for “Badman dark knight returns”
Step 1: Apply thewords rule
The first ranking rule (words) sorts documents by how many query words they contain:
Step 2: Apply the
typo rule within buckets
If a bucket contains multiple documents, the next rule (typo) breaks ties. For example, in the 1-word bucket where “Badman” appears:
This continues recursively until all buckets contain single documents or all ranking rules are exhausted.
Why bucket sort?
Bucket sort offers several advantages for search ranking:- Flexibility: Different sorting algorithms can be applied within individual buckets
- Configurable priority: You control which criteria matter most by reordering rules
- Efficient tie-breaking: Only documents that tie on one rule need evaluation by the next
Best and worst cases
Default ranking rules
Meilisearch applies these rules in order:- words: Documents containing more query words rank higher
- typo: Documents with fewer typos rank higher
- proximity: Documents where query words appear closer together rank higher
- attributeRank: Documents matching in more important attributes rank higher
- sort: User-defined sort order (if specified)
- wordPosition: Documents with matches closer to the beginning of an attribute rank higher
- exactness: Documents with exact matches rank higher
Customizing ranking rules
You can reorder, add, or remove ranking rules:release_date:desc as a custom rule means newer movies rank higher when all other factors are equal.
Related concepts
- Ranking rules: Configure ranking behavior
- Ranking score: Understanding search relevance scores
- Custom ranking rules: Add business logic to ranking