GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - julienpa/algolia-tiebreaking-sort: Post-processing sorting of search results coming from Algolia

BranchesTags
Open more actions menu

Latest commit

 

History

36 Commits
36 Commits

Folders and files

NameName
Last commit message
Last commit date
.editorconfig
.editorconfig
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
package-lock.json
package-lock.json
 
 
package.json
package.json
 
 
searchresults.json
searchresults.json
 
 
tiebreakingsort.js
tiebreakingsort.js
 
 
tiebreakingsort.test.js
tiebreakingsort.test.js
 
 

Repository files navigation

Algolia tie-breaking sort

npm node-lts JavaScript Style Guide tested with jest

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 v16.2.0 showed that the function can sort 5000 results in less than 50 milliseconds.

How to use it?

Regular install through npm or yarn:

npm i algolia-tiebreaking-sort
# or
yarn add algolia-tiebreaking-sort

Then the most straightforward way to use it is the following:

const algoliasearch = require('algoliasearch')
const tieBreakingSort = require('algolia-tiebreaking-sort')

const client = algoliasearch('APPID', 'APIKEY')
const index1 = client.initIndex('index_name_1')
const index2 = client.initIndex('index_name_2')

// Only requirement is to have `_rankingInfo` and `objectID` for each hit
const search1 = index1.search('my query', { getRankingInfo: true })
const search2 = index2.search('my query', { getRankingInfo: true })

Promise.all([search1, search2]).then(results => {
  const hits = [...results[0].hits, ...results[1].hits]
  console.log(hits.sort(tieBreakingSort))
})

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
# or
yarn test

Disclaimer

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.

About

Post-processing sorting of search results coming from Algolia

www.npmjs.com/package/algolia-tiebreaking-sort

Topics

algoliamulti-indexrankranking

Resources

Readme
MIT license
Activity

Stars

1 star

Watchers

1 watching

Forks

0 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.