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:
Each rule only breaks ties from the previous one. The order matters: rules placed higher in the list have a greater overall impact.
You can reorder these rules and add custom ranking rules (like
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.