Skip to content

Instantly share code, notes, and snippets.

@modamodamoda
modamodamoda / index.js
Created July 28, 2021 05:05
Get olympic medals per capita
// npm install node-fetch cheerio
const fetch = require('node-fetch'), cheerio = require('cheerio');
const els = ['rank', 'country', 'gold', 'silver', 'bronze', 'total', 'rbt', 'code'];
var countries = [];
var aliases = {'Chinese Taipei': 'Taiwan', 'Hong Kong, China': 'Hong Kong'};
fetch('https://olympics.com/tokyo-2020/olympic-games/en/results/all-sports/medal-standings.htm').then(res => res.text()).then(text => {
@modamodamoda
modamodamoda / info.md
Last active May 2, 2021 04:39
A very quick full text search engine

The idea here is to have a basic full text search engine, which accepts documents and creates a searchable structure.

I'm kinda using a tf-idf based idea, and took some inspiration from MySQL's internals for their Fulltext index. I added more robustness to the ranking algorithm by giving weightings a boost when an exact match of part of the query is found. Of course, it's not an exact science, and could do with a lot of improvement, but I think it's a pretty cool start.

Additionally, I've tried to write it using backwards compatible javascript for browser acceptance.

The data structure

There are two objects: documents, and terms. Every time a document is inserted, the terms are tokenised and given weights. We also keep track of the word after each term to strengthen our ranking system. Documents are also stored, with their meta data, so that they can be retrieved with the results.