Algolia tie-breaking sort
What is it?
This package is a simple and fast post-processing sorting of search results coming from Algolia, with zero dependency. Original idea and implementation from mikaa123!
When should it be used?
The main use-case for this is to re-rank an Algolia result set after it has been returned by the search engine. Such need could happen if you want to merge results coming from different indices, or if you have a complex ranking strategy that needs 2 layers of sorting (Algolia has advanced result-tweaking solutions, but can only apply one global ranking strategy).
For the most performance-conscious people, a quick benchmark with Array.prototype.sort() and Node.js v14.0.0 showed that the function can sort 8000 results in less than 50 milliseconds.
How to use it?
Regular install through npm or yarn:
npm i algolia-tiebreaking-sort# oryarn add algolia-tiebreaking-sort
Then the most straightforward way to use it is the following:
const algoliasearch =const tieBreakingSort =const client =const index1 = clientconst index2 = client// Only requirement is to have `_rankingInfo` and `objectID` for each hitconst search1 = index1const search2 = index2Promiseallsearch1 search2
What are the next steps?
Potential improvements include:
- Handle sort-by criteria
- Make the ranking formula configurable, allowing custom ones
- Optimize speed
- Rewrite in Typescript
How to run tests?
Just clone this repository and run:
npm test# oryarn test
This package is not officially supported by Algolia, so it cannot be held responsible for any use in production. If you need support, use GitHub issues or the community forum, but not Algolia email support.