seaq
Version:
ES6 Text Search.
46 lines (45 loc) • 1.75 kB
TypeScript
/**
* string_score is an implementation of the string score algo developed by
* https://github.com/joshaven/string_score
*
* "hello world".score("axl") //=> 0
* "hello world".score("ow") //=> 0.35454545454545455
*
* // Single letter match
* "hello world".score("e") //=>0.1090909090909091
*
* // Single letter match plus bonuses for beginning of word and beginning of phrase
* "hello world".score("h") //=>0.5363636363636364
*
* "hello world".score("he") //=>0.5727272727272728
* "hello world".score("hel") //=>0.6090909090909091
* "hello world".score("hell") //=>0.6454545454545455
* "hello world".score("hello") //=>0.6818181818181818
* ...
* "hello world".score("hello worl") //=>0.8636363636363635
* "hello world".score("hello world") //=> 1
*
*
* // Using a "1" in place of an "l" is a mismatch unless the score is fuzzy
* "hello world".score("hello wor1") //=>0
* "hello world".score("hello wor1",0.5) //=>0.6081818181818182 (fuzzy)
*
* // Finding a match in a shorter string is more significant.
* 'Hello'.score('h') //=>0.52
* 'He'.score('h') //=>0.6249999999999999
*
* // Same case matches better than wrong case
* 'Hello'.score('h') //=>0.52
* 'Hello'.score('H') //=>0.5800000000000001
*
* // Acronyms are given a little more weight
* "Hillsdale Michigan".score("HiMi") > "Hillsdale Michigan".score("Hills")
* "Hillsdale Michigan".score("HiMi") < "Hillsdale Michigan".score("Hillsd")
*
* @export
* @param {string} target
* @param {string} query
* @param {number} [fuzziness]
* @returns {number}
*/
export declare function string_score(target: string, query: string, fuzziness?: number): number;