@taekwondo-db/database 0.0.0-stage → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +282 -2
- package/db/chagi.json +720 -0
- package/db/chigi.json +1153 -0
- package/db/ditgi.json +101 -0
- package/db/japgi.json +154 -0
- package/db/jireugi.json +458 -0
- package/db/jjireugi.json +111 -0
- package/db/kkeokgi.json +58 -0
- package/db/makgi.json +1447 -0
- package/db/milgi.json +63 -0
- package/db/neomgigi.json +45 -0
- package/db/pihagi.json +68 -0
- package/db/ppaegi.json +174 -0
- package/db/schemas/grades.json +22 -0
- package/db/schemas/historic.json +21 -0
- package/db/schemas/image.json +24 -0
- package/db/schemas/include.json +31 -0
- package/db/schemas/localized-string.json +17 -0
- package/db/schemas/patches.json +12 -0
- package/db/schemas/source.json +12 -0
- package/db/schemas/sources.json +22 -0
- package/db/schemas/techniques.json +86 -0
- package/db/schemas/terms.json +52 -0
- package/db/seogi.json +602 -0
- package/db/sources.json +29 -0
- package/db/terms.json +995 -0
- package/db/ttwigi.json +59 -0
- package/dist/search.browser.js +1197 -0
- package/index.js +1 -0
- package/package.json +50 -5
- package/src/builtins-empty.d.ts +1 -0
- package/src/builtins-empty.js +10 -0
- package/src/builtins.d.ts +10 -0
- package/src/builtins.js +46 -0
- package/src/compose-builtins.d.ts +11 -0
- package/src/compose-builtins.js +39 -0
- package/src/compose.d.ts +76 -0
- package/src/compose.js +313 -0
- package/src/database.ts +457 -0
- package/src/description.d.ts +13 -0
- package/src/description.js +63 -0
- package/src/grade.d.ts +22 -0
- package/src/grade.js +44 -0
- package/src/search.d.ts +31 -0
- package/src/search.js +59 -0
- package/types/historic.d.ts +13 -0
- package/types/image.d.ts +9 -0
- package/types/localized-string.d.ts +3 -0
- package/types/source.d.ts +34 -0
- package/types/technique.d.ts +114 -0
- package/types/term.d.ts +38 -0
|
@@ -0,0 +1,1197 @@
|
|
|
1
|
+
// node_modules/.pnpm/fuse.js@7.5.0/node_modules/fuse.js/dist/fuse.basic.mjs
|
|
2
|
+
/**
|
|
3
|
+
* Fuse.js v7.5.0 - Lightweight fuzzy-search (http://fusejs.io)
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) 2026 Kiro Risk (http://kiro.me)
|
|
6
|
+
* All Rights Reserved. Apache Software License 2.0
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*/
|
|
10
|
+
function isArray(value) {
|
|
11
|
+
return !Array.isArray ? getTag(value) === "[object Array]" : Array.isArray(value);
|
|
12
|
+
}
|
|
13
|
+
function baseToString(value) {
|
|
14
|
+
if (typeof value == "string") return value;
|
|
15
|
+
if (typeof value === "bigint") return value.toString();
|
|
16
|
+
const result = value + "";
|
|
17
|
+
return result == "0" && 1 / value == -Infinity ? "-0" : result;
|
|
18
|
+
}
|
|
19
|
+
function toString(value) {
|
|
20
|
+
return value == null ? "" : baseToString(value);
|
|
21
|
+
}
|
|
22
|
+
function isString(value) {
|
|
23
|
+
return typeof value === "string";
|
|
24
|
+
}
|
|
25
|
+
function isNumber(value) {
|
|
26
|
+
return typeof value === "number";
|
|
27
|
+
}
|
|
28
|
+
function isBoolean(value) {
|
|
29
|
+
return value === true || value === false || isObjectLike(value) && getTag(value) == "[object Boolean]";
|
|
30
|
+
}
|
|
31
|
+
function isObject(value) {
|
|
32
|
+
return typeof value === "object";
|
|
33
|
+
}
|
|
34
|
+
function isObjectLike(value) {
|
|
35
|
+
return isObject(value) && value !== null;
|
|
36
|
+
}
|
|
37
|
+
function isDefined(value) {
|
|
38
|
+
return value !== void 0 && value !== null;
|
|
39
|
+
}
|
|
40
|
+
function isBlank(value) {
|
|
41
|
+
return !value.trim().length;
|
|
42
|
+
}
|
|
43
|
+
function getTag(value) {
|
|
44
|
+
return value == null ? value === void 0 ? "[object Undefined]" : "[object Null]" : Object.prototype.toString.call(value);
|
|
45
|
+
}
|
|
46
|
+
var EXTENDED_SEARCH_UNAVAILABLE = "Extended search is not available";
|
|
47
|
+
var LOGICAL_SEARCH_UNAVAILABLE = "Logical search is not available";
|
|
48
|
+
var TOKEN_SEARCH_UNAVAILABLE = "Token search is not available";
|
|
49
|
+
var INCORRECT_INDEX_TYPE = "Incorrect 'index' type";
|
|
50
|
+
var INVALID_DOC_INDEX = "Invalid doc index: must be a non-negative integer within the bounds of the docs array";
|
|
51
|
+
var LOGICAL_SEARCH_INVALID_QUERY_FOR_KEY = (key) => `Invalid value for key ${key}`;
|
|
52
|
+
var PATTERN_LENGTH_TOO_LARGE = (max) => `Pattern length exceeds max of ${max}.`;
|
|
53
|
+
var MISSING_KEY_PROPERTY = (name) => `Missing ${name} property in key`;
|
|
54
|
+
var INVALID_KEY_WEIGHT_VALUE = (key) => `Property 'weight' in key '${key}' must be a positive integer`;
|
|
55
|
+
var FUSE_MATCH_TOKEN_SEARCH_UNSUPPORTED = "Fuse.match does not support useTokenSearch: token search requires corpus-level statistics (df, fieldCount) that a one-off string comparison does not have. Use new Fuse(...).search(...) instead.";
|
|
56
|
+
var hasOwn = Object.prototype.hasOwnProperty;
|
|
57
|
+
var KeyStore = class {
|
|
58
|
+
constructor(keys) {
|
|
59
|
+
this._keys = [];
|
|
60
|
+
this._keyMap = {};
|
|
61
|
+
let totalWeight = 0;
|
|
62
|
+
keys.forEach((key) => {
|
|
63
|
+
const obj = createKey(key);
|
|
64
|
+
this._keys.push(obj);
|
|
65
|
+
this._keyMap[obj.id] = obj;
|
|
66
|
+
totalWeight += obj.weight;
|
|
67
|
+
});
|
|
68
|
+
this._keys.forEach((key) => {
|
|
69
|
+
key.weight /= totalWeight;
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
get(keyId) {
|
|
73
|
+
return this._keyMap[keyId];
|
|
74
|
+
}
|
|
75
|
+
keys() {
|
|
76
|
+
return this._keys;
|
|
77
|
+
}
|
|
78
|
+
toJSON() {
|
|
79
|
+
return JSON.stringify(this._keys);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
function createKey(key) {
|
|
83
|
+
let path = null;
|
|
84
|
+
let id = null;
|
|
85
|
+
let src = null;
|
|
86
|
+
let weight = 1;
|
|
87
|
+
let getFn = null;
|
|
88
|
+
if (isString(key) || isArray(key)) {
|
|
89
|
+
src = key;
|
|
90
|
+
path = createKeyPath(key);
|
|
91
|
+
id = createKeyId(key);
|
|
92
|
+
} else {
|
|
93
|
+
if (!hasOwn.call(key, "name")) throw new Error(MISSING_KEY_PROPERTY("name"));
|
|
94
|
+
const name = key.name;
|
|
95
|
+
src = name;
|
|
96
|
+
if (hasOwn.call(key, "weight") && key.weight !== void 0) {
|
|
97
|
+
weight = key.weight;
|
|
98
|
+
if (weight <= 0) throw new Error(INVALID_KEY_WEIGHT_VALUE(createKeyId(name)));
|
|
99
|
+
}
|
|
100
|
+
path = createKeyPath(name);
|
|
101
|
+
id = createKeyId(name);
|
|
102
|
+
getFn = key.getFn ?? null;
|
|
103
|
+
}
|
|
104
|
+
return {
|
|
105
|
+
path,
|
|
106
|
+
id,
|
|
107
|
+
weight,
|
|
108
|
+
src,
|
|
109
|
+
getFn
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
function createKeyPath(key) {
|
|
113
|
+
return isArray(key) ? key : key.split(".");
|
|
114
|
+
}
|
|
115
|
+
function createKeyId(key) {
|
|
116
|
+
return isArray(key) ? key.join(".") : key;
|
|
117
|
+
}
|
|
118
|
+
function get(obj, path) {
|
|
119
|
+
const list = [];
|
|
120
|
+
let arr = false;
|
|
121
|
+
const deepGet = (obj, path, index, arrayIndex) => {
|
|
122
|
+
if (!isDefined(obj)) return;
|
|
123
|
+
if (!path[index]) list.push(arrayIndex !== void 0 ? {
|
|
124
|
+
v: obj,
|
|
125
|
+
i: arrayIndex
|
|
126
|
+
} : obj);
|
|
127
|
+
else {
|
|
128
|
+
const value = obj[path[index]];
|
|
129
|
+
if (!isDefined(value)) return;
|
|
130
|
+
if (index === path.length - 1 && (isString(value) || isNumber(value) || isBoolean(value) || typeof value === "bigint")) list.push(arrayIndex !== void 0 ? {
|
|
131
|
+
v: toString(value),
|
|
132
|
+
i: arrayIndex
|
|
133
|
+
} : toString(value));
|
|
134
|
+
else if (isArray(value)) {
|
|
135
|
+
arr = true;
|
|
136
|
+
for (let i = 0, len = value.length; i < len; i += 1) deepGet(value[i], path, index + 1, i);
|
|
137
|
+
} else if (path.length) deepGet(value, path, index + 1, arrayIndex);
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
deepGet(obj, isString(path) ? path.split(".") : path, 0);
|
|
141
|
+
return arr ? list : list[0];
|
|
142
|
+
}
|
|
143
|
+
var MatchOptions = {
|
|
144
|
+
includeMatches: false,
|
|
145
|
+
findAllMatches: false,
|
|
146
|
+
minMatchCharLength: 1
|
|
147
|
+
};
|
|
148
|
+
var BasicOptions = {
|
|
149
|
+
isCaseSensitive: false,
|
|
150
|
+
ignoreDiacritics: false,
|
|
151
|
+
includeScore: false,
|
|
152
|
+
keys: [],
|
|
153
|
+
shouldSort: true,
|
|
154
|
+
sortFn: (a, b) => a.score === b.score ? a.idx < b.idx ? -1 : 1 : a.score < b.score ? -1 : 1
|
|
155
|
+
};
|
|
156
|
+
var FuzzyOptions = {
|
|
157
|
+
location: 0,
|
|
158
|
+
threshold: .6,
|
|
159
|
+
distance: 100
|
|
160
|
+
};
|
|
161
|
+
var AdvancedOptions = {
|
|
162
|
+
useExtendedSearch: false,
|
|
163
|
+
useTokenSearch: false,
|
|
164
|
+
tokenize: void 0,
|
|
165
|
+
tokenMatch: "any",
|
|
166
|
+
getFn: get,
|
|
167
|
+
ignoreLocation: false,
|
|
168
|
+
ignoreFieldNorm: false,
|
|
169
|
+
fieldNormWeight: 1
|
|
170
|
+
};
|
|
171
|
+
var Config = Object.freeze({
|
|
172
|
+
...BasicOptions,
|
|
173
|
+
...MatchOptions,
|
|
174
|
+
...FuzzyOptions,
|
|
175
|
+
...AdvancedOptions
|
|
176
|
+
});
|
|
177
|
+
function isWordSeparator(code) {
|
|
178
|
+
return code >= 9 && code <= 13 || code === 32 || code === 160;
|
|
179
|
+
}
|
|
180
|
+
function norm(weight = 1, mantissa = 3) {
|
|
181
|
+
const cache = /* @__PURE__ */ new Map();
|
|
182
|
+
const m = Math.pow(10, mantissa);
|
|
183
|
+
return {
|
|
184
|
+
get(value) {
|
|
185
|
+
let numTokens = 0;
|
|
186
|
+
let inWord = false;
|
|
187
|
+
for (let i = 0; i < value.length; i++) if (!isWordSeparator(value.charCodeAt(i))) {
|
|
188
|
+
if (!inWord) {
|
|
189
|
+
numTokens++;
|
|
190
|
+
inWord = true;
|
|
191
|
+
}
|
|
192
|
+
} else inWord = false;
|
|
193
|
+
if (numTokens === 0) numTokens = 1;
|
|
194
|
+
if (cache.has(numTokens)) return cache.get(numTokens);
|
|
195
|
+
const n = Math.round(m / Math.pow(numTokens, .5 * weight)) / m;
|
|
196
|
+
cache.set(numTokens, n);
|
|
197
|
+
return n;
|
|
198
|
+
},
|
|
199
|
+
clear() {
|
|
200
|
+
cache.clear();
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
var FuseIndex = class {
|
|
205
|
+
constructor({ getFn = Config.getFn, fieldNormWeight = Config.fieldNormWeight } = {}) {
|
|
206
|
+
this.norm = norm(fieldNormWeight, 3);
|
|
207
|
+
this.getFn = getFn;
|
|
208
|
+
this.isCreated = false;
|
|
209
|
+
this.docs = [];
|
|
210
|
+
this.keys = [];
|
|
211
|
+
this._keysMap = {};
|
|
212
|
+
this.setIndexRecords();
|
|
213
|
+
}
|
|
214
|
+
setSources(docs = []) {
|
|
215
|
+
this.docs = docs;
|
|
216
|
+
}
|
|
217
|
+
setIndexRecords(records = []) {
|
|
218
|
+
this.records = records;
|
|
219
|
+
}
|
|
220
|
+
setKeys(keys = []) {
|
|
221
|
+
this.keys = keys;
|
|
222
|
+
this._keysMap = {};
|
|
223
|
+
keys.forEach((key, idx) => {
|
|
224
|
+
this._keysMap[key.id] = idx;
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
create() {
|
|
228
|
+
if (this.isCreated || !this.docs.length) return;
|
|
229
|
+
this.isCreated = true;
|
|
230
|
+
const len = this.docs.length;
|
|
231
|
+
this.records = new Array(len);
|
|
232
|
+
let recordCount = 0;
|
|
233
|
+
if (isString(this.docs[0])) for (let i = 0; i < len; i++) {
|
|
234
|
+
const record = this._createStringRecord(this.docs[i], i);
|
|
235
|
+
if (record) this.records[recordCount++] = record;
|
|
236
|
+
}
|
|
237
|
+
else for (let i = 0; i < len; i++) this.records[recordCount++] = this._createObjectRecord(this.docs[i], i);
|
|
238
|
+
this.records.length = recordCount;
|
|
239
|
+
this.norm.clear();
|
|
240
|
+
}
|
|
241
|
+
add(doc, docIndex) {
|
|
242
|
+
if (!Number.isInteger(docIndex) || docIndex < 0) throw new Error(INVALID_DOC_INDEX);
|
|
243
|
+
if (isString(doc)) {
|
|
244
|
+
const record = this._createStringRecord(doc, docIndex);
|
|
245
|
+
if (record) this.records.push(record);
|
|
246
|
+
return record;
|
|
247
|
+
}
|
|
248
|
+
const record = this._createObjectRecord(doc, docIndex);
|
|
249
|
+
this.records.push(record);
|
|
250
|
+
return record;
|
|
251
|
+
}
|
|
252
|
+
removeAt(idx) {
|
|
253
|
+
if (!Number.isInteger(idx) || idx < 0) throw new Error(INVALID_DOC_INDEX);
|
|
254
|
+
for (let i = 0, len = this.records.length; i < len; i += 1) if (this.records[i].i === idx) {
|
|
255
|
+
this.records.splice(i, 1);
|
|
256
|
+
break;
|
|
257
|
+
}
|
|
258
|
+
for (let i = 0, len = this.records.length; i < len; i += 1) if (this.records[i].i > idx) this.records[i].i -= 1;
|
|
259
|
+
}
|
|
260
|
+
removeAll(indices) {
|
|
261
|
+
const toRemove = /* @__PURE__ */ new Set();
|
|
262
|
+
for (const v of indices) if (Number.isInteger(v) && v >= 0) toRemove.add(v);
|
|
263
|
+
if (toRemove.size === 0) return;
|
|
264
|
+
this.records = this.records.filter((r) => !toRemove.has(r.i));
|
|
265
|
+
const sorted = Array.from(toRemove).sort((a, b) => a - b);
|
|
266
|
+
for (const record of this.records) {
|
|
267
|
+
let lo = 0;
|
|
268
|
+
let hi = sorted.length;
|
|
269
|
+
while (lo < hi) {
|
|
270
|
+
const mid = lo + hi >>> 1;
|
|
271
|
+
if (sorted[mid] < record.i) lo = mid + 1;
|
|
272
|
+
else hi = mid;
|
|
273
|
+
}
|
|
274
|
+
record.i -= lo;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
getValueForItemAtKeyId(item, keyId) {
|
|
278
|
+
return item[this._keysMap[keyId]];
|
|
279
|
+
}
|
|
280
|
+
size() {
|
|
281
|
+
return this.records.length;
|
|
282
|
+
}
|
|
283
|
+
_createStringRecord(doc, docIndex) {
|
|
284
|
+
if (!isDefined(doc) || isBlank(doc)) return null;
|
|
285
|
+
return {
|
|
286
|
+
v: doc,
|
|
287
|
+
i: docIndex,
|
|
288
|
+
n: this.norm.get(doc)
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
_createObjectRecord(doc, docIndex) {
|
|
292
|
+
const record = {
|
|
293
|
+
i: docIndex,
|
|
294
|
+
$: {}
|
|
295
|
+
};
|
|
296
|
+
for (let keyIndex = 0, keyLen = this.keys.length; keyIndex < keyLen; keyIndex++) {
|
|
297
|
+
const key = this.keys[keyIndex];
|
|
298
|
+
const value = key.getFn ? key.getFn(doc) : this.getFn(doc, key.path);
|
|
299
|
+
if (!isDefined(value)) continue;
|
|
300
|
+
if (isArray(value)) {
|
|
301
|
+
const subRecords = [];
|
|
302
|
+
for (let i = 0, len = value.length; i < len; i += 1) {
|
|
303
|
+
const item = value[i];
|
|
304
|
+
if (!isDefined(item)) continue;
|
|
305
|
+
if (isString(item)) {
|
|
306
|
+
if (!isBlank(item)) {
|
|
307
|
+
const subRecord = {
|
|
308
|
+
v: item,
|
|
309
|
+
i,
|
|
310
|
+
n: this.norm.get(item)
|
|
311
|
+
};
|
|
312
|
+
subRecords.push(subRecord);
|
|
313
|
+
}
|
|
314
|
+
} else if (isDefined(item.v)) {
|
|
315
|
+
const text = isString(item.v) ? item.v : toString(item.v);
|
|
316
|
+
if (!isBlank(text)) {
|
|
317
|
+
const subRecord = {
|
|
318
|
+
v: text,
|
|
319
|
+
i: item.i,
|
|
320
|
+
n: this.norm.get(text)
|
|
321
|
+
};
|
|
322
|
+
subRecords.push(subRecord);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
record.$[keyIndex] = subRecords;
|
|
327
|
+
} else if (isString(value) && !isBlank(value)) {
|
|
328
|
+
const subRecord = {
|
|
329
|
+
v: value,
|
|
330
|
+
n: this.norm.get(value)
|
|
331
|
+
};
|
|
332
|
+
record.$[keyIndex] = subRecord;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
return record;
|
|
336
|
+
}
|
|
337
|
+
toJSON() {
|
|
338
|
+
return {
|
|
339
|
+
keys: this.keys.map(({ getFn, ...key }) => key),
|
|
340
|
+
records: this.records
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
};
|
|
344
|
+
function createIndex(keys, docs, { getFn = Config.getFn, fieldNormWeight = Config.fieldNormWeight } = {}) {
|
|
345
|
+
const myIndex = new FuseIndex({
|
|
346
|
+
getFn,
|
|
347
|
+
fieldNormWeight
|
|
348
|
+
});
|
|
349
|
+
myIndex.setKeys(keys.map(createKey));
|
|
350
|
+
myIndex.setSources(docs);
|
|
351
|
+
myIndex.create();
|
|
352
|
+
return myIndex;
|
|
353
|
+
}
|
|
354
|
+
function parseIndex(data, { getFn = Config.getFn, fieldNormWeight = Config.fieldNormWeight } = {}) {
|
|
355
|
+
const { keys, records } = data;
|
|
356
|
+
const myIndex = new FuseIndex({
|
|
357
|
+
getFn,
|
|
358
|
+
fieldNormWeight
|
|
359
|
+
});
|
|
360
|
+
myIndex.setKeys(keys);
|
|
361
|
+
myIndex.setIndexRecords(records);
|
|
362
|
+
return myIndex;
|
|
363
|
+
}
|
|
364
|
+
function convertMaskToIndices(matchmask = [], minMatchCharLength = Config.minMatchCharLength) {
|
|
365
|
+
const indices = [];
|
|
366
|
+
let start = -1;
|
|
367
|
+
let end = -1;
|
|
368
|
+
let i = 0;
|
|
369
|
+
for (let len = matchmask.length; i < len; i += 1) {
|
|
370
|
+
const match = matchmask[i];
|
|
371
|
+
if (match && start === -1) start = i;
|
|
372
|
+
else if (!match && start !== -1) {
|
|
373
|
+
end = i - 1;
|
|
374
|
+
if (end - start + 1 >= minMatchCharLength) indices.push([start, end]);
|
|
375
|
+
start = -1;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
if (matchmask[i - 1] && i - start >= minMatchCharLength) indices.push([start, i - 1]);
|
|
379
|
+
return indices;
|
|
380
|
+
}
|
|
381
|
+
function search(text, pattern, patternAlphabet, { location = Config.location, distance = Config.distance, threshold = Config.threshold, findAllMatches = Config.findAllMatches, minMatchCharLength = Config.minMatchCharLength, includeMatches = Config.includeMatches, ignoreLocation = Config.ignoreLocation } = {}) {
|
|
382
|
+
if (pattern.length > 32) throw new Error(PATTERN_LENGTH_TOO_LARGE(32));
|
|
383
|
+
const patternLen = pattern.length;
|
|
384
|
+
const textLen = text.length;
|
|
385
|
+
const expectedLocation = Math.max(0, Math.min(location, textLen));
|
|
386
|
+
let currentThreshold = threshold;
|
|
387
|
+
let bestLocation = expectedLocation;
|
|
388
|
+
const calcScore = (errors, currentLocation) => {
|
|
389
|
+
const accuracy = errors / patternLen;
|
|
390
|
+
if (ignoreLocation) return accuracy;
|
|
391
|
+
const proximity = Math.abs(expectedLocation - currentLocation);
|
|
392
|
+
if (!distance) return proximity ? 1 : accuracy;
|
|
393
|
+
return accuracy + proximity / distance;
|
|
394
|
+
};
|
|
395
|
+
const computeMatches = minMatchCharLength > 1 || includeMatches;
|
|
396
|
+
const matchMask = computeMatches ? Array(textLen) : [];
|
|
397
|
+
let index;
|
|
398
|
+
while ((index = text.indexOf(pattern, bestLocation)) > -1) {
|
|
399
|
+
const score = calcScore(0, index);
|
|
400
|
+
currentThreshold = Math.min(score, currentThreshold);
|
|
401
|
+
bestLocation = index + patternLen;
|
|
402
|
+
if (computeMatches) {
|
|
403
|
+
let i = 0;
|
|
404
|
+
while (i < patternLen) {
|
|
405
|
+
matchMask[index + i] = 1;
|
|
406
|
+
i += 1;
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
bestLocation = -1;
|
|
411
|
+
let lastBitArr = [];
|
|
412
|
+
let finalScore = 1;
|
|
413
|
+
let bestErrors = 0;
|
|
414
|
+
let binMax = patternLen + textLen;
|
|
415
|
+
const mask = 1 << patternLen - 1;
|
|
416
|
+
for (let i = 0; i < patternLen; i += 1) {
|
|
417
|
+
let binMin = 0;
|
|
418
|
+
let binMid = binMax;
|
|
419
|
+
while (binMin < binMid) {
|
|
420
|
+
if (calcScore(i, expectedLocation + binMid) <= currentThreshold) binMin = binMid;
|
|
421
|
+
else binMax = binMid;
|
|
422
|
+
binMid = Math.floor((binMax - binMin) / 2 + binMin);
|
|
423
|
+
}
|
|
424
|
+
binMax = binMid;
|
|
425
|
+
let start = Math.max(1, expectedLocation - binMid + 1);
|
|
426
|
+
const finish = findAllMatches ? textLen : Math.min(expectedLocation + binMid, textLen) + patternLen;
|
|
427
|
+
const bitArr = Array(finish + 2);
|
|
428
|
+
bitArr[finish + 1] = (1 << i) - 1;
|
|
429
|
+
for (let j = finish; j >= start; j -= 1) {
|
|
430
|
+
const currentLocation = j - 1;
|
|
431
|
+
const charMatch = patternAlphabet[text[currentLocation]];
|
|
432
|
+
bitArr[j] = (bitArr[j + 1] << 1 | 1) & charMatch;
|
|
433
|
+
if (i) bitArr[j] |= (lastBitArr[j + 1] | lastBitArr[j]) << 1 | 1 | lastBitArr[j + 1];
|
|
434
|
+
if (bitArr[j] & mask) {
|
|
435
|
+
finalScore = calcScore(i, currentLocation);
|
|
436
|
+
if (finalScore <= currentThreshold) {
|
|
437
|
+
currentThreshold = finalScore;
|
|
438
|
+
bestLocation = currentLocation;
|
|
439
|
+
bestErrors = i;
|
|
440
|
+
if (bestLocation <= expectedLocation) break;
|
|
441
|
+
start = Math.max(1, 2 * expectedLocation - bestLocation);
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
if (calcScore(i + 1, expectedLocation) > currentThreshold) break;
|
|
446
|
+
lastBitArr = bitArr;
|
|
447
|
+
}
|
|
448
|
+
if (computeMatches && bestLocation >= 0) {
|
|
449
|
+
const matchEnd = Math.min(textLen - 1, bestLocation + patternLen - 1 + bestErrors);
|
|
450
|
+
for (let k = bestLocation; k <= matchEnd; k += 1) if (patternAlphabet[text[k]]) matchMask[k] = 1;
|
|
451
|
+
}
|
|
452
|
+
const result = {
|
|
453
|
+
isMatch: bestLocation >= 0,
|
|
454
|
+
score: Math.max(.001, finalScore)
|
|
455
|
+
};
|
|
456
|
+
if (computeMatches) {
|
|
457
|
+
const indices = convertMaskToIndices(matchMask, minMatchCharLength);
|
|
458
|
+
if (!indices.length) result.isMatch = false;
|
|
459
|
+
else if (includeMatches) result.indices = indices;
|
|
460
|
+
}
|
|
461
|
+
return result;
|
|
462
|
+
}
|
|
463
|
+
function createPatternAlphabet(pattern) {
|
|
464
|
+
const mask = {};
|
|
465
|
+
for (let i = 0, len = pattern.length; i < len; i += 1) {
|
|
466
|
+
const char = pattern.charAt(i);
|
|
467
|
+
mask[char] = (mask[char] || 0) | 1 << len - i - 1;
|
|
468
|
+
}
|
|
469
|
+
return mask;
|
|
470
|
+
}
|
|
471
|
+
function mergeIndices(indices) {
|
|
472
|
+
if (indices.length <= 1) return indices;
|
|
473
|
+
indices.sort((a, b) => a[0] - b[0] || a[1] - b[1]);
|
|
474
|
+
const merged = [indices[0]];
|
|
475
|
+
for (let i = 1, len = indices.length; i < len; i += 1) {
|
|
476
|
+
const last = merged[merged.length - 1];
|
|
477
|
+
const curr = indices[i];
|
|
478
|
+
if (curr[0] <= last[1] + 1) last[1] = Math.max(last[1], curr[1]);
|
|
479
|
+
else merged.push(curr);
|
|
480
|
+
}
|
|
481
|
+
return merged;
|
|
482
|
+
}
|
|
483
|
+
var NON_DECOMPOSABLE_MAP = {
|
|
484
|
+
"ł": "l",
|
|
485
|
+
"Ł": "L",
|
|
486
|
+
"đ": "d",
|
|
487
|
+
"Đ": "D",
|
|
488
|
+
"ø": "o",
|
|
489
|
+
"Ø": "O",
|
|
490
|
+
"ħ": "h",
|
|
491
|
+
"Ħ": "H",
|
|
492
|
+
"ŧ": "t",
|
|
493
|
+
"Ŧ": "T",
|
|
494
|
+
"ı": "i",
|
|
495
|
+
"ß": "ss"
|
|
496
|
+
};
|
|
497
|
+
var NON_DECOMPOSABLE_RE = new RegExp("[" + Object.keys(NON_DECOMPOSABLE_MAP).join("") + "]", "g");
|
|
498
|
+
var stripDiacritics = typeof String.prototype.normalize === "function" ? (str) => str.normalize("NFD").replace(/[\u0300-\u036F\u0483-\u0489\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u0610-\u061A\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED\u0711\u0730-\u074A\u07A6-\u07B0\u07EB-\u07F3\u07FD\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u082D\u0859-\u085B\u08D3-\u08E1\u08E3-\u0903\u093A-\u093C\u093E-\u094F\u0951-\u0957\u0962\u0963\u0981-\u0983\u09BC\u09BE-\u09C4\u09C7\u09C8\u09CB-\u09CD\u09D7\u09E2\u09E3\u09FE\u0A01-\u0A03\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A70\u0A71\u0A75\u0A81-\u0A83\u0ABC\u0ABE-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AE2\u0AE3\u0AFA-\u0AFF\u0B01-\u0B03\u0B3C\u0B3E-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B62\u0B63\u0B82\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD7\u0C00-\u0C04\u0C3E-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C62\u0C63\u0C81-\u0C83\u0CBC\u0CBE-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CE2\u0CE3\u0D00-\u0D03\u0D3B\u0D3C\u0D3E-\u0D44\u0D46-\u0D48\u0D4A-\u0D4D\u0D57\u0D62\u0D63\u0D82\u0D83\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DF2\u0DF3\u0E31\u0E34-\u0E3A\u0E47-\u0E4E\u0EB1\u0EB4-\u0EB9\u0EBB\u0EBC\u0EC8-\u0ECD\u0F18\u0F19\u0F35\u0F37\u0F39\u0F3E\u0F3F\u0F71-\u0F84\u0F86\u0F87\u0F8D-\u0F97\u0F99-\u0FBC\u0FC6\u102B-\u103E\u1056-\u1059\u105E-\u1060\u1062-\u1064\u1067-\u106D\u1071-\u1074\u1082-\u108D\u108F\u109A-\u109D\u135D-\u135F\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17B4-\u17D3\u17DD\u180B-\u180D\u1885\u1886\u18A9\u1920-\u192B\u1930-\u193B\u1A17-\u1A1B\u1A55-\u1A5E\u1A60-\u1A7C\u1A7F\u1AB0-\u1ABE\u1B00-\u1B04\u1B34-\u1B44\u1B6B-\u1B73\u1B80-\u1B82\u1BA1-\u1BAD\u1BE6-\u1BF3\u1C24-\u1C37\u1CD0-\u1CD2\u1CD4-\u1CE8\u1CED\u1CF2-\u1CF4\u1CF7-\u1CF9\u1DC0-\u1DF9\u1DFB-\u1DFF\u20D0-\u20F0\u2CEF-\u2CF1\u2D7F\u2DE0-\u2DFF\u302A-\u302F\u3099\u309A\uA66F-\uA672\uA674-\uA67D\uA69E\uA69F\uA6F0\uA6F1\uA802\uA806\uA80B\uA823-\uA827\uA880\uA881\uA8B4-\uA8C5\uA8E0-\uA8F1\uA8FF\uA926-\uA92D\uA947-\uA953\uA980-\uA983\uA9B3-\uA9C0\uA9E5\uAA29-\uAA36\uAA43\uAA4C\uAA4D\uAA7B-\uAA7D\uAAB0\uAAB2-\uAAB4\uAAB7\uAAB8\uAABE\uAABF\uAAC1\uAAEB-\uAAEF\uAAF5\uAAF6\uABE3-\uABEA\uABEC\uABED\uFB1E\uFE00-\uFE0F\uFE20-\uFE2F]/g, "").replace(NON_DECOMPOSABLE_RE, (ch) => NON_DECOMPOSABLE_MAP[ch]) : (str) => str;
|
|
499
|
+
var BitapSearch = class {
|
|
500
|
+
constructor(pattern, { location = Config.location, threshold = Config.threshold, distance = Config.distance, includeMatches = Config.includeMatches, findAllMatches = Config.findAllMatches, minMatchCharLength = Config.minMatchCharLength, isCaseSensitive = Config.isCaseSensitive, ignoreDiacritics = Config.ignoreDiacritics, ignoreLocation = Config.ignoreLocation } = {}) {
|
|
501
|
+
this.options = {
|
|
502
|
+
location,
|
|
503
|
+
threshold,
|
|
504
|
+
distance,
|
|
505
|
+
includeMatches,
|
|
506
|
+
findAllMatches,
|
|
507
|
+
minMatchCharLength,
|
|
508
|
+
isCaseSensitive,
|
|
509
|
+
ignoreDiacritics,
|
|
510
|
+
ignoreLocation
|
|
511
|
+
};
|
|
512
|
+
pattern = isCaseSensitive ? pattern : pattern.toLowerCase();
|
|
513
|
+
pattern = ignoreDiacritics ? stripDiacritics(pattern) : pattern;
|
|
514
|
+
this.pattern = pattern;
|
|
515
|
+
this.chunks = [];
|
|
516
|
+
if (!this.pattern.length) return;
|
|
517
|
+
const addChunk = (pattern, startIndex) => {
|
|
518
|
+
this.chunks.push({
|
|
519
|
+
pattern,
|
|
520
|
+
alphabet: createPatternAlphabet(pattern),
|
|
521
|
+
startIndex
|
|
522
|
+
});
|
|
523
|
+
};
|
|
524
|
+
const len = this.pattern.length;
|
|
525
|
+
if (len > 32) {
|
|
526
|
+
let i = 0;
|
|
527
|
+
const remainder = len % 32;
|
|
528
|
+
const end = len - remainder;
|
|
529
|
+
while (i < end) {
|
|
530
|
+
addChunk(this.pattern.substr(i, 32), i);
|
|
531
|
+
i += 32;
|
|
532
|
+
}
|
|
533
|
+
if (remainder) {
|
|
534
|
+
const startIndex = len - 32;
|
|
535
|
+
addChunk(this.pattern.substr(startIndex), startIndex);
|
|
536
|
+
}
|
|
537
|
+
} else addChunk(this.pattern, 0);
|
|
538
|
+
}
|
|
539
|
+
searchIn(text) {
|
|
540
|
+
const { isCaseSensitive, ignoreDiacritics, includeMatches } = this.options;
|
|
541
|
+
text = isCaseSensitive ? text : text.toLowerCase();
|
|
542
|
+
text = ignoreDiacritics ? stripDiacritics(text) : text;
|
|
543
|
+
if (this.pattern === text) {
|
|
544
|
+
if (text.length < this.options.minMatchCharLength) return {
|
|
545
|
+
isMatch: false,
|
|
546
|
+
score: 1
|
|
547
|
+
};
|
|
548
|
+
const result = {
|
|
549
|
+
isMatch: true,
|
|
550
|
+
score: 0
|
|
551
|
+
};
|
|
552
|
+
if (includeMatches) result.indices = [[0, text.length - 1]];
|
|
553
|
+
return result;
|
|
554
|
+
}
|
|
555
|
+
const { location, distance, threshold, findAllMatches, minMatchCharLength, ignoreLocation } = this.options;
|
|
556
|
+
const allIndices = [];
|
|
557
|
+
let totalScore = 0;
|
|
558
|
+
let hasMatches = false;
|
|
559
|
+
this.chunks.forEach(({ pattern, alphabet, startIndex }) => {
|
|
560
|
+
const { isMatch, score, indices } = search(text, pattern, alphabet, {
|
|
561
|
+
location: location + startIndex,
|
|
562
|
+
distance,
|
|
563
|
+
threshold,
|
|
564
|
+
findAllMatches,
|
|
565
|
+
minMatchCharLength,
|
|
566
|
+
includeMatches,
|
|
567
|
+
ignoreLocation
|
|
568
|
+
});
|
|
569
|
+
if (isMatch) hasMatches = true;
|
|
570
|
+
totalScore += score;
|
|
571
|
+
if (isMatch && indices) allIndices.push(...indices);
|
|
572
|
+
});
|
|
573
|
+
const result = {
|
|
574
|
+
isMatch: hasMatches,
|
|
575
|
+
score: hasMatches ? totalScore / this.chunks.length : 1
|
|
576
|
+
};
|
|
577
|
+
if (hasMatches && includeMatches) result.indices = mergeIndices(allIndices);
|
|
578
|
+
return result;
|
|
579
|
+
}
|
|
580
|
+
};
|
|
581
|
+
var registeredSearchers = [];
|
|
582
|
+
function register(...args) {
|
|
583
|
+
registeredSearchers.push(...args);
|
|
584
|
+
}
|
|
585
|
+
function createSearcher(pattern, options) {
|
|
586
|
+
for (let i = 0, len = registeredSearchers.length; i < len; i += 1) {
|
|
587
|
+
const searcherClass = registeredSearchers[i];
|
|
588
|
+
if (searcherClass.condition(pattern, options)) return new searcherClass(pattern, options);
|
|
589
|
+
}
|
|
590
|
+
return new BitapSearch(pattern, options);
|
|
591
|
+
}
|
|
592
|
+
var LogicalOperator = {
|
|
593
|
+
AND: "$and",
|
|
594
|
+
OR: "$or"
|
|
595
|
+
};
|
|
596
|
+
var KeyType = {
|
|
597
|
+
PATH: "$path",
|
|
598
|
+
PATTERN: "$val"
|
|
599
|
+
};
|
|
600
|
+
var isExpression = (query) => !!(query[LogicalOperator.AND] || query[LogicalOperator.OR]);
|
|
601
|
+
var isPath = (query) => !!query[KeyType.PATH];
|
|
602
|
+
var isLeaf = (query) => !isArray(query) && isObject(query) && !isExpression(query);
|
|
603
|
+
var convertToExplicit = (query) => ({ [LogicalOperator.AND]: Object.keys(query).map((key) => ({ [key]: query[key] })) });
|
|
604
|
+
function parse(query, options, { auto = true } = {}) {
|
|
605
|
+
const next = (query) => {
|
|
606
|
+
if (isString(query)) {
|
|
607
|
+
const obj = {
|
|
608
|
+
keyId: null,
|
|
609
|
+
pattern: query
|
|
610
|
+
};
|
|
611
|
+
if (auto) obj.searcher = createSearcher(query, options);
|
|
612
|
+
return obj;
|
|
613
|
+
}
|
|
614
|
+
const keys = Object.keys(query);
|
|
615
|
+
const isQueryPath = isPath(query);
|
|
616
|
+
if (!isQueryPath && keys.length > 1 && !isExpression(query)) return next(convertToExplicit(query));
|
|
617
|
+
if (isLeaf(query)) {
|
|
618
|
+
const key = isQueryPath ? query[KeyType.PATH] : keys[0];
|
|
619
|
+
const pattern = isQueryPath ? query[KeyType.PATTERN] : query[key];
|
|
620
|
+
if (!isString(pattern)) throw new Error(LOGICAL_SEARCH_INVALID_QUERY_FOR_KEY(key));
|
|
621
|
+
const obj = {
|
|
622
|
+
keyId: createKeyId(key),
|
|
623
|
+
pattern
|
|
624
|
+
};
|
|
625
|
+
if (auto) obj.searcher = createSearcher(pattern, options);
|
|
626
|
+
return obj;
|
|
627
|
+
}
|
|
628
|
+
const node = {
|
|
629
|
+
children: [],
|
|
630
|
+
operator: keys[0]
|
|
631
|
+
};
|
|
632
|
+
keys.forEach((key) => {
|
|
633
|
+
const value = query[key];
|
|
634
|
+
if (isArray(value)) value.forEach((item) => {
|
|
635
|
+
node.children.push(next(item));
|
|
636
|
+
});
|
|
637
|
+
});
|
|
638
|
+
return node;
|
|
639
|
+
};
|
|
640
|
+
if (!isExpression(query)) query = convertToExplicit(query);
|
|
641
|
+
return next(query);
|
|
642
|
+
}
|
|
643
|
+
function computeScoreSingle(matches, { ignoreFieldNorm = Config.ignoreFieldNorm }) {
|
|
644
|
+
let totalScore = 1;
|
|
645
|
+
matches.forEach(({ key, norm, score }) => {
|
|
646
|
+
const weight = key ? key.weight : null;
|
|
647
|
+
totalScore *= Math.pow(score === 0 && weight ? Number.EPSILON : score, (weight || 1) * (ignoreFieldNorm ? 1 : norm));
|
|
648
|
+
});
|
|
649
|
+
return totalScore;
|
|
650
|
+
}
|
|
651
|
+
function computeScore(results, { ignoreFieldNorm = Config.ignoreFieldNorm }) {
|
|
652
|
+
results.forEach((result) => {
|
|
653
|
+
result.score = computeScoreSingle(result.matches, { ignoreFieldNorm });
|
|
654
|
+
});
|
|
655
|
+
}
|
|
656
|
+
var MaxHeap = class {
|
|
657
|
+
constructor(limit, comparator) {
|
|
658
|
+
this.limit = limit;
|
|
659
|
+
this.heap = [];
|
|
660
|
+
this.comparator = comparator;
|
|
661
|
+
}
|
|
662
|
+
get size() {
|
|
663
|
+
return this.heap.length;
|
|
664
|
+
}
|
|
665
|
+
insert(item) {
|
|
666
|
+
if (this.size < this.limit) {
|
|
667
|
+
this.heap.push(item);
|
|
668
|
+
this._bubbleUp(this.size - 1);
|
|
669
|
+
} else if (this.comparator(item, this.heap[0]) < 0) {
|
|
670
|
+
this.heap[0] = item;
|
|
671
|
+
this._sinkDown(0);
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
extractSorted() {
|
|
675
|
+
return this.heap.sort(this.comparator);
|
|
676
|
+
}
|
|
677
|
+
_bubbleUp(i) {
|
|
678
|
+
const heap = this.heap;
|
|
679
|
+
while (i > 0) {
|
|
680
|
+
const parent = i - 1 >> 1;
|
|
681
|
+
if (this.comparator(heap[i], heap[parent]) <= 0) break;
|
|
682
|
+
const tmp = heap[i];
|
|
683
|
+
heap[i] = heap[parent];
|
|
684
|
+
heap[parent] = tmp;
|
|
685
|
+
i = parent;
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
_sinkDown(i) {
|
|
689
|
+
const heap = this.heap;
|
|
690
|
+
const len = heap.length;
|
|
691
|
+
let largest = i;
|
|
692
|
+
do {
|
|
693
|
+
i = largest;
|
|
694
|
+
const left = 2 * i + 1;
|
|
695
|
+
const right = 2 * i + 2;
|
|
696
|
+
if (left < len && this.comparator(heap[left], heap[largest]) > 0) largest = left;
|
|
697
|
+
if (right < len && this.comparator(heap[right], heap[largest]) > 0) largest = right;
|
|
698
|
+
if (largest !== i) {
|
|
699
|
+
const tmp = heap[i];
|
|
700
|
+
heap[i] = heap[largest];
|
|
701
|
+
heap[largest] = tmp;
|
|
702
|
+
}
|
|
703
|
+
} while (largest !== i);
|
|
704
|
+
}
|
|
705
|
+
};
|
|
706
|
+
function formatMatches(result) {
|
|
707
|
+
const matches = [];
|
|
708
|
+
result.matches.forEach((match) => {
|
|
709
|
+
if (!isDefined(match.indices) || !match.indices.length) return;
|
|
710
|
+
const obj = {
|
|
711
|
+
indices: match.indices,
|
|
712
|
+
value: match.value
|
|
713
|
+
};
|
|
714
|
+
if (match.key) obj.key = match.key.id;
|
|
715
|
+
if (match.idx > -1) obj.refIndex = match.idx;
|
|
716
|
+
matches.push(obj);
|
|
717
|
+
});
|
|
718
|
+
return matches;
|
|
719
|
+
}
|
|
720
|
+
function format(results, docs, { includeMatches = Config.includeMatches, includeScore = Config.includeScore } = {}) {
|
|
721
|
+
return results.map((result) => {
|
|
722
|
+
const { idx } = result;
|
|
723
|
+
const data = {
|
|
724
|
+
item: docs[idx],
|
|
725
|
+
refIndex: idx
|
|
726
|
+
};
|
|
727
|
+
if (includeMatches) data.matches = formatMatches(result);
|
|
728
|
+
if (includeScore) data.score = result.score;
|
|
729
|
+
return data;
|
|
730
|
+
});
|
|
731
|
+
}
|
|
732
|
+
var DEFAULT_TOKEN = /[\p{L}\p{M}\p{N}_]+/gu;
|
|
733
|
+
var warned = /* @__PURE__ */ new WeakSet();
|
|
734
|
+
function warnNonGlobal(regex) {
|
|
735
|
+
if (!warned.has(regex)) {
|
|
736
|
+
warned.add(regex);
|
|
737
|
+
console.warn(`[Fuse] tokenize regex ${regex} lacks the global flag; only the first match per text will be returned. Add the 'g' flag.`);
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
function resolveTokenize(tokenize) {
|
|
741
|
+
if (typeof tokenize === "function") {
|
|
742
|
+
let validated = false;
|
|
743
|
+
return (text) => {
|
|
744
|
+
const result = tokenize(text);
|
|
745
|
+
if (!validated) {
|
|
746
|
+
validated = true;
|
|
747
|
+
if (!Array.isArray(result) || result.some((t) => typeof t !== "string")) throw new Error(`[Fuse] tokenize function must return string[]; received ${Array.isArray(result) ? "array containing non-strings" : typeof result}.`);
|
|
748
|
+
}
|
|
749
|
+
return result;
|
|
750
|
+
};
|
|
751
|
+
}
|
|
752
|
+
if (tokenize instanceof RegExp) {
|
|
753
|
+
if (!tokenize.global) warnNonGlobal(tokenize);
|
|
754
|
+
return (text) => text.match(tokenize) || [];
|
|
755
|
+
}
|
|
756
|
+
return (text) => text.match(DEFAULT_TOKEN) || [];
|
|
757
|
+
}
|
|
758
|
+
function createAnalyzer({ isCaseSensitive = false, ignoreDiacritics = false, tokenize } = {}) {
|
|
759
|
+
const tokenizeFn = resolveTokenize(tokenize);
|
|
760
|
+
return { tokenize(text) {
|
|
761
|
+
if (!isCaseSensitive) text = text.toLowerCase();
|
|
762
|
+
if (ignoreDiacritics) text = stripDiacritics(text);
|
|
763
|
+
return tokenizeFn(text);
|
|
764
|
+
} };
|
|
765
|
+
}
|
|
766
|
+
function addField(index, text, docIdx, analyzer) {
|
|
767
|
+
const tokens = analyzer.tokenize(text);
|
|
768
|
+
if (!tokens.length) return;
|
|
769
|
+
index.fieldCount++;
|
|
770
|
+
index.docFieldCount.set(docIdx, (index.docFieldCount.get(docIdx) || 0) + 1);
|
|
771
|
+
const distinctTerms = new Set(tokens);
|
|
772
|
+
let perDocTerms = index.docTermFieldHits.get(docIdx);
|
|
773
|
+
if (!perDocTerms) {
|
|
774
|
+
perDocTerms = /* @__PURE__ */ new Map();
|
|
775
|
+
index.docTermFieldHits.set(docIdx, perDocTerms);
|
|
776
|
+
}
|
|
777
|
+
for (const term of distinctTerms) {
|
|
778
|
+
perDocTerms.set(term, (perDocTerms.get(term) || 0) + 1);
|
|
779
|
+
index.df.set(term, (index.df.get(term) || 0) + 1);
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
function ingestRecord(index, record, keyCount, analyzer) {
|
|
783
|
+
const { i: docIdx, v, $: fields } = record;
|
|
784
|
+
if (v !== void 0) {
|
|
785
|
+
addField(index, v, docIdx, analyzer);
|
|
786
|
+
return;
|
|
787
|
+
}
|
|
788
|
+
if (!fields) return;
|
|
789
|
+
for (let keyIdx = 0; keyIdx < keyCount; keyIdx++) {
|
|
790
|
+
const value = fields[keyIdx];
|
|
791
|
+
if (!value) continue;
|
|
792
|
+
if (Array.isArray(value)) for (const sub of value) addField(index, sub.v, docIdx, analyzer);
|
|
793
|
+
else addField(index, value.v, docIdx, analyzer);
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
function buildInvertedIndex(records, keyCount, analyzer) {
|
|
797
|
+
const index = {
|
|
798
|
+
fieldCount: 0,
|
|
799
|
+
df: /* @__PURE__ */ new Map(),
|
|
800
|
+
docFieldCount: /* @__PURE__ */ new Map(),
|
|
801
|
+
docTermFieldHits: /* @__PURE__ */ new Map()
|
|
802
|
+
};
|
|
803
|
+
for (const record of records) ingestRecord(index, record, keyCount, analyzer);
|
|
804
|
+
return index;
|
|
805
|
+
}
|
|
806
|
+
function addToInvertedIndex(index, record, keyCount, analyzer) {
|
|
807
|
+
ingestRecord(index, record, keyCount, analyzer);
|
|
808
|
+
}
|
|
809
|
+
function removeFromInvertedIndex(index, docIdx) {
|
|
810
|
+
const fieldCount = index.docFieldCount.get(docIdx);
|
|
811
|
+
if (fieldCount === void 0) return;
|
|
812
|
+
index.fieldCount -= fieldCount;
|
|
813
|
+
index.docFieldCount.delete(docIdx);
|
|
814
|
+
const perDocTerms = index.docTermFieldHits.get(docIdx);
|
|
815
|
+
if (!perDocTerms) return;
|
|
816
|
+
for (const [term, hits] of perDocTerms) {
|
|
817
|
+
const next = (index.df.get(term) || 0) - hits;
|
|
818
|
+
if (next <= 0) index.df.delete(term);
|
|
819
|
+
else index.df.set(term, next);
|
|
820
|
+
}
|
|
821
|
+
index.docTermFieldHits.delete(docIdx);
|
|
822
|
+
}
|
|
823
|
+
function removeAndShiftInvertedIndex(index, removedIndices) {
|
|
824
|
+
if (removedIndices.length === 0) return;
|
|
825
|
+
const sorted = Array.from(new Set(removedIndices)).sort((a, b) => a - b);
|
|
826
|
+
for (const idx of sorted) removeFromInvertedIndex(index, idx);
|
|
827
|
+
const shift = (oldIdx) => {
|
|
828
|
+
let lo = 0;
|
|
829
|
+
let hi = sorted.length;
|
|
830
|
+
while (lo < hi) {
|
|
831
|
+
const mid = lo + hi >>> 1;
|
|
832
|
+
if (sorted[mid] < oldIdx) lo = mid + 1;
|
|
833
|
+
else hi = mid;
|
|
834
|
+
}
|
|
835
|
+
return oldIdx - lo;
|
|
836
|
+
};
|
|
837
|
+
const firstRemoved = sorted[0];
|
|
838
|
+
const shiftedDocFieldCount = /* @__PURE__ */ new Map();
|
|
839
|
+
for (const [oldKey, count] of index.docFieldCount) shiftedDocFieldCount.set(oldKey > firstRemoved ? shift(oldKey) : oldKey, count);
|
|
840
|
+
index.docFieldCount = shiftedDocFieldCount;
|
|
841
|
+
const shiftedDocTermFieldHits = /* @__PURE__ */ new Map();
|
|
842
|
+
for (const [oldKey, terms] of index.docTermFieldHits) shiftedDocTermFieldHits.set(oldKey > firstRemoved ? shift(oldKey) : oldKey, terms);
|
|
843
|
+
index.docTermFieldHits = shiftedDocTermFieldHits;
|
|
844
|
+
}
|
|
845
|
+
var Fuse = class {
|
|
846
|
+
constructor(docs, options, index) {
|
|
847
|
+
this.options = {
|
|
848
|
+
...Config,
|
|
849
|
+
...options
|
|
850
|
+
};
|
|
851
|
+
if (this.options.useExtendedSearch && true) throw new Error(EXTENDED_SEARCH_UNAVAILABLE);
|
|
852
|
+
if (this.options.useTokenSearch && true) throw new Error(TOKEN_SEARCH_UNAVAILABLE);
|
|
853
|
+
this._keyStore = new KeyStore(this.options.keys);
|
|
854
|
+
this._docs = docs;
|
|
855
|
+
this._myIndex = null;
|
|
856
|
+
this._invertedIndex = null;
|
|
857
|
+
this.setCollection(docs, index);
|
|
858
|
+
this._lastQuery = null;
|
|
859
|
+
this._lastSearcher = null;
|
|
860
|
+
}
|
|
861
|
+
_getSearcher(query) {
|
|
862
|
+
if (this._lastQuery === query) return this._lastSearcher;
|
|
863
|
+
const searcher = createSearcher(query, this._invertedIndex ? {
|
|
864
|
+
...this.options,
|
|
865
|
+
_invertedIndex: this._invertedIndex
|
|
866
|
+
} : this.options);
|
|
867
|
+
this._lastQuery = query;
|
|
868
|
+
this._lastSearcher = searcher;
|
|
869
|
+
return searcher;
|
|
870
|
+
}
|
|
871
|
+
setCollection(docs, index) {
|
|
872
|
+
this._docs = docs;
|
|
873
|
+
if (index && !(index instanceof FuseIndex)) throw new Error(INCORRECT_INDEX_TYPE);
|
|
874
|
+
this._myIndex = index || createIndex(this.options.keys, this._docs, {
|
|
875
|
+
getFn: this.options.getFn,
|
|
876
|
+
fieldNormWeight: this.options.fieldNormWeight
|
|
877
|
+
});
|
|
878
|
+
if (this.options.useTokenSearch) {
|
|
879
|
+
const analyzer = createAnalyzer({
|
|
880
|
+
isCaseSensitive: this.options.isCaseSensitive,
|
|
881
|
+
ignoreDiacritics: this.options.ignoreDiacritics,
|
|
882
|
+
tokenize: this.options.tokenize
|
|
883
|
+
});
|
|
884
|
+
this._invertedIndex = buildInvertedIndex(this._myIndex.records, this._myIndex.keys.length, analyzer);
|
|
885
|
+
}
|
|
886
|
+
this._invalidateSearcherCache();
|
|
887
|
+
}
|
|
888
|
+
add(doc) {
|
|
889
|
+
if (!isDefined(doc)) return;
|
|
890
|
+
this._docs.push(doc);
|
|
891
|
+
const record = this._myIndex.add(doc, this._docs.length - 1);
|
|
892
|
+
if (this._invertedIndex && record) {
|
|
893
|
+
const analyzer = createAnalyzer({
|
|
894
|
+
isCaseSensitive: this.options.isCaseSensitive,
|
|
895
|
+
ignoreDiacritics: this.options.ignoreDiacritics,
|
|
896
|
+
tokenize: this.options.tokenize
|
|
897
|
+
});
|
|
898
|
+
addToInvertedIndex(this._invertedIndex, record, this._myIndex.keys.length, analyzer);
|
|
899
|
+
}
|
|
900
|
+
this._invalidateSearcherCache();
|
|
901
|
+
}
|
|
902
|
+
remove(predicate = () => false) {
|
|
903
|
+
const results = [];
|
|
904
|
+
const indicesToRemove = [];
|
|
905
|
+
for (let i = 0, len = this._docs.length; i < len; i += 1) if (predicate(this._docs[i], i)) {
|
|
906
|
+
results.push(this._docs[i]);
|
|
907
|
+
indicesToRemove.push(i);
|
|
908
|
+
}
|
|
909
|
+
if (indicesToRemove.length) {
|
|
910
|
+
if (this._invertedIndex) removeAndShiftInvertedIndex(this._invertedIndex, indicesToRemove);
|
|
911
|
+
const toRemove = new Set(indicesToRemove);
|
|
912
|
+
this._docs = this._docs.filter((_, i) => !toRemove.has(i));
|
|
913
|
+
this._myIndex.removeAll(indicesToRemove);
|
|
914
|
+
this._invalidateSearcherCache();
|
|
915
|
+
}
|
|
916
|
+
return results;
|
|
917
|
+
}
|
|
918
|
+
removeAt(idx) {
|
|
919
|
+
if (!Number.isInteger(idx) || idx < 0 || idx >= this._docs.length) throw new Error(INVALID_DOC_INDEX);
|
|
920
|
+
if (this._invertedIndex) removeAndShiftInvertedIndex(this._invertedIndex, [idx]);
|
|
921
|
+
const doc = this._docs.splice(idx, 1)[0];
|
|
922
|
+
this._myIndex.removeAt(idx);
|
|
923
|
+
this._invalidateSearcherCache();
|
|
924
|
+
return doc;
|
|
925
|
+
}
|
|
926
|
+
_invalidateSearcherCache() {
|
|
927
|
+
this._lastQuery = null;
|
|
928
|
+
this._lastSearcher = null;
|
|
929
|
+
}
|
|
930
|
+
getIndex() {
|
|
931
|
+
return this._myIndex;
|
|
932
|
+
}
|
|
933
|
+
_normalizedKeys() {
|
|
934
|
+
return this._myIndex.keys.map((key) => this._keyStore.get(key.id) || key);
|
|
935
|
+
}
|
|
936
|
+
search(query, options) {
|
|
937
|
+
const { limit = -1 } = options || {};
|
|
938
|
+
const { includeMatches, includeScore, shouldSort, sortFn, ignoreFieldNorm } = this.options;
|
|
939
|
+
if (isString(query) && !query.trim()) {
|
|
940
|
+
let docs = this._docs.map((item, idx) => ({
|
|
941
|
+
item,
|
|
942
|
+
refIndex: idx
|
|
943
|
+
}));
|
|
944
|
+
if (isNumber(limit) && limit > -1) docs = docs.slice(0, limit);
|
|
945
|
+
return docs;
|
|
946
|
+
}
|
|
947
|
+
const useHeap = shouldSort && isNumber(limit) && limit > 0 && isString(query);
|
|
948
|
+
const comparator = sortFn;
|
|
949
|
+
const stable = (a, b) => comparator(a, b) || a.idx - b.idx;
|
|
950
|
+
let results;
|
|
951
|
+
if (useHeap) {
|
|
952
|
+
const heap = new MaxHeap(limit, stable);
|
|
953
|
+
if (isString(this._docs[0])) this._searchStringList(query, {
|
|
954
|
+
heap,
|
|
955
|
+
ignoreFieldNorm
|
|
956
|
+
});
|
|
957
|
+
else this._searchObjectList(query, {
|
|
958
|
+
heap,
|
|
959
|
+
ignoreFieldNorm
|
|
960
|
+
});
|
|
961
|
+
results = heap.extractSorted();
|
|
962
|
+
} else {
|
|
963
|
+
results = isString(query) ? isString(this._docs[0]) ? this._searchStringList(query) : this._searchObjectList(query) : this._searchLogical(query);
|
|
964
|
+
computeScore(results, { ignoreFieldNorm });
|
|
965
|
+
if (shouldSort) results.sort(isString(query) ? stable : comparator);
|
|
966
|
+
if (isNumber(limit) && limit > -1) results = results.slice(0, limit);
|
|
967
|
+
}
|
|
968
|
+
return format(results, this._docs, {
|
|
969
|
+
includeMatches,
|
|
970
|
+
includeScore
|
|
971
|
+
});
|
|
972
|
+
}
|
|
973
|
+
_searchStringList(query, { heap, ignoreFieldNorm } = {}) {
|
|
974
|
+
const searcher = this._getSearcher(query);
|
|
975
|
+
const requireAllTokens = this.options.useTokenSearch && this.options.tokenMatch === "all";
|
|
976
|
+
const { records } = this._myIndex;
|
|
977
|
+
const results = heap ? null : [];
|
|
978
|
+
records.forEach(({ v: text, i: idx, n: norm }) => {
|
|
979
|
+
if (!isDefined(text)) return;
|
|
980
|
+
const searchResult = searcher.searchIn(text);
|
|
981
|
+
if (searchResult.isMatch) {
|
|
982
|
+
const match = {
|
|
983
|
+
score: searchResult.score,
|
|
984
|
+
value: text,
|
|
985
|
+
norm,
|
|
986
|
+
indices: searchResult.indices
|
|
987
|
+
};
|
|
988
|
+
if (requireAllTokens) {
|
|
989
|
+
match.matchedMask = searchResult.matchedMask;
|
|
990
|
+
match.matchedTerms = searchResult.matchedTerms;
|
|
991
|
+
match.termCount = searchResult.termCount;
|
|
992
|
+
}
|
|
993
|
+
const matches = [match];
|
|
994
|
+
if (!requireAllTokens || this._coversAllTokens(matches)) {
|
|
995
|
+
const result = {
|
|
996
|
+
item: text,
|
|
997
|
+
idx,
|
|
998
|
+
matches
|
|
999
|
+
};
|
|
1000
|
+
if (heap) {
|
|
1001
|
+
result.score = computeScoreSingle(result.matches, { ignoreFieldNorm });
|
|
1002
|
+
heap.insert(result);
|
|
1003
|
+
} else results.push(result);
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
});
|
|
1007
|
+
return results;
|
|
1008
|
+
}
|
|
1009
|
+
_searchLogical(query) {
|
|
1010
|
+
throw new Error(LOGICAL_SEARCH_UNAVAILABLE);
|
|
1011
|
+
}
|
|
1012
|
+
_searchObjectList(query, { heap, ignoreFieldNorm } = {}) {
|
|
1013
|
+
const searcher = this._getSearcher(query);
|
|
1014
|
+
const requireAllTokens = this.options.useTokenSearch && this.options.tokenMatch === "all";
|
|
1015
|
+
const { records } = this._myIndex;
|
|
1016
|
+
const keys = this._normalizedKeys();
|
|
1017
|
+
const results = heap ? null : [];
|
|
1018
|
+
records.forEach(({ $: item, i: idx }) => {
|
|
1019
|
+
if (!isDefined(item)) return;
|
|
1020
|
+
const matches = [];
|
|
1021
|
+
let anyKeyFailed = false;
|
|
1022
|
+
let hasInverse = false;
|
|
1023
|
+
keys.forEach((key, keyIndex) => {
|
|
1024
|
+
const keyMatches = this._findMatches({
|
|
1025
|
+
key,
|
|
1026
|
+
value: item[keyIndex],
|
|
1027
|
+
searcher
|
|
1028
|
+
});
|
|
1029
|
+
if (keyMatches.length) {
|
|
1030
|
+
matches.push(...keyMatches);
|
|
1031
|
+
if (keyMatches[0].hasInverse) hasInverse = true;
|
|
1032
|
+
} else anyKeyFailed = true;
|
|
1033
|
+
});
|
|
1034
|
+
if (hasInverse && anyKeyFailed) return;
|
|
1035
|
+
if (matches.length && (!requireAllTokens || this._coversAllTokens(matches))) {
|
|
1036
|
+
const result = {
|
|
1037
|
+
idx,
|
|
1038
|
+
item,
|
|
1039
|
+
matches
|
|
1040
|
+
};
|
|
1041
|
+
if (heap) {
|
|
1042
|
+
result.score = computeScoreSingle(result.matches, { ignoreFieldNorm });
|
|
1043
|
+
heap.insert(result);
|
|
1044
|
+
} else results.push(result);
|
|
1045
|
+
}
|
|
1046
|
+
});
|
|
1047
|
+
return results;
|
|
1048
|
+
}
|
|
1049
|
+
_findMatches({ key, value, searcher }) {
|
|
1050
|
+
if (!isDefined(value)) return [];
|
|
1051
|
+
const matches = [];
|
|
1052
|
+
if (isArray(value)) value.forEach(({ v: text, i: idx, n: norm }) => {
|
|
1053
|
+
if (!isDefined(text)) return;
|
|
1054
|
+
const searchResult = searcher.searchIn(text);
|
|
1055
|
+
if (searchResult.isMatch) {
|
|
1056
|
+
const match = {
|
|
1057
|
+
score: searchResult.score,
|
|
1058
|
+
key,
|
|
1059
|
+
value: text,
|
|
1060
|
+
idx,
|
|
1061
|
+
norm,
|
|
1062
|
+
indices: searchResult.indices,
|
|
1063
|
+
hasInverse: searchResult.hasInverse
|
|
1064
|
+
};
|
|
1065
|
+
if (searchResult.termCount !== void 0) {
|
|
1066
|
+
match.matchedMask = searchResult.matchedMask;
|
|
1067
|
+
match.matchedTerms = searchResult.matchedTerms;
|
|
1068
|
+
match.termCount = searchResult.termCount;
|
|
1069
|
+
}
|
|
1070
|
+
matches.push(match);
|
|
1071
|
+
}
|
|
1072
|
+
});
|
|
1073
|
+
else {
|
|
1074
|
+
const { v: text, n: norm } = value;
|
|
1075
|
+
const searchResult = searcher.searchIn(text);
|
|
1076
|
+
if (searchResult.isMatch) {
|
|
1077
|
+
const match = {
|
|
1078
|
+
score: searchResult.score,
|
|
1079
|
+
key,
|
|
1080
|
+
value: text,
|
|
1081
|
+
norm,
|
|
1082
|
+
indices: searchResult.indices,
|
|
1083
|
+
hasInverse: searchResult.hasInverse
|
|
1084
|
+
};
|
|
1085
|
+
if (searchResult.termCount !== void 0) {
|
|
1086
|
+
match.matchedMask = searchResult.matchedMask;
|
|
1087
|
+
match.matchedTerms = searchResult.matchedTerms;
|
|
1088
|
+
match.termCount = searchResult.termCount;
|
|
1089
|
+
}
|
|
1090
|
+
matches.push(match);
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1093
|
+
return matches;
|
|
1094
|
+
}
|
|
1095
|
+
_coversAllTokens(matches) {
|
|
1096
|
+
const termCount = matches.length ? matches[0].termCount : void 0;
|
|
1097
|
+
if (termCount === void 0) return true;
|
|
1098
|
+
if (termCount <= 31) {
|
|
1099
|
+
let coverage = 0;
|
|
1100
|
+
for (let i = 0; i < matches.length; i++) coverage |= matches[i].matchedMask || 0;
|
|
1101
|
+
return coverage === 2 ** termCount - 1;
|
|
1102
|
+
}
|
|
1103
|
+
const coverage = /* @__PURE__ */ new Set();
|
|
1104
|
+
for (let i = 0; i < matches.length; i++) {
|
|
1105
|
+
const terms = matches[i].matchedTerms;
|
|
1106
|
+
if (terms) for (const t of terms) coverage.add(t);
|
|
1107
|
+
}
|
|
1108
|
+
return coverage.size === termCount;
|
|
1109
|
+
}
|
|
1110
|
+
};
|
|
1111
|
+
Fuse.version = "7.5.0";
|
|
1112
|
+
Fuse.createIndex = createIndex;
|
|
1113
|
+
Fuse.parseIndex = parseIndex;
|
|
1114
|
+
Fuse.config = Config;
|
|
1115
|
+
Fuse.match = function(pattern, text, options) {
|
|
1116
|
+
if (options && options.useTokenSearch) throw new Error(FUSE_MATCH_TOKEN_SEARCH_UNSUPPORTED);
|
|
1117
|
+
return createSearcher(pattern, {
|
|
1118
|
+
...Config,
|
|
1119
|
+
...options
|
|
1120
|
+
}).searchIn(text);
|
|
1121
|
+
};
|
|
1122
|
+
Fuse.parseQuery = parse;
|
|
1123
|
+
Fuse.use = function(...plugins) {
|
|
1124
|
+
plugins.forEach((plugin) => register(plugin));
|
|
1125
|
+
};
|
|
1126
|
+
var entry_default = Fuse;
|
|
1127
|
+
// src/description.js
|
|
1128
|
+
/**
|
|
1129
|
+
* Inline references in description texts.
|
|
1130
|
+
*
|
|
1131
|
+
* Syntax: `#[Key]`, `#[Key|label]`, `#[technique:Key]`, `#[term:key]`.
|
|
1132
|
+
*
|
|
1133
|
+
* Without an explicit kind the casing of the key decides: technique names
|
|
1134
|
+
* start with an upper-case letter ("Ieochagi"), term keys are lower-case
|
|
1135
|
+
* ("palmok"). The label is the displayed text and defaults to the key.
|
|
1136
|
+
*/
|
|
1137
|
+
/** Matches one reference; groups: kind, key, label. Global — reset `lastIndex` or use `matchAll`. */
|
|
1138
|
+
var REF_PATTERN = /#\[(?:(technique|term):)?([^\]|]+?)(?:\|([^\]]+))?\]/g;
|
|
1139
|
+
/**
|
|
1140
|
+
* Replaces every reference by its label, e.g. for plain-text output or search.
|
|
1141
|
+
* @param {string} text
|
|
1142
|
+
* @returns {string}
|
|
1143
|
+
*/
|
|
1144
|
+
function stripRefs(text) {
|
|
1145
|
+
return text.replace(REF_PATTERN, (_, _kind, key, label) => label ?? key.trim());
|
|
1146
|
+
}
|
|
1147
|
+
// src/search.js
|
|
1148
|
+
/**
|
|
1149
|
+
* The fuzzy search over techniques and terms, in one place for the library
|
|
1150
|
+
* (`TaekwondoDatabase#searchTechniques`, `#searchTerms`) and for apps that
|
|
1151
|
+
* search a compact index of their own, e.g. in the browser.
|
|
1152
|
+
*
|
|
1153
|
+
* Works on loaded entries as well as on flat index entries: `translation` and
|
|
1154
|
+
* `description` may be a localized object (`{ de, en }`) or already a string
|
|
1155
|
+
* in one language.
|
|
1156
|
+
*
|
|
1157
|
+
* Plain JavaScript without Node APIs, so it also runs in the browser; the
|
|
1158
|
+
* package ships it bundled with Fuse.js as `search.browser.js`.
|
|
1159
|
+
*/
|
|
1160
|
+
var THRESHOLD = .3;
|
|
1161
|
+
function localized(value, lang) {
|
|
1162
|
+
if (typeof value === "string") return value;
|
|
1163
|
+
return value?.[lang] ?? "";
|
|
1164
|
+
}
|
|
1165
|
+
/**
|
|
1166
|
+
* Searches techniques by name, `supplementaryName` and translation.
|
|
1167
|
+
* Returns a function from a query to the matching items, best first.
|
|
1168
|
+
*/
|
|
1169
|
+
function createTechniqueSearch(items, lang) {
|
|
1170
|
+
const fuse = new entry_default(items, {
|
|
1171
|
+
keys: [
|
|
1172
|
+
"name",
|
|
1173
|
+
"supplementaryName",
|
|
1174
|
+
{
|
|
1175
|
+
getFn: (item) => localized(item.translation, lang),
|
|
1176
|
+
name: "translation"
|
|
1177
|
+
}
|
|
1178
|
+
],
|
|
1179
|
+
threshold: THRESHOLD
|
|
1180
|
+
});
|
|
1181
|
+
return (query) => fuse.search(query).map((result) => result.item);
|
|
1182
|
+
}
|
|
1183
|
+
/**
|
|
1184
|
+
* Searches terms by name and description, without reference markup.
|
|
1185
|
+
* Returns a function from a query to the matching items, best first.
|
|
1186
|
+
*/
|
|
1187
|
+
function createTermSearch(items, lang) {
|
|
1188
|
+
const fuse = new entry_default(items, {
|
|
1189
|
+
keys: ["name", {
|
|
1190
|
+
getFn: (item) => stripRefs(localized(item.description, lang)),
|
|
1191
|
+
name: "description"
|
|
1192
|
+
}],
|
|
1193
|
+
threshold: THRESHOLD
|
|
1194
|
+
});
|
|
1195
|
+
return (query) => fuse.search(query).map((result) => result.item);
|
|
1196
|
+
}
|
|
1197
|
+
export { createTechniqueSearch, createTermSearch };
|