Last active
November 25, 2019 04:35
-
-
Save samuraitruong/8fc78fec0a9b61b66063e93043bd9ead to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(async () => { | |
const axios = require("axios") | |
const fs = require('fs'); | |
const FuzzySet = require("fuzzyset.js"); | |
const FuzzySearch = require('fuzzy-search') | |
// const res = await axios.get("https://github.com/dwyl/english-words/raw/master/words_dictionary.json"); | |
// fs.writeFileSync("data.json", JSON.stringify(res.data, null, 2)); | |
const data = JSON.parse(fs.readFileSync("data.json", "utf8")); | |
console.log("Initial fuzzy set data"); | |
// var set = new FuzzySet(Object.keys(data)); | |
console.log("loaded data"); | |
// console.log(set.get("exp")); | |
const searcher = new FuzzySearch(Object.keys(data), null, { | |
sort: false | |
}); | |
const testWord = "Simple" | |
const result = searcher.search(testWord); | |
console.log(result); | |
const t = Object.keys(data).map(x => { | |
return { | |
title: x | |
} | |
}); | |
const options = { | |
key: "title", | |
limit: 100, // don't return more results than you need! | |
allowTypo: false, // if you don't care about allowing typos | |
threshold: -100, // don't return bad results | |
} | |
const fuzzysort = require('fuzzysort') | |
const result1s = fuzzysort.go(testWord, t, options); | |
console.log(result1s) | |
const Fuse = require("fuse.js"); | |
var fuseOptions = { | |
shouldSort: true, | |
threshold: 0.1, | |
location: 0, | |
distance: 100, | |
maxPatternLength: 32, | |
minMatchCharLength: 3, | |
keys: [ | |
"title", | |
] | |
}; | |
var fuse = new Fuse(t, fuseOptions); // "list" is the item array | |
var fuseResult = fuse.search(testWord); | |
console.log(fuseResult); | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment