How bucket sort works
- A search query arrives and Meilisearch identifies all matching documents
- The first ranking rule sorts these documents, creating groups of documents that are equally relevant according to that rule
- Within each group, the second ranking rule further sorts documents into smaller groups
- This process continues through each ranking rule in order
- The final ordering is the search result
The default ranking pipeline
Meilisearch applies seven built-in ranking rules in this order by default:| Step | Rule | What it does |
|---|---|---|
| 1 | words | Sorts by number of matched query terms (more matches = higher rank) |
| 2 | typo | Sorts by number of typos in matches (fewer typos = higher rank) |
| 3 | proximity | Sorts by distance between matched terms (closer = higher rank) |
| 4 | attributeRank | Sorts by which attribute contains the match (higher-priority attribute = higher rank) |
| 5 | sort | Applies user-defined sorting from the sort search parameter |
| 6 | wordPosition | Sorts by position of matched terms within attributes (earlier = higher rank) |
| 7 | exactness | Sorts by how closely matches resemble the original query terms |
rating:desc) to inject business logic into the pipeline. See built-in ranking rules for detailed descriptions and visual examples of each rule.
Visualizing the pipeline
Consider a search fordark knight across a movies index. Here is how documents flow through the pipeline:
- Words: 50 documents match both terms, 30 match only one term. The 50 full-match documents form the first bucket.
- Typo: Within the 50 full-match documents, 40 have zero typos and 10 have one typo. The 40 zero-typo documents form the top bucket.
- Proximity: Within those 40 documents, 15 have “dark” and “knight” adjacent, 25 have them further apart. The 15 adjacent-match documents rank highest.
- Attribute rank: Within those 15 documents, 5 have the match in
titleand 10 have it inoverview. The 5 title-match documents rank highest. - Sort: No
sortparameter was provided, so this rule has no effect. - Word position: Within the 5 title-match documents, those with “dark knight” appearing earlier in the title rank higher.
- Exactness: Final tiebreaker based on exact vs. fuzzy matches.
For a deeper look at the bucket sort algorithm, see bucket sort internals. For details on each ranking rule, see built-in ranking rules.