deno.land / x / fuse@v6.4.1 / src / tools / norm.js

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
const SPACE = /[^ ]+/g
// Field-length norm: the shorter the field, the higher the weight.// Set to 3 decimals to reduce index size.export default function norm(mantissa = 3) { const cache = new Map()
return { get(value) { const numTokens = value.match(SPACE).length
if (cache.has(numTokens)) { return cache.get(numTokens) }
const n = parseFloat((1 / Math.sqrt(numTokens)).toFixed(mantissa))
cache.set(numTokens, n)
return n }, clear() { cache.clear() } }}
fuse

Version Info

Tagged at
3 years ago