@thyn-ai/fuse-mojo-core 0.1.7
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/NOTICE +16 -0
- package/index.cjs +147 -0
- package/index.d.ts +87 -0
- package/index.mjs +7 -0
- package/package.json +48 -0
- package/src/engine.cjs +314 -0
- package/src/native.cjs +374 -0
- package/src/options.cjs +242 -0
- package/vendor/fuse.basic.cjs +1342 -0
|
@@ -0,0 +1,1342 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fuse.js v7.1.0 - Lightweight fuzzy-search (http://fusejs.io)
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2025 Kiro Risk (http://kiro.me)
|
|
5
|
+
* All Rights Reserved. Apache Software License 2.0
|
|
6
|
+
*
|
|
7
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
'use strict';
|
|
11
|
+
|
|
12
|
+
function ownKeys(object, enumerableOnly) {
|
|
13
|
+
var keys = Object.keys(object);
|
|
14
|
+
if (Object.getOwnPropertySymbols) {
|
|
15
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
16
|
+
enumerableOnly && (symbols = symbols.filter(function (sym) {
|
|
17
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
18
|
+
})), keys.push.apply(keys, symbols);
|
|
19
|
+
}
|
|
20
|
+
return keys;
|
|
21
|
+
}
|
|
22
|
+
function _objectSpread2(target) {
|
|
23
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
24
|
+
var source = null != arguments[i] ? arguments[i] : {};
|
|
25
|
+
i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
|
|
26
|
+
_defineProperty(target, key, source[key]);
|
|
27
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
|
|
28
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
return target;
|
|
32
|
+
}
|
|
33
|
+
function _typeof(obj) {
|
|
34
|
+
"@babel/helpers - typeof";
|
|
35
|
+
|
|
36
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
|
|
37
|
+
return typeof obj;
|
|
38
|
+
} : function (obj) {
|
|
39
|
+
return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
|
40
|
+
}, _typeof(obj);
|
|
41
|
+
}
|
|
42
|
+
function _classCallCheck(instance, Constructor) {
|
|
43
|
+
if (!(instance instanceof Constructor)) {
|
|
44
|
+
throw new TypeError("Cannot call a class as a function");
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function _defineProperties(target, props) {
|
|
48
|
+
for (var i = 0; i < props.length; i++) {
|
|
49
|
+
var descriptor = props[i];
|
|
50
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
51
|
+
descriptor.configurable = true;
|
|
52
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
53
|
+
Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function _createClass(Constructor, protoProps, staticProps) {
|
|
57
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
58
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
59
|
+
Object.defineProperty(Constructor, "prototype", {
|
|
60
|
+
writable: false
|
|
61
|
+
});
|
|
62
|
+
return Constructor;
|
|
63
|
+
}
|
|
64
|
+
function _defineProperty(obj, key, value) {
|
|
65
|
+
key = _toPropertyKey(key);
|
|
66
|
+
if (key in obj) {
|
|
67
|
+
Object.defineProperty(obj, key, {
|
|
68
|
+
value: value,
|
|
69
|
+
enumerable: true,
|
|
70
|
+
configurable: true,
|
|
71
|
+
writable: true
|
|
72
|
+
});
|
|
73
|
+
} else {
|
|
74
|
+
obj[key] = value;
|
|
75
|
+
}
|
|
76
|
+
return obj;
|
|
77
|
+
}
|
|
78
|
+
function _toConsumableArray(arr) {
|
|
79
|
+
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
|
|
80
|
+
}
|
|
81
|
+
function _arrayWithoutHoles(arr) {
|
|
82
|
+
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
|
|
83
|
+
}
|
|
84
|
+
function _iterableToArray(iter) {
|
|
85
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
86
|
+
}
|
|
87
|
+
function _unsupportedIterableToArray(o, minLen) {
|
|
88
|
+
if (!o) return;
|
|
89
|
+
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
90
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
91
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
92
|
+
if (n === "Map" || n === "Set") return Array.from(o);
|
|
93
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
94
|
+
}
|
|
95
|
+
function _arrayLikeToArray(arr, len) {
|
|
96
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
97
|
+
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
98
|
+
return arr2;
|
|
99
|
+
}
|
|
100
|
+
function _nonIterableSpread() {
|
|
101
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
102
|
+
}
|
|
103
|
+
function _toPrimitive(input, hint) {
|
|
104
|
+
if (typeof input !== "object" || input === null) return input;
|
|
105
|
+
var prim = input[Symbol.toPrimitive];
|
|
106
|
+
if (prim !== undefined) {
|
|
107
|
+
var res = prim.call(input, hint || "default");
|
|
108
|
+
if (typeof res !== "object") return res;
|
|
109
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
110
|
+
}
|
|
111
|
+
return (hint === "string" ? String : Number)(input);
|
|
112
|
+
}
|
|
113
|
+
function _toPropertyKey(arg) {
|
|
114
|
+
var key = _toPrimitive(arg, "string");
|
|
115
|
+
return typeof key === "symbol" ? key : String(key);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function isArray(value) {
|
|
119
|
+
return !Array.isArray ? getTag(value) === '[object Array]' : Array.isArray(value);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Adapted from: https://github.com/lodash/lodash/blob/master/.internal/baseToString.js
|
|
123
|
+
var INFINITY = 1 / 0;
|
|
124
|
+
function baseToString(value) {
|
|
125
|
+
// Exit early for strings to avoid a performance hit in some environments.
|
|
126
|
+
if (typeof value == 'string') {
|
|
127
|
+
return value;
|
|
128
|
+
}
|
|
129
|
+
var result = value + '';
|
|
130
|
+
return result == '0' && 1 / value == -INFINITY ? '-0' : result;
|
|
131
|
+
}
|
|
132
|
+
function toString(value) {
|
|
133
|
+
return value == null ? '' : baseToString(value);
|
|
134
|
+
}
|
|
135
|
+
function isString(value) {
|
|
136
|
+
return typeof value === 'string';
|
|
137
|
+
}
|
|
138
|
+
function isNumber(value) {
|
|
139
|
+
return typeof value === 'number';
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// Adapted from: https://github.com/lodash/lodash/blob/master/isBoolean.js
|
|
143
|
+
function isBoolean(value) {
|
|
144
|
+
return value === true || value === false || isObjectLike(value) && getTag(value) == '[object Boolean]';
|
|
145
|
+
}
|
|
146
|
+
function isObject(value) {
|
|
147
|
+
return _typeof(value) === 'object';
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// Checks if `value` is object-like.
|
|
151
|
+
function isObjectLike(value) {
|
|
152
|
+
return isObject(value) && value !== null;
|
|
153
|
+
}
|
|
154
|
+
function isDefined(value) {
|
|
155
|
+
return value !== undefined && value !== null;
|
|
156
|
+
}
|
|
157
|
+
function isBlank(value) {
|
|
158
|
+
return !value.trim().length;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// Gets the `toStringTag` of `value`.
|
|
162
|
+
// Adapted from: https://github.com/lodash/lodash/blob/master/.internal/getTag.js
|
|
163
|
+
function getTag(value) {
|
|
164
|
+
return value == null ? value === undefined ? '[object Undefined]' : '[object Null]' : Object.prototype.toString.call(value);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
var EXTENDED_SEARCH_UNAVAILABLE = 'Extended search is not available';
|
|
168
|
+
var LOGICAL_SEARCH_UNAVAILABLE = 'Logical search is not available';
|
|
169
|
+
var INCORRECT_INDEX_TYPE = "Incorrect 'index' type";
|
|
170
|
+
var LOGICAL_SEARCH_INVALID_QUERY_FOR_KEY = function LOGICAL_SEARCH_INVALID_QUERY_FOR_KEY(key) {
|
|
171
|
+
return "Invalid value for key ".concat(key);
|
|
172
|
+
};
|
|
173
|
+
var PATTERN_LENGTH_TOO_LARGE = function PATTERN_LENGTH_TOO_LARGE(max) {
|
|
174
|
+
return "Pattern length exceeds max of ".concat(max, ".");
|
|
175
|
+
};
|
|
176
|
+
var MISSING_KEY_PROPERTY = function MISSING_KEY_PROPERTY(name) {
|
|
177
|
+
return "Missing ".concat(name, " property in key");
|
|
178
|
+
};
|
|
179
|
+
var INVALID_KEY_WEIGHT_VALUE = function INVALID_KEY_WEIGHT_VALUE(key) {
|
|
180
|
+
return "Property 'weight' in key '".concat(key, "' must be a positive integer");
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
var hasOwn = Object.prototype.hasOwnProperty;
|
|
184
|
+
var KeyStore = /*#__PURE__*/function () {
|
|
185
|
+
function KeyStore(keys) {
|
|
186
|
+
var _this = this;
|
|
187
|
+
_classCallCheck(this, KeyStore);
|
|
188
|
+
this._keys = [];
|
|
189
|
+
this._keyMap = {};
|
|
190
|
+
var totalWeight = 0;
|
|
191
|
+
keys.forEach(function (key) {
|
|
192
|
+
var obj = createKey(key);
|
|
193
|
+
_this._keys.push(obj);
|
|
194
|
+
_this._keyMap[obj.id] = obj;
|
|
195
|
+
totalWeight += obj.weight;
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
// Normalize weights so that their sum is equal to 1
|
|
199
|
+
this._keys.forEach(function (key) {
|
|
200
|
+
key.weight /= totalWeight;
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
_createClass(KeyStore, [{
|
|
204
|
+
key: "get",
|
|
205
|
+
value: function get(keyId) {
|
|
206
|
+
return this._keyMap[keyId];
|
|
207
|
+
}
|
|
208
|
+
}, {
|
|
209
|
+
key: "keys",
|
|
210
|
+
value: function keys() {
|
|
211
|
+
return this._keys;
|
|
212
|
+
}
|
|
213
|
+
}, {
|
|
214
|
+
key: "toJSON",
|
|
215
|
+
value: function toJSON() {
|
|
216
|
+
return JSON.stringify(this._keys);
|
|
217
|
+
}
|
|
218
|
+
}]);
|
|
219
|
+
return KeyStore;
|
|
220
|
+
}();
|
|
221
|
+
function createKey(key) {
|
|
222
|
+
var path = null;
|
|
223
|
+
var id = null;
|
|
224
|
+
var src = null;
|
|
225
|
+
var weight = 1;
|
|
226
|
+
var getFn = null;
|
|
227
|
+
if (isString(key) || isArray(key)) {
|
|
228
|
+
src = key;
|
|
229
|
+
path = createKeyPath(key);
|
|
230
|
+
id = createKeyId(key);
|
|
231
|
+
} else {
|
|
232
|
+
if (!hasOwn.call(key, 'name')) {
|
|
233
|
+
throw new Error(MISSING_KEY_PROPERTY('name'));
|
|
234
|
+
}
|
|
235
|
+
var name = key.name;
|
|
236
|
+
src = name;
|
|
237
|
+
if (hasOwn.call(key, 'weight')) {
|
|
238
|
+
weight = key.weight;
|
|
239
|
+
if (weight <= 0) {
|
|
240
|
+
throw new Error(INVALID_KEY_WEIGHT_VALUE(name));
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
path = createKeyPath(name);
|
|
244
|
+
id = createKeyId(name);
|
|
245
|
+
getFn = key.getFn;
|
|
246
|
+
}
|
|
247
|
+
return {
|
|
248
|
+
path: path,
|
|
249
|
+
id: id,
|
|
250
|
+
weight: weight,
|
|
251
|
+
src: src,
|
|
252
|
+
getFn: getFn
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
function createKeyPath(key) {
|
|
256
|
+
return isArray(key) ? key : key.split('.');
|
|
257
|
+
}
|
|
258
|
+
function createKeyId(key) {
|
|
259
|
+
return isArray(key) ? key.join('.') : key;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
function get(obj, path) {
|
|
263
|
+
var list = [];
|
|
264
|
+
var arr = false;
|
|
265
|
+
var deepGet = function deepGet(obj, path, index) {
|
|
266
|
+
if (!isDefined(obj)) {
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
if (!path[index]) {
|
|
270
|
+
// If there's no path left, we've arrived at the object we care about.
|
|
271
|
+
list.push(obj);
|
|
272
|
+
} else {
|
|
273
|
+
var key = path[index];
|
|
274
|
+
var value = obj[key];
|
|
275
|
+
if (!isDefined(value)) {
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
// If we're at the last value in the path, and if it's a string/number/bool,
|
|
280
|
+
// add it to the list
|
|
281
|
+
if (index === path.length - 1 && (isString(value) || isNumber(value) || isBoolean(value))) {
|
|
282
|
+
list.push(toString(value));
|
|
283
|
+
} else if (isArray(value)) {
|
|
284
|
+
arr = true;
|
|
285
|
+
// Search each item in the array.
|
|
286
|
+
for (var i = 0, len = value.length; i < len; i += 1) {
|
|
287
|
+
deepGet(value[i], path, index + 1);
|
|
288
|
+
}
|
|
289
|
+
} else if (path.length) {
|
|
290
|
+
// An object. Recurse further.
|
|
291
|
+
deepGet(value, path, index + 1);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
// Backwards compatibility (since path used to be a string)
|
|
297
|
+
deepGet(obj, isString(path) ? path.split('.') : path, 0);
|
|
298
|
+
return arr ? list : list[0];
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
var MatchOptions = {
|
|
302
|
+
// Whether the matches should be included in the result set. When `true`, each record in the result
|
|
303
|
+
// set will include the indices of the matched characters.
|
|
304
|
+
// These can consequently be used for highlighting purposes.
|
|
305
|
+
includeMatches: false,
|
|
306
|
+
// When `true`, the matching function will continue to the end of a search pattern even if
|
|
307
|
+
// a perfect match has already been located in the string.
|
|
308
|
+
findAllMatches: false,
|
|
309
|
+
// Minimum number of characters that must be matched before a result is considered a match
|
|
310
|
+
minMatchCharLength: 1
|
|
311
|
+
};
|
|
312
|
+
var BasicOptions = {
|
|
313
|
+
// When `true`, the algorithm continues searching to the end of the input even if a perfect
|
|
314
|
+
// match is found before the end of the same input.
|
|
315
|
+
isCaseSensitive: false,
|
|
316
|
+
// When `true`, the algorithm will ignore diacritics (accents) in comparisons
|
|
317
|
+
ignoreDiacritics: false,
|
|
318
|
+
// When true, the matching function will continue to the end of a search pattern even if
|
|
319
|
+
includeScore: false,
|
|
320
|
+
// List of properties that will be searched. This also supports nested properties.
|
|
321
|
+
keys: [],
|
|
322
|
+
// Whether to sort the result list, by score
|
|
323
|
+
shouldSort: true,
|
|
324
|
+
// Default sort function: sort by ascending score, ascending index
|
|
325
|
+
sortFn: function sortFn(a, b) {
|
|
326
|
+
return a.score === b.score ? a.idx < b.idx ? -1 : 1 : a.score < b.score ? -1 : 1;
|
|
327
|
+
}
|
|
328
|
+
};
|
|
329
|
+
var FuzzyOptions = {
|
|
330
|
+
// Approximately where in the text is the pattern expected to be found?
|
|
331
|
+
location: 0,
|
|
332
|
+
// At what point does the match algorithm give up. A threshold of '0.0' requires a perfect match
|
|
333
|
+
// (of both letters and location), a threshold of '1.0' would match anything.
|
|
334
|
+
threshold: 0.6,
|
|
335
|
+
// Determines how close the match must be to the fuzzy location (specified above).
|
|
336
|
+
// An exact letter match which is 'distance' characters away from the fuzzy location
|
|
337
|
+
// would score as a complete mismatch. A distance of '0' requires the match be at
|
|
338
|
+
// the exact location specified, a threshold of '1000' would require a perfect match
|
|
339
|
+
// to be within 800 characters of the fuzzy location to be found using a 0.8 threshold.
|
|
340
|
+
distance: 100
|
|
341
|
+
};
|
|
342
|
+
var AdvancedOptions = {
|
|
343
|
+
// When `true`, it enables the use of unix-like search commands
|
|
344
|
+
useExtendedSearch: false,
|
|
345
|
+
// The get function to use when fetching an object's properties.
|
|
346
|
+
// The default will search nested paths *ie foo.bar.baz*
|
|
347
|
+
getFn: get,
|
|
348
|
+
// When `true`, search will ignore `location` and `distance`, so it won't matter
|
|
349
|
+
// where in the string the pattern appears.
|
|
350
|
+
// More info: https://fusejs.io/concepts/scoring-theory.html#fuzziness-score
|
|
351
|
+
ignoreLocation: false,
|
|
352
|
+
// When `true`, the calculation for the relevance score (used for sorting) will
|
|
353
|
+
// ignore the field-length norm.
|
|
354
|
+
// More info: https://fusejs.io/concepts/scoring-theory.html#field-length-norm
|
|
355
|
+
ignoreFieldNorm: false,
|
|
356
|
+
// The weight to determine how much field length norm effects scoring.
|
|
357
|
+
fieldNormWeight: 1
|
|
358
|
+
};
|
|
359
|
+
var Config = _objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({}, BasicOptions), MatchOptions), FuzzyOptions), AdvancedOptions);
|
|
360
|
+
|
|
361
|
+
var SPACE = /[^ ]+/g;
|
|
362
|
+
|
|
363
|
+
// Field-length norm: the shorter the field, the higher the weight.
|
|
364
|
+
// Set to 3 decimals to reduce index size.
|
|
365
|
+
function norm() {
|
|
366
|
+
var weight = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
|
|
367
|
+
var mantissa = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 3;
|
|
368
|
+
var cache = new Map();
|
|
369
|
+
var m = Math.pow(10, mantissa);
|
|
370
|
+
return {
|
|
371
|
+
get: function get(value) {
|
|
372
|
+
var numTokens = value.match(SPACE).length;
|
|
373
|
+
if (cache.has(numTokens)) {
|
|
374
|
+
return cache.get(numTokens);
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
// Default function is 1/sqrt(x), weight makes that variable
|
|
378
|
+
var norm = 1 / Math.pow(numTokens, 0.5 * weight);
|
|
379
|
+
|
|
380
|
+
// In place of `toFixed(mantissa)`, for faster computation
|
|
381
|
+
var n = parseFloat(Math.round(norm * m) / m);
|
|
382
|
+
cache.set(numTokens, n);
|
|
383
|
+
return n;
|
|
384
|
+
},
|
|
385
|
+
clear: function clear() {
|
|
386
|
+
cache.clear();
|
|
387
|
+
}
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
var FuseIndex = /*#__PURE__*/function () {
|
|
392
|
+
function FuseIndex() {
|
|
393
|
+
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
394
|
+
_ref$getFn = _ref.getFn,
|
|
395
|
+
getFn = _ref$getFn === void 0 ? Config.getFn : _ref$getFn,
|
|
396
|
+
_ref$fieldNormWeight = _ref.fieldNormWeight,
|
|
397
|
+
fieldNormWeight = _ref$fieldNormWeight === void 0 ? Config.fieldNormWeight : _ref$fieldNormWeight;
|
|
398
|
+
_classCallCheck(this, FuseIndex);
|
|
399
|
+
this.norm = norm(fieldNormWeight, 3);
|
|
400
|
+
this.getFn = getFn;
|
|
401
|
+
this.isCreated = false;
|
|
402
|
+
this.setIndexRecords();
|
|
403
|
+
}
|
|
404
|
+
_createClass(FuseIndex, [{
|
|
405
|
+
key: "setSources",
|
|
406
|
+
value: function setSources() {
|
|
407
|
+
var docs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
408
|
+
this.docs = docs;
|
|
409
|
+
}
|
|
410
|
+
}, {
|
|
411
|
+
key: "setIndexRecords",
|
|
412
|
+
value: function setIndexRecords() {
|
|
413
|
+
var records = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
414
|
+
this.records = records;
|
|
415
|
+
}
|
|
416
|
+
}, {
|
|
417
|
+
key: "setKeys",
|
|
418
|
+
value: function setKeys() {
|
|
419
|
+
var _this = this;
|
|
420
|
+
var keys = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
421
|
+
this.keys = keys;
|
|
422
|
+
this._keysMap = {};
|
|
423
|
+
keys.forEach(function (key, idx) {
|
|
424
|
+
_this._keysMap[key.id] = idx;
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
}, {
|
|
428
|
+
key: "create",
|
|
429
|
+
value: function create() {
|
|
430
|
+
var _this2 = this;
|
|
431
|
+
if (this.isCreated || !this.docs.length) {
|
|
432
|
+
return;
|
|
433
|
+
}
|
|
434
|
+
this.isCreated = true;
|
|
435
|
+
|
|
436
|
+
// List is Array<String>
|
|
437
|
+
if (isString(this.docs[0])) {
|
|
438
|
+
this.docs.forEach(function (doc, docIndex) {
|
|
439
|
+
_this2._addString(doc, docIndex);
|
|
440
|
+
});
|
|
441
|
+
} else {
|
|
442
|
+
// List is Array<Object>
|
|
443
|
+
this.docs.forEach(function (doc, docIndex) {
|
|
444
|
+
_this2._addObject(doc, docIndex);
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
this.norm.clear();
|
|
448
|
+
}
|
|
449
|
+
// Adds a doc to the end of the index
|
|
450
|
+
}, {
|
|
451
|
+
key: "add",
|
|
452
|
+
value: function add(doc) {
|
|
453
|
+
var idx = this.size();
|
|
454
|
+
if (isString(doc)) {
|
|
455
|
+
this._addString(doc, idx);
|
|
456
|
+
} else {
|
|
457
|
+
this._addObject(doc, idx);
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
// Removes the doc at the specified index of the index
|
|
461
|
+
}, {
|
|
462
|
+
key: "removeAt",
|
|
463
|
+
value: function removeAt(idx) {
|
|
464
|
+
this.records.splice(idx, 1);
|
|
465
|
+
|
|
466
|
+
// Change ref index of every subsquent doc
|
|
467
|
+
for (var i = idx, len = this.size(); i < len; i += 1) {
|
|
468
|
+
this.records[i].i -= 1;
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
}, {
|
|
472
|
+
key: "getValueForItemAtKeyId",
|
|
473
|
+
value: function getValueForItemAtKeyId(item, keyId) {
|
|
474
|
+
return item[this._keysMap[keyId]];
|
|
475
|
+
}
|
|
476
|
+
}, {
|
|
477
|
+
key: "size",
|
|
478
|
+
value: function size() {
|
|
479
|
+
return this.records.length;
|
|
480
|
+
}
|
|
481
|
+
}, {
|
|
482
|
+
key: "_addString",
|
|
483
|
+
value: function _addString(doc, docIndex) {
|
|
484
|
+
if (!isDefined(doc) || isBlank(doc)) {
|
|
485
|
+
return;
|
|
486
|
+
}
|
|
487
|
+
var record = {
|
|
488
|
+
v: doc,
|
|
489
|
+
i: docIndex,
|
|
490
|
+
n: this.norm.get(doc)
|
|
491
|
+
};
|
|
492
|
+
this.records.push(record);
|
|
493
|
+
}
|
|
494
|
+
}, {
|
|
495
|
+
key: "_addObject",
|
|
496
|
+
value: function _addObject(doc, docIndex) {
|
|
497
|
+
var _this3 = this;
|
|
498
|
+
var record = {
|
|
499
|
+
i: docIndex,
|
|
500
|
+
$: {}
|
|
501
|
+
};
|
|
502
|
+
|
|
503
|
+
// Iterate over every key (i.e, path), and fetch the value at that key
|
|
504
|
+
this.keys.forEach(function (key, keyIndex) {
|
|
505
|
+
var value = key.getFn ? key.getFn(doc) : _this3.getFn(doc, key.path);
|
|
506
|
+
if (!isDefined(value)) {
|
|
507
|
+
return;
|
|
508
|
+
}
|
|
509
|
+
if (isArray(value)) {
|
|
510
|
+
var subRecords = [];
|
|
511
|
+
var stack = [{
|
|
512
|
+
nestedArrIndex: -1,
|
|
513
|
+
value: value
|
|
514
|
+
}];
|
|
515
|
+
while (stack.length) {
|
|
516
|
+
var _stack$pop = stack.pop(),
|
|
517
|
+
nestedArrIndex = _stack$pop.nestedArrIndex,
|
|
518
|
+
_value = _stack$pop.value;
|
|
519
|
+
if (!isDefined(_value)) {
|
|
520
|
+
continue;
|
|
521
|
+
}
|
|
522
|
+
if (isString(_value) && !isBlank(_value)) {
|
|
523
|
+
var subRecord = {
|
|
524
|
+
v: _value,
|
|
525
|
+
i: nestedArrIndex,
|
|
526
|
+
n: _this3.norm.get(_value)
|
|
527
|
+
};
|
|
528
|
+
subRecords.push(subRecord);
|
|
529
|
+
} else if (isArray(_value)) {
|
|
530
|
+
_value.forEach(function (item, k) {
|
|
531
|
+
stack.push({
|
|
532
|
+
nestedArrIndex: k,
|
|
533
|
+
value: item
|
|
534
|
+
});
|
|
535
|
+
});
|
|
536
|
+
} else ;
|
|
537
|
+
}
|
|
538
|
+
record.$[keyIndex] = subRecords;
|
|
539
|
+
} else if (isString(value) && !isBlank(value)) {
|
|
540
|
+
var _subRecord = {
|
|
541
|
+
v: value,
|
|
542
|
+
n: _this3.norm.get(value)
|
|
543
|
+
};
|
|
544
|
+
record.$[keyIndex] = _subRecord;
|
|
545
|
+
}
|
|
546
|
+
});
|
|
547
|
+
this.records.push(record);
|
|
548
|
+
}
|
|
549
|
+
}, {
|
|
550
|
+
key: "toJSON",
|
|
551
|
+
value: function toJSON() {
|
|
552
|
+
return {
|
|
553
|
+
keys: this.keys,
|
|
554
|
+
records: this.records
|
|
555
|
+
};
|
|
556
|
+
}
|
|
557
|
+
}]);
|
|
558
|
+
return FuseIndex;
|
|
559
|
+
}();
|
|
560
|
+
function createIndex(keys, docs) {
|
|
561
|
+
var _ref2 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
|
|
562
|
+
_ref2$getFn = _ref2.getFn,
|
|
563
|
+
getFn = _ref2$getFn === void 0 ? Config.getFn : _ref2$getFn,
|
|
564
|
+
_ref2$fieldNormWeight = _ref2.fieldNormWeight,
|
|
565
|
+
fieldNormWeight = _ref2$fieldNormWeight === void 0 ? Config.fieldNormWeight : _ref2$fieldNormWeight;
|
|
566
|
+
var myIndex = new FuseIndex({
|
|
567
|
+
getFn: getFn,
|
|
568
|
+
fieldNormWeight: fieldNormWeight
|
|
569
|
+
});
|
|
570
|
+
myIndex.setKeys(keys.map(createKey));
|
|
571
|
+
myIndex.setSources(docs);
|
|
572
|
+
myIndex.create();
|
|
573
|
+
return myIndex;
|
|
574
|
+
}
|
|
575
|
+
function parseIndex(data) {
|
|
576
|
+
var _ref3 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
577
|
+
_ref3$getFn = _ref3.getFn,
|
|
578
|
+
getFn = _ref3$getFn === void 0 ? Config.getFn : _ref3$getFn,
|
|
579
|
+
_ref3$fieldNormWeight = _ref3.fieldNormWeight,
|
|
580
|
+
fieldNormWeight = _ref3$fieldNormWeight === void 0 ? Config.fieldNormWeight : _ref3$fieldNormWeight;
|
|
581
|
+
var keys = data.keys,
|
|
582
|
+
records = data.records;
|
|
583
|
+
var myIndex = new FuseIndex({
|
|
584
|
+
getFn: getFn,
|
|
585
|
+
fieldNormWeight: fieldNormWeight
|
|
586
|
+
});
|
|
587
|
+
myIndex.setKeys(keys);
|
|
588
|
+
myIndex.setIndexRecords(records);
|
|
589
|
+
return myIndex;
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
function computeScore$1(pattern) {
|
|
593
|
+
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
594
|
+
_ref$errors = _ref.errors,
|
|
595
|
+
errors = _ref$errors === void 0 ? 0 : _ref$errors,
|
|
596
|
+
_ref$currentLocation = _ref.currentLocation,
|
|
597
|
+
currentLocation = _ref$currentLocation === void 0 ? 0 : _ref$currentLocation,
|
|
598
|
+
_ref$expectedLocation = _ref.expectedLocation,
|
|
599
|
+
expectedLocation = _ref$expectedLocation === void 0 ? 0 : _ref$expectedLocation,
|
|
600
|
+
_ref$distance = _ref.distance,
|
|
601
|
+
distance = _ref$distance === void 0 ? Config.distance : _ref$distance,
|
|
602
|
+
_ref$ignoreLocation = _ref.ignoreLocation,
|
|
603
|
+
ignoreLocation = _ref$ignoreLocation === void 0 ? Config.ignoreLocation : _ref$ignoreLocation;
|
|
604
|
+
var accuracy = errors / pattern.length;
|
|
605
|
+
if (ignoreLocation) {
|
|
606
|
+
return accuracy;
|
|
607
|
+
}
|
|
608
|
+
var proximity = Math.abs(expectedLocation - currentLocation);
|
|
609
|
+
if (!distance) {
|
|
610
|
+
// Dodge divide by zero error.
|
|
611
|
+
return proximity ? 1.0 : accuracy;
|
|
612
|
+
}
|
|
613
|
+
return accuracy + proximity / distance;
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
function convertMaskToIndices() {
|
|
617
|
+
var matchmask = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
618
|
+
var minMatchCharLength = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Config.minMatchCharLength;
|
|
619
|
+
var indices = [];
|
|
620
|
+
var start = -1;
|
|
621
|
+
var end = -1;
|
|
622
|
+
var i = 0;
|
|
623
|
+
for (var len = matchmask.length; i < len; i += 1) {
|
|
624
|
+
var match = matchmask[i];
|
|
625
|
+
if (match && start === -1) {
|
|
626
|
+
start = i;
|
|
627
|
+
} else if (!match && start !== -1) {
|
|
628
|
+
end = i - 1;
|
|
629
|
+
if (end - start + 1 >= minMatchCharLength) {
|
|
630
|
+
indices.push([start, end]);
|
|
631
|
+
}
|
|
632
|
+
start = -1;
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
// (i-1 - start) + 1 => i - start
|
|
637
|
+
if (matchmask[i - 1] && i - start >= minMatchCharLength) {
|
|
638
|
+
indices.push([start, i - 1]);
|
|
639
|
+
}
|
|
640
|
+
return indices;
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
// Machine word size
|
|
644
|
+
var MAX_BITS = 32;
|
|
645
|
+
|
|
646
|
+
function search(text, pattern, patternAlphabet) {
|
|
647
|
+
var _ref = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {},
|
|
648
|
+
_ref$location = _ref.location,
|
|
649
|
+
location = _ref$location === void 0 ? Config.location : _ref$location,
|
|
650
|
+
_ref$distance = _ref.distance,
|
|
651
|
+
distance = _ref$distance === void 0 ? Config.distance : _ref$distance,
|
|
652
|
+
_ref$threshold = _ref.threshold,
|
|
653
|
+
threshold = _ref$threshold === void 0 ? Config.threshold : _ref$threshold,
|
|
654
|
+
_ref$findAllMatches = _ref.findAllMatches,
|
|
655
|
+
findAllMatches = _ref$findAllMatches === void 0 ? Config.findAllMatches : _ref$findAllMatches,
|
|
656
|
+
_ref$minMatchCharLeng = _ref.minMatchCharLength,
|
|
657
|
+
minMatchCharLength = _ref$minMatchCharLeng === void 0 ? Config.minMatchCharLength : _ref$minMatchCharLeng,
|
|
658
|
+
_ref$includeMatches = _ref.includeMatches,
|
|
659
|
+
includeMatches = _ref$includeMatches === void 0 ? Config.includeMatches : _ref$includeMatches,
|
|
660
|
+
_ref$ignoreLocation = _ref.ignoreLocation,
|
|
661
|
+
ignoreLocation = _ref$ignoreLocation === void 0 ? Config.ignoreLocation : _ref$ignoreLocation;
|
|
662
|
+
if (pattern.length > MAX_BITS) {
|
|
663
|
+
throw new Error(PATTERN_LENGTH_TOO_LARGE(MAX_BITS));
|
|
664
|
+
}
|
|
665
|
+
var patternLen = pattern.length;
|
|
666
|
+
// Set starting location at beginning text and initialize the alphabet.
|
|
667
|
+
var textLen = text.length;
|
|
668
|
+
// Handle the case when location > text.length
|
|
669
|
+
var expectedLocation = Math.max(0, Math.min(location, textLen));
|
|
670
|
+
// Highest score beyond which we give up.
|
|
671
|
+
var currentThreshold = threshold;
|
|
672
|
+
// Is there a nearby exact match? (speedup)
|
|
673
|
+
var bestLocation = expectedLocation;
|
|
674
|
+
|
|
675
|
+
// Performance: only computer matches when the minMatchCharLength > 1
|
|
676
|
+
// OR if `includeMatches` is true.
|
|
677
|
+
var computeMatches = minMatchCharLength > 1 || includeMatches;
|
|
678
|
+
// A mask of the matches, used for building the indices
|
|
679
|
+
var matchMask = computeMatches ? Array(textLen) : [];
|
|
680
|
+
var index;
|
|
681
|
+
|
|
682
|
+
// Get all exact matches, here for speed up
|
|
683
|
+
while ((index = text.indexOf(pattern, bestLocation)) > -1) {
|
|
684
|
+
var score = computeScore$1(pattern, {
|
|
685
|
+
currentLocation: index,
|
|
686
|
+
expectedLocation: expectedLocation,
|
|
687
|
+
distance: distance,
|
|
688
|
+
ignoreLocation: ignoreLocation
|
|
689
|
+
});
|
|
690
|
+
currentThreshold = Math.min(score, currentThreshold);
|
|
691
|
+
bestLocation = index + patternLen;
|
|
692
|
+
if (computeMatches) {
|
|
693
|
+
var i = 0;
|
|
694
|
+
while (i < patternLen) {
|
|
695
|
+
matchMask[index + i] = 1;
|
|
696
|
+
i += 1;
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
// Reset the best location
|
|
702
|
+
bestLocation = -1;
|
|
703
|
+
var lastBitArr = [];
|
|
704
|
+
var finalScore = 1;
|
|
705
|
+
var binMax = patternLen + textLen;
|
|
706
|
+
var mask = 1 << patternLen - 1;
|
|
707
|
+
for (var _i = 0; _i < patternLen; _i += 1) {
|
|
708
|
+
// Scan for the best match; each iteration allows for one more error.
|
|
709
|
+
// Run a binary search to determine how far from the match location we can stray
|
|
710
|
+
// at this error level.
|
|
711
|
+
var binMin = 0;
|
|
712
|
+
var binMid = binMax;
|
|
713
|
+
while (binMin < binMid) {
|
|
714
|
+
var _score = computeScore$1(pattern, {
|
|
715
|
+
errors: _i,
|
|
716
|
+
currentLocation: expectedLocation + binMid,
|
|
717
|
+
expectedLocation: expectedLocation,
|
|
718
|
+
distance: distance,
|
|
719
|
+
ignoreLocation: ignoreLocation
|
|
720
|
+
});
|
|
721
|
+
if (_score <= currentThreshold) {
|
|
722
|
+
binMin = binMid;
|
|
723
|
+
} else {
|
|
724
|
+
binMax = binMid;
|
|
725
|
+
}
|
|
726
|
+
binMid = Math.floor((binMax - binMin) / 2 + binMin);
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
// Use the result from this iteration as the maximum for the next.
|
|
730
|
+
binMax = binMid;
|
|
731
|
+
var start = Math.max(1, expectedLocation - binMid + 1);
|
|
732
|
+
var finish = findAllMatches ? textLen : Math.min(expectedLocation + binMid, textLen) + patternLen;
|
|
733
|
+
|
|
734
|
+
// Initialize the bit array
|
|
735
|
+
var bitArr = Array(finish + 2);
|
|
736
|
+
bitArr[finish + 1] = (1 << _i) - 1;
|
|
737
|
+
for (var j = finish; j >= start; j -= 1) {
|
|
738
|
+
var currentLocation = j - 1;
|
|
739
|
+
var charMatch = patternAlphabet[text.charAt(currentLocation)];
|
|
740
|
+
if (computeMatches) {
|
|
741
|
+
// Speed up: quick bool to int conversion (i.e, `charMatch ? 1 : 0`)
|
|
742
|
+
matchMask[currentLocation] = +!!charMatch;
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
// First pass: exact match
|
|
746
|
+
bitArr[j] = (bitArr[j + 1] << 1 | 1) & charMatch;
|
|
747
|
+
|
|
748
|
+
// Subsequent passes: fuzzy match
|
|
749
|
+
if (_i) {
|
|
750
|
+
bitArr[j] |= (lastBitArr[j + 1] | lastBitArr[j]) << 1 | 1 | lastBitArr[j + 1];
|
|
751
|
+
}
|
|
752
|
+
if (bitArr[j] & mask) {
|
|
753
|
+
finalScore = computeScore$1(pattern, {
|
|
754
|
+
errors: _i,
|
|
755
|
+
currentLocation: currentLocation,
|
|
756
|
+
expectedLocation: expectedLocation,
|
|
757
|
+
distance: distance,
|
|
758
|
+
ignoreLocation: ignoreLocation
|
|
759
|
+
});
|
|
760
|
+
|
|
761
|
+
// This match will almost certainly be better than any existing match.
|
|
762
|
+
// But check anyway.
|
|
763
|
+
if (finalScore <= currentThreshold) {
|
|
764
|
+
// Indeed it is
|
|
765
|
+
currentThreshold = finalScore;
|
|
766
|
+
bestLocation = currentLocation;
|
|
767
|
+
|
|
768
|
+
// Already passed `loc`, downhill from here on in.
|
|
769
|
+
if (bestLocation <= expectedLocation) {
|
|
770
|
+
break;
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
// When passing `bestLocation`, don't exceed our current distance from `expectedLocation`.
|
|
774
|
+
start = Math.max(1, 2 * expectedLocation - bestLocation);
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
// No hope for a (better) match at greater error levels.
|
|
780
|
+
var _score2 = computeScore$1(pattern, {
|
|
781
|
+
errors: _i + 1,
|
|
782
|
+
currentLocation: expectedLocation,
|
|
783
|
+
expectedLocation: expectedLocation,
|
|
784
|
+
distance: distance,
|
|
785
|
+
ignoreLocation: ignoreLocation
|
|
786
|
+
});
|
|
787
|
+
if (_score2 > currentThreshold) {
|
|
788
|
+
break;
|
|
789
|
+
}
|
|
790
|
+
lastBitArr = bitArr;
|
|
791
|
+
}
|
|
792
|
+
var result = {
|
|
793
|
+
isMatch: bestLocation >= 0,
|
|
794
|
+
// Count exact matches (those with a score of 0) to be "almost" exact
|
|
795
|
+
score: Math.max(0.001, finalScore)
|
|
796
|
+
};
|
|
797
|
+
if (computeMatches) {
|
|
798
|
+
var indices = convertMaskToIndices(matchMask, minMatchCharLength);
|
|
799
|
+
if (!indices.length) {
|
|
800
|
+
result.isMatch = false;
|
|
801
|
+
} else if (includeMatches) {
|
|
802
|
+
result.indices = indices;
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
return result;
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
function createPatternAlphabet(pattern) {
|
|
809
|
+
var mask = {};
|
|
810
|
+
for (var i = 0, len = pattern.length; i < len; i += 1) {
|
|
811
|
+
var _char = pattern.charAt(i);
|
|
812
|
+
mask[_char] = (mask[_char] || 0) | 1 << len - i - 1;
|
|
813
|
+
}
|
|
814
|
+
return mask;
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
var stripDiacritics = String.prototype.normalize ? function (str) {
|
|
818
|
+
return 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, '');
|
|
819
|
+
} : function (str) {
|
|
820
|
+
return str;
|
|
821
|
+
};
|
|
822
|
+
|
|
823
|
+
var BitapSearch = /*#__PURE__*/function () {
|
|
824
|
+
function BitapSearch(pattern) {
|
|
825
|
+
var _this = this;
|
|
826
|
+
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
827
|
+
_ref$location = _ref.location,
|
|
828
|
+
location = _ref$location === void 0 ? Config.location : _ref$location,
|
|
829
|
+
_ref$threshold = _ref.threshold,
|
|
830
|
+
threshold = _ref$threshold === void 0 ? Config.threshold : _ref$threshold,
|
|
831
|
+
_ref$distance = _ref.distance,
|
|
832
|
+
distance = _ref$distance === void 0 ? Config.distance : _ref$distance,
|
|
833
|
+
_ref$includeMatches = _ref.includeMatches,
|
|
834
|
+
includeMatches = _ref$includeMatches === void 0 ? Config.includeMatches : _ref$includeMatches,
|
|
835
|
+
_ref$findAllMatches = _ref.findAllMatches,
|
|
836
|
+
findAllMatches = _ref$findAllMatches === void 0 ? Config.findAllMatches : _ref$findAllMatches,
|
|
837
|
+
_ref$minMatchCharLeng = _ref.minMatchCharLength,
|
|
838
|
+
minMatchCharLength = _ref$minMatchCharLeng === void 0 ? Config.minMatchCharLength : _ref$minMatchCharLeng,
|
|
839
|
+
_ref$isCaseSensitive = _ref.isCaseSensitive,
|
|
840
|
+
isCaseSensitive = _ref$isCaseSensitive === void 0 ? Config.isCaseSensitive : _ref$isCaseSensitive,
|
|
841
|
+
_ref$ignoreDiacritics = _ref.ignoreDiacritics,
|
|
842
|
+
ignoreDiacritics = _ref$ignoreDiacritics === void 0 ? Config.ignoreDiacritics : _ref$ignoreDiacritics,
|
|
843
|
+
_ref$ignoreLocation = _ref.ignoreLocation,
|
|
844
|
+
ignoreLocation = _ref$ignoreLocation === void 0 ? Config.ignoreLocation : _ref$ignoreLocation;
|
|
845
|
+
_classCallCheck(this, BitapSearch);
|
|
846
|
+
this.options = {
|
|
847
|
+
location: location,
|
|
848
|
+
threshold: threshold,
|
|
849
|
+
distance: distance,
|
|
850
|
+
includeMatches: includeMatches,
|
|
851
|
+
findAllMatches: findAllMatches,
|
|
852
|
+
minMatchCharLength: minMatchCharLength,
|
|
853
|
+
isCaseSensitive: isCaseSensitive,
|
|
854
|
+
ignoreDiacritics: ignoreDiacritics,
|
|
855
|
+
ignoreLocation: ignoreLocation
|
|
856
|
+
};
|
|
857
|
+
pattern = isCaseSensitive ? pattern : pattern.toLowerCase();
|
|
858
|
+
pattern = ignoreDiacritics ? stripDiacritics(pattern) : pattern;
|
|
859
|
+
this.pattern = pattern;
|
|
860
|
+
this.chunks = [];
|
|
861
|
+
if (!this.pattern.length) {
|
|
862
|
+
return;
|
|
863
|
+
}
|
|
864
|
+
var addChunk = function addChunk(pattern, startIndex) {
|
|
865
|
+
_this.chunks.push({
|
|
866
|
+
pattern: pattern,
|
|
867
|
+
alphabet: createPatternAlphabet(pattern),
|
|
868
|
+
startIndex: startIndex
|
|
869
|
+
});
|
|
870
|
+
};
|
|
871
|
+
var len = this.pattern.length;
|
|
872
|
+
if (len > MAX_BITS) {
|
|
873
|
+
var i = 0;
|
|
874
|
+
var remainder = len % MAX_BITS;
|
|
875
|
+
var end = len - remainder;
|
|
876
|
+
while (i < end) {
|
|
877
|
+
addChunk(this.pattern.substr(i, MAX_BITS), i);
|
|
878
|
+
i += MAX_BITS;
|
|
879
|
+
}
|
|
880
|
+
if (remainder) {
|
|
881
|
+
var startIndex = len - MAX_BITS;
|
|
882
|
+
addChunk(this.pattern.substr(startIndex), startIndex);
|
|
883
|
+
}
|
|
884
|
+
} else {
|
|
885
|
+
addChunk(this.pattern, 0);
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
_createClass(BitapSearch, [{
|
|
889
|
+
key: "searchIn",
|
|
890
|
+
value: function searchIn(text) {
|
|
891
|
+
var _this$options = this.options,
|
|
892
|
+
isCaseSensitive = _this$options.isCaseSensitive,
|
|
893
|
+
ignoreDiacritics = _this$options.ignoreDiacritics,
|
|
894
|
+
includeMatches = _this$options.includeMatches;
|
|
895
|
+
text = isCaseSensitive ? text : text.toLowerCase();
|
|
896
|
+
text = ignoreDiacritics ? stripDiacritics(text) : text;
|
|
897
|
+
|
|
898
|
+
// Exact match
|
|
899
|
+
if (this.pattern === text) {
|
|
900
|
+
var _result = {
|
|
901
|
+
isMatch: true,
|
|
902
|
+
score: 0
|
|
903
|
+
};
|
|
904
|
+
if (includeMatches) {
|
|
905
|
+
_result.indices = [[0, text.length - 1]];
|
|
906
|
+
}
|
|
907
|
+
return _result;
|
|
908
|
+
}
|
|
909
|
+
|
|
910
|
+
// Otherwise, use Bitap algorithm
|
|
911
|
+
var _this$options2 = this.options,
|
|
912
|
+
location = _this$options2.location,
|
|
913
|
+
distance = _this$options2.distance,
|
|
914
|
+
threshold = _this$options2.threshold,
|
|
915
|
+
findAllMatches = _this$options2.findAllMatches,
|
|
916
|
+
minMatchCharLength = _this$options2.minMatchCharLength,
|
|
917
|
+
ignoreLocation = _this$options2.ignoreLocation;
|
|
918
|
+
var allIndices = [];
|
|
919
|
+
var totalScore = 0;
|
|
920
|
+
var hasMatches = false;
|
|
921
|
+
this.chunks.forEach(function (_ref2) {
|
|
922
|
+
var pattern = _ref2.pattern,
|
|
923
|
+
alphabet = _ref2.alphabet,
|
|
924
|
+
startIndex = _ref2.startIndex;
|
|
925
|
+
var _search = search(text, pattern, alphabet, {
|
|
926
|
+
location: location + startIndex,
|
|
927
|
+
distance: distance,
|
|
928
|
+
threshold: threshold,
|
|
929
|
+
findAllMatches: findAllMatches,
|
|
930
|
+
minMatchCharLength: minMatchCharLength,
|
|
931
|
+
includeMatches: includeMatches,
|
|
932
|
+
ignoreLocation: ignoreLocation
|
|
933
|
+
}),
|
|
934
|
+
isMatch = _search.isMatch,
|
|
935
|
+
score = _search.score,
|
|
936
|
+
indices = _search.indices;
|
|
937
|
+
if (isMatch) {
|
|
938
|
+
hasMatches = true;
|
|
939
|
+
}
|
|
940
|
+
totalScore += score;
|
|
941
|
+
if (isMatch && indices) {
|
|
942
|
+
allIndices = [].concat(_toConsumableArray(allIndices), _toConsumableArray(indices));
|
|
943
|
+
}
|
|
944
|
+
});
|
|
945
|
+
var result = {
|
|
946
|
+
isMatch: hasMatches,
|
|
947
|
+
score: hasMatches ? totalScore / this.chunks.length : 1
|
|
948
|
+
};
|
|
949
|
+
if (hasMatches && includeMatches) {
|
|
950
|
+
result.indices = allIndices;
|
|
951
|
+
}
|
|
952
|
+
return result;
|
|
953
|
+
}
|
|
954
|
+
}]);
|
|
955
|
+
return BitapSearch;
|
|
956
|
+
}();
|
|
957
|
+
|
|
958
|
+
var registeredSearchers = [];
|
|
959
|
+
function createSearcher(pattern, options) {
|
|
960
|
+
for (var i = 0, len = registeredSearchers.length; i < len; i += 1) {
|
|
961
|
+
var searcherClass = registeredSearchers[i];
|
|
962
|
+
if (searcherClass.condition(pattern, options)) {
|
|
963
|
+
return new searcherClass(pattern, options);
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
return new BitapSearch(pattern, options);
|
|
967
|
+
}
|
|
968
|
+
|
|
969
|
+
var LogicalOperator = {
|
|
970
|
+
AND: '$and',
|
|
971
|
+
OR: '$or'
|
|
972
|
+
};
|
|
973
|
+
var KeyType = {
|
|
974
|
+
PATH: '$path',
|
|
975
|
+
PATTERN: '$val'
|
|
976
|
+
};
|
|
977
|
+
var isExpression = function isExpression(query) {
|
|
978
|
+
return !!(query[LogicalOperator.AND] || query[LogicalOperator.OR]);
|
|
979
|
+
};
|
|
980
|
+
var isPath = function isPath(query) {
|
|
981
|
+
return !!query[KeyType.PATH];
|
|
982
|
+
};
|
|
983
|
+
var isLeaf = function isLeaf(query) {
|
|
984
|
+
return !isArray(query) && isObject(query) && !isExpression(query);
|
|
985
|
+
};
|
|
986
|
+
var convertToExplicit = function convertToExplicit(query) {
|
|
987
|
+
return _defineProperty({}, LogicalOperator.AND, Object.keys(query).map(function (key) {
|
|
988
|
+
return _defineProperty({}, key, query[key]);
|
|
989
|
+
}));
|
|
990
|
+
};
|
|
991
|
+
|
|
992
|
+
// When `auto` is `true`, the parse function will infer and initialize and add
|
|
993
|
+
// the appropriate `Searcher` instance
|
|
994
|
+
function parse(query, options) {
|
|
995
|
+
var _ref3 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
|
|
996
|
+
_ref3$auto = _ref3.auto,
|
|
997
|
+
auto = _ref3$auto === void 0 ? true : _ref3$auto;
|
|
998
|
+
var next = function next(query) {
|
|
999
|
+
var keys = Object.keys(query);
|
|
1000
|
+
var isQueryPath = isPath(query);
|
|
1001
|
+
if (!isQueryPath && keys.length > 1 && !isExpression(query)) {
|
|
1002
|
+
return next(convertToExplicit(query));
|
|
1003
|
+
}
|
|
1004
|
+
if (isLeaf(query)) {
|
|
1005
|
+
var key = isQueryPath ? query[KeyType.PATH] : keys[0];
|
|
1006
|
+
var pattern = isQueryPath ? query[KeyType.PATTERN] : query[key];
|
|
1007
|
+
if (!isString(pattern)) {
|
|
1008
|
+
throw new Error(LOGICAL_SEARCH_INVALID_QUERY_FOR_KEY(key));
|
|
1009
|
+
}
|
|
1010
|
+
var obj = {
|
|
1011
|
+
keyId: createKeyId(key),
|
|
1012
|
+
pattern: pattern
|
|
1013
|
+
};
|
|
1014
|
+
if (auto) {
|
|
1015
|
+
obj.searcher = createSearcher(pattern, options);
|
|
1016
|
+
}
|
|
1017
|
+
return obj;
|
|
1018
|
+
}
|
|
1019
|
+
var node = {
|
|
1020
|
+
children: [],
|
|
1021
|
+
operator: keys[0]
|
|
1022
|
+
};
|
|
1023
|
+
keys.forEach(function (key) {
|
|
1024
|
+
var value = query[key];
|
|
1025
|
+
if (isArray(value)) {
|
|
1026
|
+
value.forEach(function (item) {
|
|
1027
|
+
node.children.push(next(item));
|
|
1028
|
+
});
|
|
1029
|
+
}
|
|
1030
|
+
});
|
|
1031
|
+
return node;
|
|
1032
|
+
};
|
|
1033
|
+
if (!isExpression(query)) {
|
|
1034
|
+
query = convertToExplicit(query);
|
|
1035
|
+
}
|
|
1036
|
+
return next(query);
|
|
1037
|
+
}
|
|
1038
|
+
|
|
1039
|
+
// Practical scoring function
|
|
1040
|
+
function computeScore(results, _ref) {
|
|
1041
|
+
var _ref$ignoreFieldNorm = _ref.ignoreFieldNorm,
|
|
1042
|
+
ignoreFieldNorm = _ref$ignoreFieldNorm === void 0 ? Config.ignoreFieldNorm : _ref$ignoreFieldNorm;
|
|
1043
|
+
results.forEach(function (result) {
|
|
1044
|
+
var totalScore = 1;
|
|
1045
|
+
result.matches.forEach(function (_ref2) {
|
|
1046
|
+
var key = _ref2.key,
|
|
1047
|
+
norm = _ref2.norm,
|
|
1048
|
+
score = _ref2.score;
|
|
1049
|
+
var weight = key ? key.weight : null;
|
|
1050
|
+
totalScore *= Math.pow(score === 0 && weight ? Number.EPSILON : score, (weight || 1) * (ignoreFieldNorm ? 1 : norm));
|
|
1051
|
+
});
|
|
1052
|
+
result.score = totalScore;
|
|
1053
|
+
});
|
|
1054
|
+
}
|
|
1055
|
+
|
|
1056
|
+
function transformMatches(result, data) {
|
|
1057
|
+
var matches = result.matches;
|
|
1058
|
+
data.matches = [];
|
|
1059
|
+
if (!isDefined(matches)) {
|
|
1060
|
+
return;
|
|
1061
|
+
}
|
|
1062
|
+
matches.forEach(function (match) {
|
|
1063
|
+
if (!isDefined(match.indices) || !match.indices.length) {
|
|
1064
|
+
return;
|
|
1065
|
+
}
|
|
1066
|
+
var indices = match.indices,
|
|
1067
|
+
value = match.value;
|
|
1068
|
+
var obj = {
|
|
1069
|
+
indices: indices,
|
|
1070
|
+
value: value
|
|
1071
|
+
};
|
|
1072
|
+
if (match.key) {
|
|
1073
|
+
obj.key = match.key.src;
|
|
1074
|
+
}
|
|
1075
|
+
if (match.idx > -1) {
|
|
1076
|
+
obj.refIndex = match.idx;
|
|
1077
|
+
}
|
|
1078
|
+
data.matches.push(obj);
|
|
1079
|
+
});
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1082
|
+
function transformScore(result, data) {
|
|
1083
|
+
data.score = result.score;
|
|
1084
|
+
}
|
|
1085
|
+
|
|
1086
|
+
function format(results, docs) {
|
|
1087
|
+
var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
|
|
1088
|
+
_ref$includeMatches = _ref.includeMatches,
|
|
1089
|
+
includeMatches = _ref$includeMatches === void 0 ? Config.includeMatches : _ref$includeMatches,
|
|
1090
|
+
_ref$includeScore = _ref.includeScore,
|
|
1091
|
+
includeScore = _ref$includeScore === void 0 ? Config.includeScore : _ref$includeScore;
|
|
1092
|
+
var transformers = [];
|
|
1093
|
+
if (includeMatches) transformers.push(transformMatches);
|
|
1094
|
+
if (includeScore) transformers.push(transformScore);
|
|
1095
|
+
return results.map(function (result) {
|
|
1096
|
+
var idx = result.idx;
|
|
1097
|
+
var data = {
|
|
1098
|
+
item: docs[idx],
|
|
1099
|
+
refIndex: idx
|
|
1100
|
+
};
|
|
1101
|
+
if (transformers.length) {
|
|
1102
|
+
transformers.forEach(function (transformer) {
|
|
1103
|
+
transformer(result, data);
|
|
1104
|
+
});
|
|
1105
|
+
}
|
|
1106
|
+
return data;
|
|
1107
|
+
});
|
|
1108
|
+
}
|
|
1109
|
+
|
|
1110
|
+
var Fuse$1 = /*#__PURE__*/function () {
|
|
1111
|
+
function Fuse(docs) {
|
|
1112
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1113
|
+
var index = arguments.length > 2 ? arguments[2] : undefined;
|
|
1114
|
+
_classCallCheck(this, Fuse);
|
|
1115
|
+
this.options = _objectSpread2(_objectSpread2({}, Config), options);
|
|
1116
|
+
if (this.options.useExtendedSearch && !false) {
|
|
1117
|
+
throw new Error(EXTENDED_SEARCH_UNAVAILABLE);
|
|
1118
|
+
}
|
|
1119
|
+
this._keyStore = new KeyStore(this.options.keys);
|
|
1120
|
+
this.setCollection(docs, index);
|
|
1121
|
+
}
|
|
1122
|
+
_createClass(Fuse, [{
|
|
1123
|
+
key: "setCollection",
|
|
1124
|
+
value: function setCollection(docs, index) {
|
|
1125
|
+
this._docs = docs;
|
|
1126
|
+
if (index && !(index instanceof FuseIndex)) {
|
|
1127
|
+
throw new Error(INCORRECT_INDEX_TYPE);
|
|
1128
|
+
}
|
|
1129
|
+
this._myIndex = index || createIndex(this.options.keys, this._docs, {
|
|
1130
|
+
getFn: this.options.getFn,
|
|
1131
|
+
fieldNormWeight: this.options.fieldNormWeight
|
|
1132
|
+
});
|
|
1133
|
+
}
|
|
1134
|
+
}, {
|
|
1135
|
+
key: "add",
|
|
1136
|
+
value: function add(doc) {
|
|
1137
|
+
if (!isDefined(doc)) {
|
|
1138
|
+
return;
|
|
1139
|
+
}
|
|
1140
|
+
this._docs.push(doc);
|
|
1141
|
+
this._myIndex.add(doc);
|
|
1142
|
+
}
|
|
1143
|
+
}, {
|
|
1144
|
+
key: "remove",
|
|
1145
|
+
value: function remove() {
|
|
1146
|
+
var predicate = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function /* doc, idx */ () {
|
|
1147
|
+
return false;
|
|
1148
|
+
};
|
|
1149
|
+
var results = [];
|
|
1150
|
+
for (var i = 0, len = this._docs.length; i < len; i += 1) {
|
|
1151
|
+
var doc = this._docs[i];
|
|
1152
|
+
if (predicate(doc, i)) {
|
|
1153
|
+
this.removeAt(i);
|
|
1154
|
+
i -= 1;
|
|
1155
|
+
len -= 1;
|
|
1156
|
+
results.push(doc);
|
|
1157
|
+
}
|
|
1158
|
+
}
|
|
1159
|
+
return results;
|
|
1160
|
+
}
|
|
1161
|
+
}, {
|
|
1162
|
+
key: "removeAt",
|
|
1163
|
+
value: function removeAt(idx) {
|
|
1164
|
+
this._docs.splice(idx, 1);
|
|
1165
|
+
this._myIndex.removeAt(idx);
|
|
1166
|
+
}
|
|
1167
|
+
}, {
|
|
1168
|
+
key: "getIndex",
|
|
1169
|
+
value: function getIndex() {
|
|
1170
|
+
return this._myIndex;
|
|
1171
|
+
}
|
|
1172
|
+
}, {
|
|
1173
|
+
key: "search",
|
|
1174
|
+
value: function search(query) {
|
|
1175
|
+
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
1176
|
+
_ref$limit = _ref.limit,
|
|
1177
|
+
limit = _ref$limit === void 0 ? -1 : _ref$limit;
|
|
1178
|
+
var _this$options = this.options,
|
|
1179
|
+
includeMatches = _this$options.includeMatches,
|
|
1180
|
+
includeScore = _this$options.includeScore,
|
|
1181
|
+
shouldSort = _this$options.shouldSort,
|
|
1182
|
+
sortFn = _this$options.sortFn,
|
|
1183
|
+
ignoreFieldNorm = _this$options.ignoreFieldNorm;
|
|
1184
|
+
var results = isString(query) ? isString(this._docs[0]) ? this._searchStringList(query) : this._searchObjectList(query) : this._searchLogical(query);
|
|
1185
|
+
computeScore(results, {
|
|
1186
|
+
ignoreFieldNorm: ignoreFieldNorm
|
|
1187
|
+
});
|
|
1188
|
+
if (shouldSort) {
|
|
1189
|
+
results.sort(sortFn);
|
|
1190
|
+
}
|
|
1191
|
+
if (isNumber(limit) && limit > -1) {
|
|
1192
|
+
results = results.slice(0, limit);
|
|
1193
|
+
}
|
|
1194
|
+
return format(results, this._docs, {
|
|
1195
|
+
includeMatches: includeMatches,
|
|
1196
|
+
includeScore: includeScore
|
|
1197
|
+
});
|
|
1198
|
+
}
|
|
1199
|
+
}, {
|
|
1200
|
+
key: "_searchStringList",
|
|
1201
|
+
value: function _searchStringList(query) {
|
|
1202
|
+
var searcher = createSearcher(query, this.options);
|
|
1203
|
+
var records = this._myIndex.records;
|
|
1204
|
+
var results = [];
|
|
1205
|
+
|
|
1206
|
+
// Iterate over every string in the index
|
|
1207
|
+
records.forEach(function (_ref2) {
|
|
1208
|
+
var text = _ref2.v,
|
|
1209
|
+
idx = _ref2.i,
|
|
1210
|
+
norm = _ref2.n;
|
|
1211
|
+
if (!isDefined(text)) {
|
|
1212
|
+
return;
|
|
1213
|
+
}
|
|
1214
|
+
var _searcher$searchIn = searcher.searchIn(text),
|
|
1215
|
+
isMatch = _searcher$searchIn.isMatch,
|
|
1216
|
+
score = _searcher$searchIn.score,
|
|
1217
|
+
indices = _searcher$searchIn.indices;
|
|
1218
|
+
if (isMatch) {
|
|
1219
|
+
results.push({
|
|
1220
|
+
item: text,
|
|
1221
|
+
idx: idx,
|
|
1222
|
+
matches: [{
|
|
1223
|
+
score: score,
|
|
1224
|
+
value: text,
|
|
1225
|
+
norm: norm,
|
|
1226
|
+
indices: indices
|
|
1227
|
+
}]
|
|
1228
|
+
});
|
|
1229
|
+
}
|
|
1230
|
+
});
|
|
1231
|
+
return results;
|
|
1232
|
+
}
|
|
1233
|
+
}, {
|
|
1234
|
+
key: "_searchLogical",
|
|
1235
|
+
value: function _searchLogical(query) {
|
|
1236
|
+
{
|
|
1237
|
+
throw new Error(LOGICAL_SEARCH_UNAVAILABLE);
|
|
1238
|
+
}
|
|
1239
|
+
}
|
|
1240
|
+
}, {
|
|
1241
|
+
key: "_searchObjectList",
|
|
1242
|
+
value: function _searchObjectList(query) {
|
|
1243
|
+
var _this2 = this;
|
|
1244
|
+
var searcher = createSearcher(query, this.options);
|
|
1245
|
+
var _this$_myIndex = this._myIndex,
|
|
1246
|
+
keys = _this$_myIndex.keys,
|
|
1247
|
+
records = _this$_myIndex.records;
|
|
1248
|
+
var results = [];
|
|
1249
|
+
|
|
1250
|
+
// List is Array<Object>
|
|
1251
|
+
records.forEach(function (_ref5) {
|
|
1252
|
+
var item = _ref5.$,
|
|
1253
|
+
idx = _ref5.i;
|
|
1254
|
+
if (!isDefined(item)) {
|
|
1255
|
+
return;
|
|
1256
|
+
}
|
|
1257
|
+
var matches = [];
|
|
1258
|
+
|
|
1259
|
+
// Iterate over every key (i.e, path), and fetch the value at that key
|
|
1260
|
+
keys.forEach(function (key, keyIndex) {
|
|
1261
|
+
matches.push.apply(matches, _toConsumableArray(_this2._findMatches({
|
|
1262
|
+
key: key,
|
|
1263
|
+
value: item[keyIndex],
|
|
1264
|
+
searcher: searcher
|
|
1265
|
+
})));
|
|
1266
|
+
});
|
|
1267
|
+
if (matches.length) {
|
|
1268
|
+
results.push({
|
|
1269
|
+
idx: idx,
|
|
1270
|
+
item: item,
|
|
1271
|
+
matches: matches
|
|
1272
|
+
});
|
|
1273
|
+
}
|
|
1274
|
+
});
|
|
1275
|
+
return results;
|
|
1276
|
+
}
|
|
1277
|
+
}, {
|
|
1278
|
+
key: "_findMatches",
|
|
1279
|
+
value: function _findMatches(_ref6) {
|
|
1280
|
+
var key = _ref6.key,
|
|
1281
|
+
value = _ref6.value,
|
|
1282
|
+
searcher = _ref6.searcher;
|
|
1283
|
+
if (!isDefined(value)) {
|
|
1284
|
+
return [];
|
|
1285
|
+
}
|
|
1286
|
+
var matches = [];
|
|
1287
|
+
if (isArray(value)) {
|
|
1288
|
+
value.forEach(function (_ref7) {
|
|
1289
|
+
var text = _ref7.v,
|
|
1290
|
+
idx = _ref7.i,
|
|
1291
|
+
norm = _ref7.n;
|
|
1292
|
+
if (!isDefined(text)) {
|
|
1293
|
+
return;
|
|
1294
|
+
}
|
|
1295
|
+
var _searcher$searchIn2 = searcher.searchIn(text),
|
|
1296
|
+
isMatch = _searcher$searchIn2.isMatch,
|
|
1297
|
+
score = _searcher$searchIn2.score,
|
|
1298
|
+
indices = _searcher$searchIn2.indices;
|
|
1299
|
+
if (isMatch) {
|
|
1300
|
+
matches.push({
|
|
1301
|
+
score: score,
|
|
1302
|
+
key: key,
|
|
1303
|
+
value: text,
|
|
1304
|
+
idx: idx,
|
|
1305
|
+
norm: norm,
|
|
1306
|
+
indices: indices
|
|
1307
|
+
});
|
|
1308
|
+
}
|
|
1309
|
+
});
|
|
1310
|
+
} else {
|
|
1311
|
+
var text = value.v,
|
|
1312
|
+
norm = value.n;
|
|
1313
|
+
var _searcher$searchIn3 = searcher.searchIn(text),
|
|
1314
|
+
isMatch = _searcher$searchIn3.isMatch,
|
|
1315
|
+
score = _searcher$searchIn3.score,
|
|
1316
|
+
indices = _searcher$searchIn3.indices;
|
|
1317
|
+
if (isMatch) {
|
|
1318
|
+
matches.push({
|
|
1319
|
+
score: score,
|
|
1320
|
+
key: key,
|
|
1321
|
+
value: text,
|
|
1322
|
+
norm: norm,
|
|
1323
|
+
indices: indices
|
|
1324
|
+
});
|
|
1325
|
+
}
|
|
1326
|
+
}
|
|
1327
|
+
return matches;
|
|
1328
|
+
}
|
|
1329
|
+
}]);
|
|
1330
|
+
return Fuse;
|
|
1331
|
+
}();
|
|
1332
|
+
|
|
1333
|
+
Fuse$1.version = '7.1.0';
|
|
1334
|
+
Fuse$1.createIndex = createIndex;
|
|
1335
|
+
Fuse$1.parseIndex = parseIndex;
|
|
1336
|
+
Fuse$1.config = Config;
|
|
1337
|
+
{
|
|
1338
|
+
Fuse$1.parseQuery = parse;
|
|
1339
|
+
}
|
|
1340
|
+
var Fuse = Fuse$1;
|
|
1341
|
+
|
|
1342
|
+
module.exports = Fuse;
|