| 1 | | -/** |
| 2 | | - * Fuse.js v6.6.2 - Lightweight fuzzy-search (http://fusejs.io) |
| 3 | | - * |
| 4 | | - * Copyright (c) 2022 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 | | -(function (global, factory) { |
| 11 | | - typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : |
| 12 | | - typeof define === 'function' && define.amd ? define(factory) : |
| 13 | | - (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Fuse = factory()); |
| 14 | | -})(this, (function () { 'use strict'; |
| 15 | | - |
| 16 | | - function ownKeys(object, enumerableOnly) { |
| 17 | | - var keys = Object.keys(object); |
| 18 | | - |
| 19 | | - if (Object.getOwnPropertySymbols) { |
| 20 | | - var symbols = Object.getOwnPropertySymbols(object); |
| 21 | | - enumerableOnly && (symbols = symbols.filter(function (sym) { |
| 22 | | - return Object.getOwnPropertyDescriptor(object, sym).enumerable; |
| 23 | | - })), keys.push.apply(keys, symbols); |
| 24 | | - } |
| 25 | | - |
| 26 | | - return keys; |
| 27 | | - } |
| 28 | | - |
| 29 | | - function _objectSpread2(target) { |
| 30 | | - for (var i = 1; i < arguments.length; i++) { |
| 31 | | - var source = null != arguments[i] ? arguments[i] : {}; |
| 32 | | - i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { |
| 33 | | - _defineProperty(target, key, source[key]); |
| 34 | | - }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { |
| 35 | | - Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); |
| 36 | | - }); |
| 37 | | - } |
| 38 | | - |
| 39 | | - return target; |
| 40 | | - } |
| 41 | | - |
| 42 | | - function _typeof(obj) { |
| 43 | | - "@babel/helpers - typeof"; |
| 44 | | - |
| 45 | | - return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { |
| 46 | | - return typeof obj; |
| 47 | | - } : function (obj) { |
| 48 | | - return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; |
| 49 | | - }, _typeof(obj); |
| 50 | | - } |
| 51 | | - |
| 52 | | - function _classCallCheck(instance, Constructor) { |
| 53 | | - if (!(instance instanceof Constructor)) { |
| 54 | | - throw new TypeError("Cannot call a class as a function"); |
| 55 | | - } |
| 56 | | - } |
| 57 | | - |
| 58 | | - function _defineProperties(target, props) { |
| 59 | | - for (var i = 0; i < props.length; i++) { |
| 60 | | - var descriptor = props[i]; |
| 61 | | - descriptor.enumerable = descriptor.enumerable || false; |
| 62 | | - descriptor.configurable = true; |
| 63 | | - if ("value" in descriptor) descriptor.writable = true; |
| 64 | | - Object.defineProperty(target, descriptor.key, descriptor); |
| 65 | | - } |
| 66 | | - } |
| 67 | | - |
| 68 | | - function _createClass(Constructor, protoProps, staticProps) { |
| 69 | | - if (protoProps) _defineProperties(Constructor.prototype, protoProps); |
| 70 | | - if (staticProps) _defineProperties(Constructor, staticProps); |
| 71 | | - Object.defineProperty(Constructor, "prototype", { |
| 72 | | - writable: false |
| 73 | | - }); |
| 74 | | - return Constructor; |
| 75 | | - } |
| 76 | | - |
| 77 | | - function _defineProperty(obj, key, value) { |
| 78 | | - if (key in obj) { |
| 79 | | - Object.defineProperty(obj, key, { |
| 80 | | - value: value, |
| 81 | | - enumerable: true, |
| 82 | | - configurable: true, |
| 83 | | - writable: true |
| 84 | | - }); |
| 85 | | - } else { |
| 86 | | - obj[key] = value; |
| 87 | | - } |
| 88 | | - |
| 89 | | - return obj; |
| 90 | | - } |
| 91 | | - |
| 92 | | - function _inherits(subClass, superClass) { |
| 93 | | - if (typeof superClass !== "function" && superClass !== null) { |
| 94 | | - throw new TypeError("Super expression must either be null or a function"); |
| 95 | | - } |
| 96 | | - |
| 97 | | - Object.defineProperty(subClass, "prototype", { |
| 98 | | - value: Object.create(superClass && superClass.prototype, { |
| 99 | | - constructor: { |
| 100 | | - value: subClass, |
| 101 | | - writable: true, |
| 102 | | - configurable: true |
| 103 | | - } |
| 104 | | - }), |
| 105 | | - writable: false |
| 106 | | - }); |
| 107 | | - if (superClass) _setPrototypeOf(subClass, superClass); |
| 108 | | - } |
| 109 | | - |
| 110 | | - function _getPrototypeOf(o) { |
| 111 | | - _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { |
| 112 | | - return o.__proto__ || Object.getPrototypeOf(o); |
| 113 | | - }; |
| 114 | | - return _getPrototypeOf(o); |
| 115 | | - } |
| 116 | | - |
| 117 | | - function _setPrototypeOf(o, p) { |
| 118 | | - _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { |
| 119 | | - o.__proto__ = p; |
| 120 | | - return o; |
| 121 | | - }; |
| 122 | | - |
| 123 | | - return _setPrototypeOf(o, p); |
| 124 | | - } |
| 125 | | - |
| 126 | | - function _isNativeReflectConstruct() { |
| 127 | | - if (typeof Reflect === "undefined" || !Reflect.construct) return false; |
| 128 | | - if (Reflect.construct.sham) return false; |
| 129 | | - if (typeof Proxy === "function") return true; |
| 130 | | - |
| 131 | | - try { |
| 132 | | - Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); |
| 133 | | - return true; |
| 134 | | - } catch (e) { |
| 135 | | - return false; |
| 136 | | - } |
| 137 | | - } |
| 138 | | - |
| 139 | | - function _assertThisInitialized(self) { |
| 140 | | - if (self === void 0) { |
| 141 | | - throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); |
| 142 | | - } |
| 143 | | - |
| 144 | | - return self; |
| 145 | | - } |
| 146 | | - |
| 147 | | - function _possibleConstructorReturn(self, call) { |
| 148 | | - if (call && (typeof call === "object" || typeof call === "function")) { |
| 149 | | - return call; |
| 150 | | - } else if (call !== void 0) { |
| 151 | | - throw new TypeError("Derived constructors may only return object or undefined"); |
| 152 | | - } |
| 153 | | - |
| 154 | | - return _assertThisInitialized(self); |
| 155 | | - } |
| 156 | | - |
| 157 | | - function _createSuper(Derived) { |
| 158 | | - var hasNativeReflectConstruct = _isNativeReflectConstruct(); |
| 159 | | - |
| 160 | | - return function _createSuperInternal() { |
| 161 | | - var Super = _getPrototypeOf(Derived), |
| 162 | | - result; |
| 163 | | - |
| 164 | | - if (hasNativeReflectConstruct) { |
| 165 | | - var NewTarget = _getPrototypeOf(this).constructor; |
| 166 | | - |
| 167 | | - result = Reflect.construct(Super, arguments, NewTarget); |
| 168 | | - } else { |
| 169 | | - result = Super.apply(this, arguments); |
| 170 | | - } |
| 171 | | - |
| 172 | | - return _possibleConstructorReturn(this, result); |
| 173 | | - }; |
| 174 | | - } |
| 175 | | - |
| 176 | | - function _toConsumableArray(arr) { |
| 177 | | - return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); |
| 178 | | - } |
| 179 | | - |
| 180 | | - function _arrayWithoutHoles(arr) { |
| 181 | | - if (Array.isArray(arr)) return _arrayLikeToArray(arr); |
| 182 | | - } |
| 183 | | - |
| 184 | | - function _iterableToArray(iter) { |
| 185 | | - if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); |
| 186 | | - } |
| 187 | | - |
| 188 | | - function _unsupportedIterableToArray(o, minLen) { |
| 189 | | - if (!o) return; |
| 190 | | - if (typeof o === "string") return _arrayLikeToArray(o, minLen); |
| 191 | | - var n = Object.prototype.toString.call(o).slice(8, -1); |
| 192 | | - if (n === "Object" && o.constructor) n = o.constructor.name; |
| 193 | | - if (n === "Map" || n === "Set") return Array.from(o); |
| 194 | | - if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); |
| 195 | | - } |
| 196 | | - |
| 197 | | - function _arrayLikeToArray(arr, len) { |
| 198 | | - if (len == null || len > arr.length) len = arr.length; |
| 199 | | - |
| 200 | | - for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; |
| 201 | | - |
| 202 | | - return arr2; |
| 203 | | - } |
| 204 | | - |
| 205 | | - function _nonIterableSpread() { |
| 206 | | - throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); |
| 207 | | - } |
| 208 | | - |
| 209 | | - function isArray(value) { |
| 210 | | - return !Array.isArray ? getTag(value) === '[object Array]' : Array.isArray(value); |
| 211 | | - } // Adapted from: https://github.com/lodash/lodash/blob/master/.internal/baseToString.js |
| 212 | | - |
| 213 | | - var INFINITY = 1 / 0; |
| 214 | | - function baseToString(value) { |
| 215 | | - // Exit early for strings to avoid a performance hit in some environments. |
| 216 | | - if (typeof value == 'string') { |
| 217 | | - return value; |
| 218 | | - } |
| 219 | | - |
| 220 | | - var result = value + ''; |
| 221 | | - return result == '0' && 1 / value == -INFINITY ? '-0' : result; |
| 222 | | - } |
| 223 | | - function toString(value) { |
| 224 | | - return value == null ? '' : baseToString(value); |
| 225 | | - } |
| 226 | | - function isString(value) { |
| 227 | | - return typeof value === 'string'; |
| 228 | | - } |
| 229 | | - function isNumber(value) { |
| 230 | | - return typeof value === 'number'; |
| 231 | | - } // Adapted from: https://github.com/lodash/lodash/blob/master/isBoolean.js |
| 232 | | - |
| 233 | | - function isBoolean(value) { |
| 234 | | - return value === true || value === false || isObjectLike(value) && getTag(value) == '[object Boolean]'; |
| 235 | | - } |
| 236 | | - function isObject(value) { |
| 237 | | - return _typeof(value) === 'object'; |
| 238 | | - } // Checks if `value` is object-like. |
| 239 | | - |
| 240 | | - function isObjectLike(value) { |
| 241 | | - return isObject(value) && value !== null; |
| 242 | | - } |
| 243 | | - function isDefined(value) { |
| 244 | | - return value !== undefined && value !== null; |
| 245 | | - } |
| 246 | | - function isBlank(value) { |
| 247 | | - return !value.trim().length; |
| 248 | | - } // Gets the `toStringTag` of `value`. |
| 249 | | - // Adapted from: https://github.com/lodash/lodash/blob/master/.internal/getTag.js |
| 250 | | - |
| 251 | | - function getTag(value) { |
| 252 | | - return value == null ? value === undefined ? '[object Undefined]' : '[object Null]' : Object.prototype.toString.call(value); |
| 253 | | - } |
| 254 | | - |
| 255 | | - var EXTENDED_SEARCH_UNAVAILABLE = 'Extended search is not available'; |
| 256 | | - var INCORRECT_INDEX_TYPE = "Incorrect 'index' type"; |
| 257 | | - var LOGICAL_SEARCH_INVALID_QUERY_FOR_KEY = function LOGICAL_SEARCH_INVALID_QUERY_FOR_KEY(key) { |
| 258 | | - return "Invalid value for key ".concat(key); |
| 259 | | - }; |
| 260 | | - var PATTERN_LENGTH_TOO_LARGE = function PATTERN_LENGTH_TOO_LARGE(max) { |
| 261 | | - return "Pattern length exceeds max of ".concat(max, "."); |
| 262 | | - }; |
| 263 | | - var MISSING_KEY_PROPERTY = function MISSING_KEY_PROPERTY(name) { |
| 264 | | - return "Missing ".concat(name, " property in key"); |
| 265 | | - }; |
| 266 | | - var INVALID_KEY_WEIGHT_VALUE = function INVALID_KEY_WEIGHT_VALUE(key) { |
| 267 | | - return "Property 'weight' in key '".concat(key, "' must be a positive integer"); |
| 268 | | - }; |
| 269 | | - |
| 270 | | - var hasOwn = Object.prototype.hasOwnProperty; |
| 271 | | - |
| 272 | | - var KeyStore = /*#__PURE__*/function () { |
| 273 | | - function KeyStore(keys) { |
| 274 | | - var _this = this; |
| 275 | | - |
| 276 | | - _classCallCheck(this, KeyStore); |
| 277 | | - |
| 278 | | - this._keys = []; |
| 279 | | - this._keyMap = {}; |
| 280 | | - var totalWeight = 0; |
| 281 | | - keys.forEach(function (key) { |
| 282 | | - var obj = createKey(key); |
| 283 | | - totalWeight += obj.weight; |
| 284 | | - |
| 285 | | - _this._keys.push(obj); |
| 286 | | - |
| 287 | | - _this._keyMap[obj.id] = obj; |
| 288 | | - totalWeight += obj.weight; |
| 289 | | - }); // Normalize weights so that their sum is equal to 1 |
| 290 | | - |
| 291 | | - this._keys.forEach(function (key) { |
| 292 | | - key.weight /= totalWeight; |
| 293 | | - }); |
| 294 | | - } |
| 295 | | - |
| 296 | | - _createClass(KeyStore, [{ |
| 297 | | - key: "get", |
| 298 | | - value: function get(keyId) { |
| 299 | | - return this._keyMap[keyId]; |
| 300 | | - } |
| 301 | | - }, { |
| 302 | | - key: "keys", |
| 303 | | - value: function keys() { |
| 304 | | - return this._keys; |
| 305 | | - } |
| 306 | | - }, { |
| 307 | | - key: "toJSON", |
| 308 | | - value: function toJSON() { |
| 309 | | - return JSON.stringify(this._keys); |
| 310 | | - } |
| 311 | | - }]); |
| 312 | | - |
| 313 | | - return KeyStore; |
| 314 | | - }(); |
| 315 | | - function createKey(key) { |
| 316 | | - var path = null; |
| 317 | | - var id = null; |
| 318 | | - var src = null; |
| 319 | | - var weight = 1; |
| 320 | | - var getFn = null; |
| 321 | | - |
| 322 | | - if (isString(key) || isArray(key)) { |
| 323 | | - src = key; |
| 324 | | - path = createKeyPath(key); |
| 325 | | - id = createKeyId(key); |
| 326 | | - } else { |
| 327 | | - if (!hasOwn.call(key, 'name')) { |
| 328 | | - throw new Error(MISSING_KEY_PROPERTY('name')); |
| 329 | | - } |
| 330 | | - |
| 331 | | - var name = key.name; |
| 332 | | - src = name; |
| 333 | | - |
| 334 | | - if (hasOwn.call(key, 'weight')) { |
| 335 | | - weight = key.weight; |
| 336 | | - |
| 337 | | - if (weight <= 0) { |
| 338 | | - throw new Error(INVALID_KEY_WEIGHT_VALUE(name)); |
| 339 | | - } |
| 340 | | - } |
| 341 | | - |
| 342 | | - path = createKeyPath(name); |
| 343 | | - id = createKeyId(name); |
| 344 | | - getFn = key.getFn; |
| 345 | | - } |
| 346 | | - |
| 347 | | - return { |
| 348 | | - path: path, |
| 349 | | - id: id, |
| 350 | | - weight: weight, |
| 351 | | - src: src, |
| 352 | | - getFn: getFn |
| 353 | | - }; |
| 354 | | - } |
| 355 | | - function createKeyPath(key) { |
| 356 | | - return isArray(key) ? key : key.split('.'); |
| 357 | | - } |
| 358 | | - function createKeyId(key) { |
| 359 | | - return isArray(key) ? key.join('.') : key; |
| 360 | | - } |
| 361 | | - |
| 362 | | - function get(obj, path) { |
| 363 | | - var list = []; |
| 364 | | - var arr = false; |
| 365 | | - |
| 366 | | - var deepGet = function deepGet(obj, path, index) { |
| 367 | | - if (!isDefined(obj)) { |
| 368 | | - return; |
| 369 | | - } |
| 370 | | - |
| 371 | | - if (!path[index]) { |
| 372 | | - // If there's no path left, we've arrived at the object we care about. |
| 373 | | - list.push(obj); |
| 374 | | - } else { |
| 375 | | - var key = path[index]; |
| 376 | | - var value = obj[key]; |
| 377 | | - |
| 378 | | - if (!isDefined(value)) { |
| 379 | | - return; |
| 380 | | - } // If we're at the last value in the path, and if it's a string/number/bool, |
| 381 | | - // add it to the list |
| 382 | | - |
| 383 | | - |
| 384 | | - if (index === path.length - 1 && (isString(value) || isNumber(value) || isBoolean(value))) { |
| 385 | | - list.push(toString(value)); |
| 386 | | - } else if (isArray(value)) { |
| 387 | | - arr = true; // Search each item in the array. |
| 388 | | - |
| 389 | | - for (var i = 0, len = value.length; i < len; i += 1) { |
| 390 | | - deepGet(value[i], path, index + 1); |
| 391 | | - } |
| 392 | | - } else if (path.length) { |
| 393 | | - // An object. Recurse further. |
| 394 | | - deepGet(value, path, index + 1); |
| 395 | | - } |
| 396 | | - } |
| 397 | | - }; // Backwards compatibility (since path used to be a string) |
| 398 | | - |
| 399 | | - |
| 400 | | - deepGet(obj, isString(path) ? path.split('.') : path, 0); |
| 401 | | - return arr ? list : list[0]; |
| 402 | | - } |
| 403 | | - |
| 404 | | - var MatchOptions = { |
| 405 | | - // Whether the matches should be included in the result set. When `true`, each record in the result |
| 406 | | - // set will include the indices of the matched characters. |
| 407 | | - // These can consequently be used for highlighting purposes. |
| 408 | | - includeMatches: false, |
| 409 | | - // When `true`, the matching function will continue to the end of a search pattern even if |
| 410 | | - // a perfect match has already been located in the string. |
| 411 | | - findAllMatches: false, |
| 412 | | - // Minimum number of characters that must be matched before a result is considered a match |
| 413 | | - minMatchCharLength: 1 |
| 414 | | - }; |
| 415 | | - var BasicOptions = { |
| 416 | | - // When `true`, the algorithm continues searching to the end of the input even if a perfect |
| 417 | | - // match is found before the end of the same input. |
| 418 | | - isCaseSensitive: false, |
| 419 | | - // When true, the matching function will continue to the end of a search pattern even if |
| 420 | | - includeScore: false, |
| 421 | | - // List of properties that will be searched. This also supports nested properties. |
| 422 | | - keys: [], |
| 423 | | - // Whether to sort the result list, by score |
| 424 | | - shouldSort: true, |
| 425 | | - // Default sort function: sort by ascending score, ascending index |
| 426 | | - sortFn: function sortFn(a, b) { |
| 427 | | - return a.score === b.score ? a.idx < b.idx ? -1 : 1 : a.score < b.score ? -1 : 1; |
| 428 | | - } |
| 429 | | - }; |
| 430 | | - var FuzzyOptions = { |
| 431 | | - // Approximately where in the text is the pattern expected to be found? |
| 432 | | - location: 0, |
| 433 | | - // At what point does the match algorithm give up. A threshold of '0.0' requires a perfect match |
| 434 | | - // (of both letters and location), a threshold of '1.0' would match anything. |
| 435 | | - threshold: 0.6, |
| 436 | | - // Determines how close the match must be to the fuzzy location (specified above). |
| 437 | | - // An exact letter match which is 'distance' characters away from the fuzzy location |
| 438 | | - // would score as a complete mismatch. A distance of '0' requires the match be at |
| 439 | | - // the exact location specified, a threshold of '1000' would require a perfect match |
| 440 | | - // to be within 800 characters of the fuzzy location to be found using a 0.8 threshold. |
| 441 | | - distance: 100 |
| 442 | | - }; |
| 443 | | - var AdvancedOptions = { |
| 444 | | - // When `true`, it enables the use of unix-like search commands |
| 445 | | - useExtendedSearch: false, |
| 446 | | - // The get function to use when fetching an object's properties. |
| 447 | | - // The default will search nested paths *ie foo.bar.baz* |
| 448 | | - getFn: get, |
| 449 | | - // When `true`, search will ignore `location` and `distance`, so it won't matter |
| 450 | | - // where in the string the pattern appears. |
| 451 | | - // More info: https://fusejs.io/concepts/scoring-theory.html#fuzziness-score |
| 452 | | - ignoreLocation: false, |
| 453 | | - // When `true`, the calculation for the relevance score (used for sorting) will |
| 454 | | - // ignore the field-length norm. |
| 455 | | - // More info: https://fusejs.io/concepts/scoring-theory.html#field-length-norm |
| 456 | | - ignoreFieldNorm: false, |
| 457 | | - // The weight to determine how much field length norm effects scoring. |
| 458 | | - fieldNormWeight: 1 |
| 459 | | - }; |
| 460 | | - var Config = _objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({}, BasicOptions), MatchOptions), FuzzyOptions), AdvancedOptions); |
| 461 | | - |
| 462 | | - var SPACE = /[^ ]+/g; // Field-length norm: the shorter the field, the higher the weight. |
| 463 | | - // Set to 3 decimals to reduce index size. |
| 464 | | - |
| 465 | | - function norm() { |
| 466 | | - var weight = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; |
| 467 | | - var mantissa = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 3; |
| 468 | | - var cache = new Map(); |
| 469 | | - var m = Math.pow(10, mantissa); |
| 470 | | - return { |
| 471 | | - get: function get(value) { |
| 472 | | - var numTokens = value.match(SPACE).length; |
| 473 | | - |
| 474 | | - if (cache.has(numTokens)) { |
| 475 | | - return cache.get(numTokens); |
| 476 | | - } // Default function is 1/sqrt(x), weight makes that variable |
| 477 | | - |
| 478 | | - |
| 479 | | - var norm = 1 / Math.pow(numTokens, 0.5 * weight); // In place of `toFixed(mantissa)`, for faster computation |
| 480 | | - |
| 481 | | - var n = parseFloat(Math.round(norm * m) / m); |
| 482 | | - cache.set(numTokens, n); |
| 483 | | - return n; |
| 484 | | - }, |
| 485 | | - clear: function clear() { |
| 486 | | - cache.clear(); |
| 487 | | - } |
| 488 | | - }; |
| 489 | | - } |
| 490 | | - |
| 491 | | - var FuseIndex = /*#__PURE__*/function () { |
| 492 | | - function FuseIndex() { |
| 493 | | - var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, |
| 494 | | - _ref$getFn = _ref.getFn, |
| 495 | | - getFn = _ref$getFn === void 0 ? Config.getFn : _ref$getFn, |
| 496 | | - _ref$fieldNormWeight = _ref.fieldNormWeight, |
| 497 | | - fieldNormWeight = _ref$fieldNormWeight === void 0 ? Config.fieldNormWeight : _ref$fieldNormWeight; |
| 498 | | - |
| 499 | | - _classCallCheck(this, FuseIndex); |
| 500 | | - |
| 501 | | - this.norm = norm(fieldNormWeight, 3); |
| 502 | | - this.getFn = getFn; |
| 503 | | - this.isCreated = false; |
| 504 | | - this.setIndexRecords(); |
| 505 | | - } |
| 506 | | - |
| 507 | | - _createClass(FuseIndex, [{ |
| 508 | | - key: "setSources", |
| 509 | | - value: function setSources() { |
| 510 | | - var docs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; |
| 511 | | - this.docs = docs; |
| 512 | | - } |
| 513 | | - }, { |
| 514 | | - key: "setIndexRecords", |
| 515 | | - value: function setIndexRecords() { |
| 516 | | - var records = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; |
| 517 | | - this.records = records; |
| 518 | | - } |
| 519 | | - }, { |
| 520 | | - key: "setKeys", |
| 521 | | - value: function setKeys() { |
| 522 | | - var _this = this; |
| 523 | | - |
| 524 | | - var keys = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; |
| 525 | | - this.keys = keys; |
| 526 | | - this._keysMap = {}; |
| 527 | | - keys.forEach(function (key, idx) { |
| 528 | | - _this._keysMap[key.id] = idx; |
| 529 | | - }); |
| 530 | | - } |
| 531 | | - }, { |
| 532 | | - key: "create", |
| 533 | | - value: function create() { |
| 534 | | - var _this2 = this; |
| 535 | | - |
| 536 | | - if (this.isCreated || !this.docs.length) { |
| 537 | | - return; |
| 538 | | - } |
| 539 | | - |
| 540 | | - this.isCreated = true; // List is Array<String> |
| 541 | | - |
| 542 | | - if (isString(this.docs[0])) { |
| 543 | | - this.docs.forEach(function (doc, docIndex) { |
| 544 | | - _this2._addString(doc, docIndex); |
| 545 | | - }); |
| 546 | | - } else { |
| 547 | | - // List is Array<Object> |
| 548 | | - this.docs.forEach(function (doc, docIndex) { |
| 549 | | - _this2._addObject(doc, docIndex); |
| 550 | | - }); |
| 551 | | - } |
| 552 | | - |
| 553 | | - this.norm.clear(); |
| 554 | | - } // Adds a doc to the end of the index |
| 555 | | - |
| 556 | | - }, { |
| 557 | | - key: "add", |
| 558 | | - value: function add(doc) { |
| 559 | | - var idx = this.size(); |
| 560 | | - |
| 561 | | - if (isString(doc)) { |
| 562 | | - this._addString(doc, idx); |
| 563 | | - } else { |
| 564 | | - this._addObject(doc, idx); |
| 565 | | - } |
| 566 | | - } // Removes the doc at the specified index of the index |
| 567 | | - |
| 568 | | - }, { |
| 569 | | - key: "removeAt", |
| 570 | | - value: function removeAt(idx) { |
| 571 | | - this.records.splice(idx, 1); // Change ref index of every subsquent doc |
| 572 | | - |
| 573 | | - for (var i = idx, len = this.size(); i < len; i += 1) { |
| 574 | | - this.records[i].i -= 1; |
| 575 | | - } |
| 576 | | - } |
| 577 | | - }, { |
| 578 | | - key: "getValueForItemAtKeyId", |
| 579 | | - value: function getValueForItemAtKeyId(item, keyId) { |
| 580 | | - return item[this._keysMap[keyId]]; |
| 581 | | - } |
| 582 | | - }, { |
| 583 | | - key: "size", |
| 584 | | - value: function size() { |
| 585 | | - return this.records.length; |
| 586 | | - } |
| 587 | | - }, { |
| 588 | | - key: "_addString", |
| 589 | | - value: function _addString(doc, docIndex) { |
| 590 | | - if (!isDefined(doc) || isBlank(doc)) { |
| 591 | | - return; |
| 592 | | - } |
| 593 | | - |
| 594 | | - var record = { |
| 595 | | - v: doc, |
| 596 | | - i: docIndex, |
| 597 | | - n: this.norm.get(doc) |
| 598 | | - }; |
| 599 | | - this.records.push(record); |
| 600 | | - } |
| 601 | | - }, { |
| 602 | | - key: "_addObject", |
| 603 | | - value: function _addObject(doc, docIndex) { |
| 604 | | - var _this3 = this; |
| 605 | | - |
| 606 | | - var record = { |
| 607 | | - i: docIndex, |
| 608 | | - $: {} |
| 609 | | - }; // Iterate over every key (i.e, path), and fetch the value at that key |
| 610 | | - |
| 611 | | - this.keys.forEach(function (key, keyIndex) { |
| 612 | | - var value = key.getFn ? key.getFn(doc) : _this3.getFn(doc, key.path); |
| 613 | | - |
| 614 | | - if (!isDefined(value)) { |
| 615 | | - return; |
| 616 | | - } |
| 617 | | - |
| 618 | | - if (isArray(value)) { |
| 619 | | - (function () { |
| 620 | | - var subRecords = []; |
| 621 | | - var stack = [{ |
| 622 | | - nestedArrIndex: -1, |
| 623 | | - value: value |
| 624 | | - }]; |
| 625 | | - |
| 626 | | - while (stack.length) { |
| 627 | | - var _stack$pop = stack.pop(), |
| 628 | | - nestedArrIndex = _stack$pop.nestedArrIndex, |
| 629 | | - _value = _stack$pop.value; |
| 630 | | - |
| 631 | | - if (!isDefined(_value)) { |
| 632 | | - continue; |
| 633 | | - } |
| 634 | | - |
| 635 | | - if (isString(_value) && !isBlank(_value)) { |
| 636 | | - var subRecord = { |
| 637 | | - v: _value, |
| 638 | | - i: nestedArrIndex, |
| 639 | | - n: _this3.norm.get(_value) |
| 640 | | - }; |
| 641 | | - subRecords.push(subRecord); |
| 642 | | - } else if (isArray(_value)) { |
| 643 | | - _value.forEach(function (item, k) { |
| 644 | | - stack.push({ |
| 645 | | - nestedArrIndex: k, |
| 646 | | - value: item |
| 647 | | - }); |
| 648 | | - }); |
| 649 | | - } else ; |
| 650 | | - } |
| 651 | | - |
| 652 | | - record.$[keyIndex] = subRecords; |
| 653 | | - })(); |
| 654 | | - } else if (isString(value) && !isBlank(value)) { |
| 655 | | - var subRecord = { |
| 656 | | - v: value, |
| 657 | | - n: _this3.norm.get(value) |
| 658 | | - }; |
| 659 | | - record.$[keyIndex] = subRecord; |
| 660 | | - } |
| 661 | | - }); |
| 662 | | - this.records.push(record); |
| 663 | | - } |
| 664 | | - }, { |
| 665 | | - key: "toJSON", |
| 666 | | - value: function toJSON() { |
| 667 | | - return { |
| 668 | | - keys: this.keys, |
| 669 | | - records: this.records |
| 670 | | - }; |
| 671 | | - } |
| 672 | | - }]); |
| 673 | | - |
| 674 | | - return FuseIndex; |
| 675 | | - }(); |
| 676 | | - function createIndex(keys, docs) { |
| 677 | | - var _ref2 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, |
| 678 | | - _ref2$getFn = _ref2.getFn, |
| 679 | | - getFn = _ref2$getFn === void 0 ? Config.getFn : _ref2$getFn, |
| 680 | | - _ref2$fieldNormWeight = _ref2.fieldNormWeight, |
| 681 | | - fieldNormWeight = _ref2$fieldNormWeight === void 0 ? Config.fieldNormWeight : _ref2$fieldNormWeight; |
| 682 | | - |
| 683 | | - var myIndex = new FuseIndex({ |
| 684 | | - getFn: getFn, |
| 685 | | - fieldNormWeight: fieldNormWeight |
| 686 | | - }); |
| 687 | | - myIndex.setKeys(keys.map(createKey)); |
| 688 | | - myIndex.setSources(docs); |
| 689 | | - myIndex.create(); |
| 690 | | - return myIndex; |
| 691 | | - } |
| 692 | | - function parseIndex(data) { |
| 693 | | - var _ref3 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, |
| 694 | | - _ref3$getFn = _ref3.getFn, |
| 695 | | - getFn = _ref3$getFn === void 0 ? Config.getFn : _ref3$getFn, |
| 696 | | - _ref3$fieldNormWeight = _ref3.fieldNormWeight, |
| 697 | | - fieldNormWeight = _ref3$fieldNormWeight === void 0 ? Config.fieldNormWeight : _ref3$fieldNormWeight; |
| 698 | | - |
| 699 | | - var keys = data.keys, |
| 700 | | - records = data.records; |
| 701 | | - var myIndex = new FuseIndex({ |
| 702 | | - getFn: getFn, |
| 703 | | - fieldNormWeight: fieldNormWeight |
| 704 | | - }); |
| 705 | | - myIndex.setKeys(keys); |
| 706 | | - myIndex.setIndexRecords(records); |
| 707 | | - return myIndex; |
| 708 | | - } |
| 709 | | - |
| 710 | | - function computeScore$1(pattern) { |
| 711 | | - var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, |
| 712 | | - _ref$errors = _ref.errors, |
| 713 | | - errors = _ref$errors === void 0 ? 0 : _ref$errors, |
| 714 | | - _ref$currentLocation = _ref.currentLocation, |
| 715 | | - currentLocation = _ref$currentLocation === void 0 ? 0 : _ref$currentLocation, |
| 716 | | - _ref$expectedLocation = _ref.expectedLocation, |
| 717 | | - expectedLocation = _ref$expectedLocation === void 0 ? 0 : _ref$expectedLocation, |
| 718 | | - _ref$distance = _ref.distance, |
| 719 | | - distance = _ref$distance === void 0 ? Config.distance : _ref$distance, |
| 720 | | - _ref$ignoreLocation = _ref.ignoreLocation, |
| 721 | | - ignoreLocation = _ref$ignoreLocation === void 0 ? Config.ignoreLocation : _ref$ignoreLocation; |
| 722 | | - |
| 723 | | - var accuracy = errors / pattern.length; |
| 724 | | - |
| 725 | | - if (ignoreLocation) { |
| 726 | | - return accuracy; |
| 727 | | - } |
| 728 | | - |
| 729 | | - var proximity = Math.abs(expectedLocation - currentLocation); |
| 730 | | - |
| 731 | | - if (!distance) { |
| 732 | | - // Dodge divide by zero error. |
| 733 | | - return proximity ? 1.0 : accuracy; |
| 734 | | - } |
| 735 | | - |
| 736 | | - return accuracy + proximity / distance; |
| 737 | | - } |
| 738 | | - |
| 739 | | - function convertMaskToIndices() { |
| 740 | | - var matchmask = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; |
| 741 | | - var minMatchCharLength = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Config.minMatchCharLength; |
| 742 | | - var indices = []; |
| 743 | | - var start = -1; |
| 744 | | - var end = -1; |
| 745 | | - var i = 0; |
| 746 | | - |
| 747 | | - for (var len = matchmask.length; i < len; i += 1) { |
| 748 | | - var match = matchmask[i]; |
| 749 | | - |
| 750 | | - if (match && start === -1) { |
| 751 | | - start = i; |
| 752 | | - } else if (!match && start !== -1) { |
| 753 | | - end = i - 1; |
| 754 | | - |
| 755 | | - if (end - start + 1 >= minMatchCharLength) { |
| 756 | | - indices.push([start, end]); |
| 757 | | - } |
| 758 | | - |
| 759 | | - start = -1; |
| 760 | | - } |
| 761 | | - } // (i-1 - start) + 1 => i - start |
| 762 | | - |
| 763 | | - |
| 764 | | - if (matchmask[i - 1] && i - start >= minMatchCharLength) { |
| 765 | | - indices.push([start, i - 1]); |
| 766 | | - } |
| 767 | | - |
| 768 | | - return indices; |
| 769 | | - } |
| 770 | | - |
| 771 | | - // Machine word size |
| 772 | | - var MAX_BITS = 32; |
| 773 | | - |
| 774 | | - function search(text, pattern, patternAlphabet) { |
| 775 | | - var _ref = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}, |
| 776 | | - _ref$location = _ref.location, |
| 777 | | - location = _ref$location === void 0 ? Config.location : _ref$location, |
| 778 | | - _ref$distance = _ref.distance, |
| 779 | | - distance = _ref$distance === void 0 ? Config.distance : _ref$distance, |
| 780 | | - _ref$threshold = _ref.threshold, |
| 781 | | - threshold = _ref$threshold === void 0 ? Config.threshold : _ref$threshold, |
| 782 | | - _ref$findAllMatches = _ref.findAllMatches, |
| 783 | | - findAllMatches = _ref$findAllMatches === void 0 ? Config.findAllMatches : _ref$findAllMatches, |
| 784 | | - _ref$minMatchCharLeng = _ref.minMatchCharLength, |
| 785 | | - minMatchCharLength = _ref$minMatchCharLeng === void 0 ? Config.minMatchCharLength : _ref$minMatchCharLeng, |
| 786 | | - _ref$includeMatches = _ref.includeMatches, |
| 787 | | - includeMatches = _ref$includeMatches === void 0 ? Config.includeMatches : _ref$includeMatches, |
| 788 | | - _ref$ignoreLocation = _ref.ignoreLocation, |
| 789 | | - ignoreLocation = _ref$ignoreLocation === void 0 ? Config.ignoreLocation : _ref$ignoreLocation; |
| 790 | | - |
| 791 | | - if (pattern.length > MAX_BITS) { |
| 792 | | - throw new Error(PATTERN_LENGTH_TOO_LARGE(MAX_BITS)); |
| 793 | | - } |
| 794 | | - |
| 795 | | - var patternLen = pattern.length; // Set starting location at beginning text and initialize the alphabet. |
| 796 | | - |
| 797 | | - var textLen = text.length; // Handle the case when location > text.length |
| 798 | | - |
| 799 | | - var expectedLocation = Math.max(0, Math.min(location, textLen)); // Highest score beyond which we give up. |
| 800 | | - |
| 801 | | - var currentThreshold = threshold; // Is there a nearby exact match? (speedup) |
| 802 | | - |
| 803 | | - var bestLocation = expectedLocation; // Performance: only computer matches when the minMatchCharLength > 1 |
| 804 | | - // OR if `includeMatches` is true. |
| 805 | | - |
| 806 | | - var computeMatches = minMatchCharLength > 1 || includeMatches; // A mask of the matches, used for building the indices |
| 807 | | - |
| 808 | | - var matchMask = computeMatches ? Array(textLen) : []; |
| 809 | | - var index; // Get all exact matches, here for speed up |
| 810 | | - |
| 811 | | - while ((index = text.indexOf(pattern, bestLocation)) > -1) { |
| 812 | | - var score = computeScore$1(pattern, { |
| 813 | | - currentLocation: index, |
| 814 | | - expectedLocation: expectedLocation, |
| 815 | | - distance: distance, |
| 816 | | - ignoreLocation: ignoreLocation |
| 817 | | - }); |
| 818 | | - currentThreshold = Math.min(score, currentThreshold); |
| 819 | | - bestLocation = index + patternLen; |
| 820 | | - |
| 821 | | - if (computeMatches) { |
| 822 | | - var i = 0; |
| 823 | | - |
| 824 | | - while (i < patternLen) { |
| 825 | | - matchMask[index + i] = 1; |
| 826 | | - i += 1; |
| 827 | | - } |
| 828 | | - } |
| 829 | | - } // Reset the best location |
| 830 | | - |
| 831 | | - |
| 832 | | - bestLocation = -1; |
| 833 | | - var lastBitArr = []; |
| 834 | | - var finalScore = 1; |
| 835 | | - var binMax = patternLen + textLen; |
| 836 | | - var mask = 1 << patternLen - 1; |
| 837 | | - |
| 838 | | - for (var _i = 0; _i < patternLen; _i += 1) { |
| 839 | | - // Scan for the best match; each iteration allows for one more error. |
| 840 | | - // Run a binary search to determine how far from the match location we can stray |
| 841 | | - // at this error level. |
| 842 | | - var binMin = 0; |
| 843 | | - var binMid = binMax; |
| 844 | | - |
| 845 | | - while (binMin < binMid) { |
| 846 | | - var _score2 = computeScore$1(pattern, { |
| 847 | | - errors: _i, |
| 848 | | - currentLocation: expectedLocation + binMid, |
| 849 | | - expectedLocation: expectedLocation, |
| 850 | | - distance: distance, |
| 851 | | - ignoreLocation: ignoreLocation |
| 852 | | - }); |
| 853 | | - |
| 854 | | - if (_score2 <= currentThreshold) { |
| 855 | | - binMin = binMid; |
| 856 | | - } else { |
| 857 | | - binMax = binMid; |
| 858 | | - } |
| 859 | | - |
| 860 | | - binMid = Math.floor((binMax - binMin) / 2 + binMin); |
| 861 | | - } // Use the result from this iteration as the maximum for the next. |
| 862 | | - |
| 863 | | - |
| 864 | | - binMax = binMid; |
| 865 | | - var start = Math.max(1, expectedLocation - binMid + 1); |
| 866 | | - var finish = findAllMatches ? textLen : Math.min(expectedLocation + binMid, textLen) + patternLen; // Initialize the bit array |
| 867 | | - |
| 868 | | - var bitArr = Array(finish + 2); |
| 869 | | - bitArr[finish + 1] = (1 << _i) - 1; |
| 870 | | - |
| 871 | | - for (var j = finish; j >= start; j -= 1) { |
| 872 | | - var currentLocation = j - 1; |
| 873 | | - var charMatch = patternAlphabet[text.charAt(currentLocation)]; |
| 874 | | - |
| 875 | | - if (computeMatches) { |
| 876 | | - // Speed up: quick bool to int conversion (i.e, `charMatch ? 1 : 0`) |
| 877 | | - matchMask[currentLocation] = +!!charMatch; |
| 878 | | - } // First pass: exact match |
| 879 | | - |
| 880 | | - |
| 881 | | - bitArr[j] = (bitArr[j + 1] << 1 | 1) & charMatch; // Subsequent passes: fuzzy match |
| 882 | | - |
| 883 | | - if (_i) { |
| 884 | | - bitArr[j] |= (lastBitArr[j + 1] | lastBitArr[j]) << 1 | 1 | lastBitArr[j + 1]; |
| 885 | | - } |
| 886 | | - |
| 887 | | - if (bitArr[j] & mask) { |
| 888 | | - finalScore = computeScore$1(pattern, { |
| 889 | | - errors: _i, |
| 890 | | - currentLocation: currentLocation, |
| 891 | | - expectedLocation: expectedLocation, |
| 892 | | - distance: distance, |
| 893 | | - ignoreLocation: ignoreLocation |
| 894 | | - }); // This match will almost certainly be better than any existing match. |
| 895 | | - // But check anyway. |
| 896 | | - |
| 897 | | - if (finalScore <= currentThreshold) { |
| 898 | | - // Indeed it is |
| 899 | | - currentThreshold = finalScore; |
| 900 | | - bestLocation = currentLocation; // Already passed `loc`, downhill from here on in. |
| 901 | | - |
| 902 | | - if (bestLocation <= expectedLocation) { |
| 903 | | - break; |
| 904 | | - } // When passing `bestLocation`, don't exceed our current distance from `expectedLocation`. |
| 905 | | - |
| 906 | | - |
| 907 | | - start = Math.max(1, 2 * expectedLocation - bestLocation); |
| 908 | | - } |
| 909 | | - } |
| 910 | | - } // No hope for a (better) match at greater error levels. |
| 911 | | - |
| 912 | | - |
| 913 | | - var _score = computeScore$1(pattern, { |
| 914 | | - errors: _i + 1, |
| 915 | | - currentLocation: expectedLocation, |
| 916 | | - expectedLocation: expectedLocation, |
| 917 | | - distance: distance, |
| 918 | | - ignoreLocation: ignoreLocation |
| 919 | | - }); |
| 920 | | - |
| 921 | | - if (_score > currentThreshold) { |
| 922 | | - break; |
| 923 | | - } |
| 924 | | - |
| 925 | | - lastBitArr = bitArr; |
| 926 | | - } |
| 927 | | - |
| 928 | | - var result = { |
| 929 | | - isMatch: bestLocation >= 0, |
| 930 | | - // Count exact matches (those with a score of 0) to be "almost" exact |
| 931 | | - score: Math.max(0.001, finalScore) |
| 932 | | - }; |
| 933 | | - |
| 934 | | - if (computeMatches) { |
| 935 | | - var indices = convertMaskToIndices(matchMask, minMatchCharLength); |
| 936 | | - |
| 937 | | - if (!indices.length) { |
| 938 | | - result.isMatch = false; |
| 939 | | - } else if (includeMatches) { |
| 940 | | - result.indices = indices; |
| 941 | | - } |
| 942 | | - } |
| 943 | | - |
| 944 | | - return result; |
| 945 | | - } |
| 946 | | - |
| 947 | | - function createPatternAlphabet(pattern) { |
| 948 | | - var mask = {}; |
| 949 | | - |
| 950 | | - for (var i = 0, len = pattern.length; i < len; i += 1) { |
| 951 | | - var _char = pattern.charAt(i); |
| 952 | | - |
| 953 | | - mask[_char] = (mask[_char] || 0) | 1 << len - i - 1; |
| 954 | | - } |
| 955 | | - |
| 956 | | - return mask; |
| 957 | | - } |
| 958 | | - |
| 959 | | - var BitapSearch = /*#__PURE__*/function () { |
| 960 | | - function BitapSearch(pattern) { |
| 961 | | - var _this = this; |
| 962 | | - |
| 963 | | - var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, |
| 964 | | - _ref$location = _ref.location, |
| 965 | | - location = _ref$location === void 0 ? Config.location : _ref$location, |
| 966 | | - _ref$threshold = _ref.threshold, |
| 967 | | - threshold = _ref$threshold === void 0 ? Config.threshold : _ref$threshold, |
| 968 | | - _ref$distance = _ref.distance, |
| 969 | | - distance = _ref$distance === void 0 ? Config.distance : _ref$distance, |
| 970 | | - _ref$includeMatches = _ref.includeMatches, |
| 971 | | - includeMatches = _ref$includeMatches === void 0 ? Config.includeMatches : _ref$includeMatches, |
| 972 | | - _ref$findAllMatches = _ref.findAllMatches, |
| 973 | | - findAllMatches = _ref$findAllMatches === void 0 ? Config.findAllMatches : _ref$findAllMatches, |
| 974 | | - _ref$minMatchCharLeng = _ref.minMatchCharLength, |
| 975 | | - minMatchCharLength = _ref$minMatchCharLeng === void 0 ? Config.minMatchCharLength : _ref$minMatchCharLeng, |
| 976 | | - _ref$isCaseSensitive = _ref.isCaseSensitive, |
| 977 | | - isCaseSensitive = _ref$isCaseSensitive === void 0 ? Config.isCaseSensitive : _ref$isCaseSensitive, |
| 978 | | - _ref$ignoreLocation = _ref.ignoreLocation, |
| 979 | | - ignoreLocation = _ref$ignoreLocation === void 0 ? Config.ignoreLocation : _ref$ignoreLocation; |
| 980 | | - |
| 981 | | - _classCallCheck(this, BitapSearch); |
| 982 | | - |
| 983 | | - this.options = { |
| 984 | | - location: location, |
| 985 | | - threshold: threshold, |
| 986 | | - distance: distance, |
| 987 | | - includeMatches: includeMatches, |
| 988 | | - findAllMatches: findAllMatches, |
| 989 | | - minMatchCharLength: minMatchCharLength, |
| 990 | | - isCaseSensitive: isCaseSensitive, |
| 991 | | - ignoreLocation: ignoreLocation |
| 992 | | - }; |
| 993 | | - this.pattern = isCaseSensitive ? pattern : pattern.toLowerCase(); |
| 994 | | - this.chunks = []; |
| 995 | | - |
| 996 | | - if (!this.pattern.length) { |
| 997 | | - return; |
| 998 | | - } |
| 999 | | - |
| 1000 | | - var addChunk = function addChunk(pattern, startIndex) { |
| 1001 | | - _this.chunks.push({ |
| 1002 | | - pattern: pattern, |
| 1003 | | - alphabet: createPatternAlphabet(pattern), |
| 1004 | | - startIndex: startIndex |
| 1005 | | - }); |
| 1006 | | - }; |
| 1007 | | - |
| 1008 | | - var len = this.pattern.length; |
| 1009 | | - |
| 1010 | | - if (len > MAX_BITS) { |
| 1011 | | - var i = 0; |
| 1012 | | - var remainder = len % MAX_BITS; |
| 1013 | | - var end = len - remainder; |
| 1014 | | - |
| 1015 | | - while (i < end) { |
| 1016 | | - addChunk(this.pattern.substr(i, MAX_BITS), i); |
| 1017 | | - i += MAX_BITS; |
| 1018 | | - } |
| 1019 | | - |
| 1020 | | - if (remainder) { |
| 1021 | | - var startIndex = len - MAX_BITS; |
| 1022 | | - addChunk(this.pattern.substr(startIndex), startIndex); |
| 1023 | | - } |
| 1024 | | - } else { |
| 1025 | | - addChunk(this.pattern, 0); |
| 1026 | | - } |
| 1027 | | - } |
| 1028 | | - |
| 1029 | | - _createClass(BitapSearch, [{ |
| 1030 | | - key: "searchIn", |
| 1031 | | - value: function searchIn(text) { |
| 1032 | | - var _this$options = this.options, |
| 1033 | | - isCaseSensitive = _this$options.isCaseSensitive, |
| 1034 | | - includeMatches = _this$options.includeMatches; |
| 1035 | | - |
| 1036 | | - if (!isCaseSensitive) { |
| 1037 | | - text = text.toLowerCase(); |
| 1038 | | - } // Exact match |
| 1039 | | - |
| 1040 | | - |
| 1041 | | - if (this.pattern === text) { |
| 1042 | | - var _result = { |
| 1043 | | - isMatch: true, |
| 1044 | | - score: 0 |
| 1045 | | - }; |
| 1046 | | - |
| 1047 | | - if (includeMatches) { |
| 1048 | | - _result.indices = [[0, text.length - 1]]; |
| 1049 | | - } |
| 1050 | | - |
| 1051 | | - return _result; |
| 1052 | | - } // Otherwise, use Bitap algorithm |
| 1053 | | - |
| 1054 | | - |
| 1055 | | - var _this$options2 = this.options, |
| 1056 | | - location = _this$options2.location, |
| 1057 | | - distance = _this$options2.distance, |
| 1058 | | - threshold = _this$options2.threshold, |
| 1059 | | - findAllMatches = _this$options2.findAllMatches, |
| 1060 | | - minMatchCharLength = _this$options2.minMatchCharLength, |
| 1061 | | - ignoreLocation = _this$options2.ignoreLocation; |
| 1062 | | - var allIndices = []; |
| 1063 | | - var totalScore = 0; |
| 1064 | | - var hasMatches = false; |
| 1065 | | - this.chunks.forEach(function (_ref2) { |
| 1066 | | - var pattern = _ref2.pattern, |
| 1067 | | - alphabet = _ref2.alphabet, |
| 1068 | | - startIndex = _ref2.startIndex; |
| 1069 | | - |
| 1070 | | - var _search = search(text, pattern, alphabet, { |
| 1071 | | - location: location + startIndex, |
| 1072 | | - distance: distance, |
| 1073 | | - threshold: threshold, |
| 1074 | | - findAllMatches: findAllMatches, |
| 1075 | | - minMatchCharLength: minMatchCharLength, |
| 1076 | | - includeMatches: includeMatches, |
| 1077 | | - ignoreLocation: ignoreLocation |
| 1078 | | - }), |
| 1079 | | - isMatch = _search.isMatch, |
| 1080 | | - score = _search.score, |
| 1081 | | - indices = _search.indices; |
| 1082 | | - |
| 1083 | | - if (isMatch) { |
| 1084 | | - hasMatches = true; |
| 1085 | | - } |
| 1086 | | - |
| 1087 | | - totalScore += score; |
| 1088 | | - |
| 1089 | | - if (isMatch && indices) { |
| 1090 | | - allIndices = [].concat(_toConsumableArray(allIndices), _toConsumableArray(indices)); |
| 1091 | | - } |
| 1092 | | - }); |
| 1093 | | - var result = { |
| 1094 | | - isMatch: hasMatches, |
| 1095 | | - score: hasMatches ? totalScore / this.chunks.length : 1 |
| 1096 | | - }; |
| 1097 | | - |
| 1098 | | - if (hasMatches && includeMatches) { |
| 1099 | | - result.indices = allIndices; |
| 1100 | | - } |
| 1101 | | - |
| 1102 | | - return result; |
| 1103 | | - } |
| 1104 | | - }]); |
| 1105 | | - |
| 1106 | | - return BitapSearch; |
| 1107 | | - }(); |
| 1108 | | - |
| 1109 | | - var BaseMatch = /*#__PURE__*/function () { |
| 1110 | | - function BaseMatch(pattern) { |
| 1111 | | - _classCallCheck(this, BaseMatch); |
| 1112 | | - |
| 1113 | | - this.pattern = pattern; |
| 1114 | | - } |
| 1115 | | - |
| 1116 | | - _createClass(BaseMatch, [{ |
| 1117 | | - key: "search", |
| 1118 | | - value: function |
| 1119 | | - /*text*/ |
| 1120 | | - search() {} |
| 1121 | | - }], [{ |
| 1122 | | - key: "isMultiMatch", |
| 1123 | | - value: function isMultiMatch(pattern) { |
| 1124 | | - return getMatch(pattern, this.multiRegex); |
| 1125 | | - } |
| 1126 | | - }, { |
| 1127 | | - key: "isSingleMatch", |
| 1128 | | - value: function isSingleMatch(pattern) { |
| 1129 | | - return getMatch(pattern, this.singleRegex); |
| 1130 | | - } |
| 1131 | | - }]); |
| 1132 | | - |
| 1133 | | - return BaseMatch; |
| 1134 | | - }(); |
| 1135 | | - |
| 1136 | | - function getMatch(pattern, exp) { |
| 1137 | | - var matches = pattern.match(exp); |
| 1138 | | - return matches ? matches[1] : null; |
| 1139 | | - } |
| 1140 | | - |
| 1141 | | - var ExactMatch = /*#__PURE__*/function (_BaseMatch) { |
| 1142 | | - _inherits(ExactMatch, _BaseMatch); |
| 1143 | | - |
| 1144 | | - var _super = _createSuper(ExactMatch); |
| 1145 | | - |
| 1146 | | - function ExactMatch(pattern) { |
| 1147 | | - _classCallCheck(this, ExactMatch); |
| 1148 | | - |
| 1149 | | - return _super.call(this, pattern); |
| 1150 | | - } |
| 1151 | | - |
| 1152 | | - _createClass(ExactMatch, [{ |
| 1153 | | - key: "search", |
| 1154 | | - value: function search(text) { |
| 1155 | | - var isMatch = text === this.pattern; |
| 1156 | | - return { |
| 1157 | | - isMatch: isMatch, |
| 1158 | | - score: isMatch ? 0 : 1, |
| 1159 | | - indices: [0, this.pattern.length - 1] |
| 1160 | | - }; |
| 1161 | | - } |
| 1162 | | - }], [{ |
| 1163 | | - key: "type", |
| 1164 | | - get: function get() { |
| 1165 | | - return 'exact'; |
| 1166 | | - } |
| 1167 | | - }, { |
| 1168 | | - key: "multiRegex", |
| 1169 | | - get: function get() { |
| 1170 | | - return /^="(.*)"$/; |
| 1171 | | - } |
| 1172 | | - }, { |
| 1173 | | - key: "singleRegex", |
| 1174 | | - get: function get() { |
| 1175 | | - return /^=(.*)$/; |
| 1176 | | - } |
| 1177 | | - }]); |
| 1178 | | - |
| 1179 | | - return ExactMatch; |
| 1180 | | - }(BaseMatch); |
| 1181 | | - |
| 1182 | | - var InverseExactMatch = /*#__PURE__*/function (_BaseMatch) { |
| 1183 | | - _inherits(InverseExactMatch, _BaseMatch); |
| 1184 | | - |
| 1185 | | - var _super = _createSuper(InverseExactMatch); |
| 1186 | | - |
| 1187 | | - function InverseExactMatch(pattern) { |
| 1188 | | - _classCallCheck(this, InverseExactMatch); |
| 1189 | | - |
| 1190 | | - return _super.call(this, pattern); |
| 1191 | | - } |
| 1192 | | - |
| 1193 | | - _createClass(InverseExactMatch, [{ |
| 1194 | | - key: "search", |
| 1195 | | - value: function search(text) { |
| 1196 | | - var index = text.indexOf(this.pattern); |
| 1197 | | - var isMatch = index === -1; |
| 1198 | | - return { |
| 1199 | | - isMatch: isMatch, |
| 1200 | | - score: isMatch ? 0 : 1, |
| 1201 | | - indices: [0, text.length - 1] |
| 1202 | | - }; |
| 1203 | | - } |
| 1204 | | - }], [{ |
| 1205 | | - key: "type", |
| 1206 | | - get: function get() { |
| 1207 | | - return 'inverse-exact'; |
| 1208 | | - } |
| 1209 | | - }, { |
| 1210 | | - key: "multiRegex", |
| 1211 | | - get: function get() { |
| 1212 | | - return /^!"(.*)"$/; |
| 1213 | | - } |
| 1214 | | - }, { |
| 1215 | | - key: "singleRegex", |
| 1216 | | - get: function get() { |
| 1217 | | - return /^!(.*)$/; |
| 1218 | | - } |
| 1219 | | - }]); |
| 1220 | | - |
| 1221 | | - return InverseExactMatch; |
| 1222 | | - }(BaseMatch); |
| 1223 | | - |
| 1224 | | - var PrefixExactMatch = /*#__PURE__*/function (_BaseMatch) { |
| 1225 | | - _inherits(PrefixExactMatch, _BaseMatch); |
| 1226 | | - |
| 1227 | | - var _super = _createSuper(PrefixExactMatch); |
| 1228 | | - |
| 1229 | | - function PrefixExactMatch(pattern) { |
| 1230 | | - _classCallCheck(this, PrefixExactMatch); |
| 1231 | | - |
| 1232 | | - return _super.call(this, pattern); |
| 1233 | | - } |
| 1234 | | - |
| 1235 | | - _createClass(PrefixExactMatch, [{ |
| 1236 | | - key: "search", |
| 1237 | | - value: function search(text) { |
| 1238 | | - var isMatch = text.startsWith(this.pattern); |
| 1239 | | - return { |
| 1240 | | - isMatch: isMatch, |
| 1241 | | - score: isMatch ? 0 : 1, |
| 1242 | | - indices: [0, this.pattern.length - 1] |
| 1243 | | - }; |
| 1244 | | - } |
| 1245 | | - }], [{ |
| 1246 | | - key: "type", |
| 1247 | | - get: function get() { |
| 1248 | | - return 'prefix-exact'; |
| 1249 | | - } |
| 1250 | | - }, { |
| 1251 | | - key: "multiRegex", |
| 1252 | | - get: function get() { |
| 1253 | | - return /^\^"(.*)"$/; |
| 1254 | | - } |
| 1255 | | - }, { |
| 1256 | | - key: "singleRegex", |
| 1257 | | - get: function get() { |
| 1258 | | - return /^\^(.*)$/; |
| 1259 | | - } |
| 1260 | | - }]); |
| 1261 | | - |
| 1262 | | - return PrefixExactMatch; |
| 1263 | | - }(BaseMatch); |
| 1264 | | - |
| 1265 | | - var InversePrefixExactMatch = /*#__PURE__*/function (_BaseMatch) { |
| 1266 | | - _inherits(InversePrefixExactMatch, _BaseMatch); |
| 1267 | | - |
| 1268 | | - var _super = _createSuper(InversePrefixExactMatch); |
| 1269 | | - |
| 1270 | | - function InversePrefixExactMatch(pattern) { |
| 1271 | | - _classCallCheck(this, InversePrefixExactMatch); |
| 1272 | | - |
| 1273 | | - return _super.call(this, pattern); |
| 1274 | | - } |
| 1275 | | - |
| 1276 | | - _createClass(InversePrefixExactMatch, [{ |
| 1277 | | - key: "search", |
| 1278 | | - value: function search(text) { |
| 1279 | | - var isMatch = !text.startsWith(this.pattern); |
| 1280 | | - return { |
| 1281 | | - isMatch: isMatch, |
| 1282 | | - score: isMatch ? 0 : 1, |
| 1283 | | - indices: [0, text.length - 1] |
| 1284 | | - }; |
| 1285 | | - } |
| 1286 | | - }], [{ |
| 1287 | | - key: "type", |
| 1288 | | - get: function get() { |
| 1289 | | - return 'inverse-prefix-exact'; |
| 1290 | | - } |
| 1291 | | - }, { |
| 1292 | | - key: "multiRegex", |
| 1293 | | - get: function get() { |
| 1294 | | - return /^!\^"(.*)"$/; |
| 1295 | | - } |
| 1296 | | - }, { |
| 1297 | | - key: "singleRegex", |
| 1298 | | - get: function get() { |
| 1299 | | - return /^!\^(.*)$/; |
| 1300 | | - } |
| 1301 | | - }]); |
| 1302 | | - |
| 1303 | | - return InversePrefixExactMatch; |
| 1304 | | - }(BaseMatch); |
| 1305 | | - |
| 1306 | | - var SuffixExactMatch = /*#__PURE__*/function (_BaseMatch) { |
| 1307 | | - _inherits(SuffixExactMatch, _BaseMatch); |
| 1308 | | - |
| 1309 | | - var _super = _createSuper(SuffixExactMatch); |
| 1310 | | - |
| 1311 | | - function SuffixExactMatch(pattern) { |
| 1312 | | - _classCallCheck(this, SuffixExactMatch); |
| 1313 | | - |
| 1314 | | - return _super.call(this, pattern); |
| 1315 | | - } |
| 1316 | | - |
| 1317 | | - _createClass(SuffixExactMatch, [{ |
| 1318 | | - key: "search", |
| 1319 | | - value: function search(text) { |
| 1320 | | - var isMatch = text.endsWith(this.pattern); |
| 1321 | | - return { |
| 1322 | | - isMatch: isMatch, |
| 1323 | | - score: isMatch ? 0 : 1, |
| 1324 | | - indices: [text.length - this.pattern.length, text.length - 1] |
| 1325 | | - }; |
| 1326 | | - } |
| 1327 | | - }], [{ |
| 1328 | | - key: "type", |
| 1329 | | - get: function get() { |
| 1330 | | - return 'suffix-exact'; |
| 1331 | | - } |
| 1332 | | - }, { |
| 1333 | | - key: "multiRegex", |
| 1334 | | - get: function get() { |
| 1335 | | - return /^"(.*)"\$$/; |
| 1336 | | - } |
| 1337 | | - }, { |
| 1338 | | - key: "singleRegex", |
| 1339 | | - get: function get() { |
| 1340 | | - return /^(.*)\$$/; |
| 1341 | | - } |
| 1342 | | - }]); |
| 1343 | | - |
| 1344 | | - return SuffixExactMatch; |
| 1345 | | - }(BaseMatch); |
| 1346 | | - |
| 1347 | | - var InverseSuffixExactMatch = /*#__PURE__*/function (_BaseMatch) { |
| 1348 | | - _inherits(InverseSuffixExactMatch, _BaseMatch); |
| 1349 | | - |
| 1350 | | - var _super = _createSuper(InverseSuffixExactMatch); |
| 1351 | | - |
| 1352 | | - function InverseSuffixExactMatch(pattern) { |
| 1353 | | - _classCallCheck(this, InverseSuffixExactMatch); |
| 1354 | | - |
| 1355 | | - return _super.call(this, pattern); |
| 1356 | | - } |
| 1357 | | - |
| 1358 | | - _createClass(InverseSuffixExactMatch, [{ |
| 1359 | | - key: "search", |
| 1360 | | - value: function search(text) { |
| 1361 | | - var isMatch = !text.endsWith(this.pattern); |
| 1362 | | - return { |
| 1363 | | - isMatch: isMatch, |
| 1364 | | - score: isMatch ? 0 : 1, |
| 1365 | | - indices: [0, text.length - 1] |
| 1366 | | - }; |
| 1367 | | - } |
| 1368 | | - }], [{ |
| 1369 | | - key: "type", |
| 1370 | | - get: function get() { |
| 1371 | | - return 'inverse-suffix-exact'; |
| 1372 | | - } |
| 1373 | | - }, { |
| 1374 | | - key: "multiRegex", |
| 1375 | | - get: function get() { |
| 1376 | | - return /^!"(.*)"\$$/; |
| 1377 | | - } |
| 1378 | | - }, { |
| 1379 | | - key: "singleRegex", |
| 1380 | | - get: function get() { |
| 1381 | | - return /^!(.*)\$$/; |
| 1382 | | - } |
| 1383 | | - }]); |
| 1384 | | - |
| 1385 | | - return InverseSuffixExactMatch; |
| 1386 | | - }(BaseMatch); |
| 1387 | | - |
| 1388 | | - var FuzzyMatch = /*#__PURE__*/function (_BaseMatch) { |
| 1389 | | - _inherits(FuzzyMatch, _BaseMatch); |
| 1390 | | - |
| 1391 | | - var _super = _createSuper(FuzzyMatch); |
| 1392 | | - |
| 1393 | | - function FuzzyMatch(pattern) { |
| 1394 | | - var _this; |
| 1395 | | - |
| 1396 | | - var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, |
| 1397 | | - _ref$location = _ref.location, |
| 1398 | | - location = _ref$location === void 0 ? Config.location : _ref$location, |
| 1399 | | - _ref$threshold = _ref.threshold, |
| 1400 | | - threshold = _ref$threshold === void 0 ? Config.threshold : _ref$threshold, |
| 1401 | | - _ref$distance = _ref.distance, |
| 1402 | | - distance = _ref$distance === void 0 ? Config.distance : _ref$distance, |
| 1403 | | - _ref$includeMatches = _ref.includeMatches, |
| 1404 | | - includeMatches = _ref$includeMatches === void 0 ? Config.includeMatches : _ref$includeMatches, |
| 1405 | | - _ref$findAllMatches = _ref.findAllMatches, |
| 1406 | | - findAllMatches = _ref$findAllMatches === void 0 ? Config.findAllMatches : _ref$findAllMatches, |
| 1407 | | - _ref$minMatchCharLeng = _ref.minMatchCharLength, |
| 1408 | | - minMatchCharLength = _ref$minMatchCharLeng === void 0 ? Config.minMatchCharLength : _ref$minMatchCharLeng, |
| 1409 | | - _ref$isCaseSensitive = _ref.isCaseSensitive, |
| 1410 | | - isCaseSensitive = _ref$isCaseSensitive === void 0 ? Config.isCaseSensitive : _ref$isCaseSensitive, |
| 1411 | | - _ref$ignoreLocation = _ref.ignoreLocation, |
| 1412 | | - ignoreLocation = _ref$ignoreLocation === void 0 ? Config.ignoreLocation : _ref$ignoreLocation; |
| 1413 | | - |
| 1414 | | - _classCallCheck(this, FuzzyMatch); |
| 1415 | | - |
| 1416 | | - _this = _super.call(this, pattern); |
| 1417 | | - _this._bitapSearch = new BitapSearch(pattern, { |
| 1418 | | - location: location, |
| 1419 | | - threshold: threshold, |
| 1420 | | - distance: distance, |
| 1421 | | - includeMatches: includeMatches, |
| 1422 | | - findAllMatches: findAllMatches, |
| 1423 | | - minMatchCharLength: minMatchCharLength, |
| 1424 | | - isCaseSensitive: isCaseSensitive, |
| 1425 | | - ignoreLocation: ignoreLocation |
| 1426 | | - }); |
| 1427 | | - return _this; |
| 1428 | | - } |
| 1429 | | - |
| 1430 | | - _createClass(FuzzyMatch, [{ |
| 1431 | | - key: "search", |
| 1432 | | - value: function search(text) { |
| 1433 | | - return this._bitapSearch.searchIn(text); |
| 1434 | | - } |
| 1435 | | - }], [{ |
| 1436 | | - key: "type", |
| 1437 | | - get: function get() { |
| 1438 | | - return 'fuzzy'; |
| 1439 | | - } |
| 1440 | | - }, { |
| 1441 | | - key: "multiRegex", |
| 1442 | | - get: function get() { |
| 1443 | | - return /^"(.*)"$/; |
| 1444 | | - } |
| 1445 | | - }, { |
| 1446 | | - key: "singleRegex", |
| 1447 | | - get: function get() { |
| 1448 | | - return /^(.*)$/; |
| 1449 | | - } |
| 1450 | | - }]); |
| 1451 | | - |
| 1452 | | - return FuzzyMatch; |
| 1453 | | - }(BaseMatch); |
| 1454 | | - |
| 1455 | | - var IncludeMatch = /*#__PURE__*/function (_BaseMatch) { |
| 1456 | | - _inherits(IncludeMatch, _BaseMatch); |
| 1457 | | - |
| 1458 | | - var _super = _createSuper(IncludeMatch); |
| 1459 | | - |
| 1460 | | - function IncludeMatch(pattern) { |
| 1461 | | - _classCallCheck(this, IncludeMatch); |
| 1462 | | - |
| 1463 | | - return _super.call(this, pattern); |
| 1464 | | - } |
| 1465 | | - |
| 1466 | | - _createClass(IncludeMatch, [{ |
| 1467 | | - key: "search", |
| 1468 | | - value: function search(text) { |
| 1469 | | - var location = 0; |
| 1470 | | - var index; |
| 1471 | | - var indices = []; |
| 1472 | | - var patternLen = this.pattern.length; // Get all exact matches |
| 1473 | | - |
| 1474 | | - while ((index = text.indexOf(this.pattern, location)) > -1) { |
| 1475 | | - location = index + patternLen; |
| 1476 | | - indices.push([index, location - 1]); |
| 1477 | | - } |
| 1478 | | - |
| 1479 | | - var isMatch = !!indices.length; |
| 1480 | | - return { |
| 1481 | | - isMatch: isMatch, |
| 1482 | | - score: isMatch ? 0 : 1, |
| 1483 | | - indices: indices |
| 1484 | | - }; |
| 1485 | | - } |
| 1486 | | - }], [{ |
| 1487 | | - key: "type", |
| 1488 | | - get: function get() { |
| 1489 | | - return 'include'; |
| 1490 | | - } |
| 1491 | | - }, { |
| 1492 | | - key: "multiRegex", |
| 1493 | | - get: function get() { |
| 1494 | | - return /^'"(.*)"$/; |
| 1495 | | - } |
| 1496 | | - }, { |
| 1497 | | - key: "singleRegex", |
| 1498 | | - get: function get() { |
| 1499 | | - return /^'(.*)$/; |
| 1500 | | - } |
| 1501 | | - }]); |
| 1502 | | - |
| 1503 | | - return IncludeMatch; |
| 1504 | | - }(BaseMatch); |
| 1505 | | - |
| 1506 | | - var searchers = [ExactMatch, IncludeMatch, PrefixExactMatch, InversePrefixExactMatch, InverseSuffixExactMatch, SuffixExactMatch, InverseExactMatch, FuzzyMatch]; |
| 1507 | | - var searchersLen = searchers.length; // Regex to split by spaces, but keep anything in quotes together |
| 1508 | | - |
| 1509 | | - var SPACE_RE = / +(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/; |
| 1510 | | - var OR_TOKEN = '|'; // Return a 2D array representation of the query, for simpler parsing. |
| 1511 | | - // Example: |
| 1512 | | - // "^core go$ | rb$ | py$ xy$" => [["^core", "go$"], ["rb$"], ["py$", "xy$"]] |
| 1513 | | - |
| 1514 | | - function parseQuery(pattern) { |
| 1515 | | - var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; |
| 1516 | | - return pattern.split(OR_TOKEN).map(function (item) { |
| 1517 | | - var query = item.trim().split(SPACE_RE).filter(function (item) { |
| 1518 | | - return item && !!item.trim(); |
| 1519 | | - }); |
| 1520 | | - var results = []; |
| 1521 | | - |
| 1522 | | - for (var i = 0, len = query.length; i < len; i += 1) { |
| 1523 | | - var queryItem = query[i]; // 1. Handle multiple query match (i.e, once that are quoted, like `"hello world"`) |
| 1524 | | - |
| 1525 | | - var found = false; |
| 1526 | | - var idx = -1; |
| 1527 | | - |
| 1528 | | - while (!found && ++idx < searchersLen) { |
| 1529 | | - var searcher = searchers[idx]; |
| 1530 | | - var token = searcher.isMultiMatch(queryItem); |
| 1531 | | - |
| 1532 | | - if (token) { |
| 1533 | | - results.push(new searcher(token, options)); |
| 1534 | | - found = true; |
| 1535 | | - } |
| 1536 | | - } |
| 1537 | | - |
| 1538 | | - if (found) { |
| 1539 | | - continue; |
| 1540 | | - } // 2. Handle single query matches (i.e, once that are *not* quoted) |
| 1541 | | - |
| 1542 | | - |
| 1543 | | - idx = -1; |
| 1544 | | - |
| 1545 | | - while (++idx < searchersLen) { |
| 1546 | | - var _searcher = searchers[idx]; |
| 1547 | | - |
| 1548 | | - var _token = _searcher.isSingleMatch(queryItem); |
| 1549 | | - |
| 1550 | | - if (_token) { |
| 1551 | | - results.push(new _searcher(_token, options)); |
| 1552 | | - break; |
| 1553 | | - } |
| 1554 | | - } |
| 1555 | | - } |
| 1556 | | - |
| 1557 | | - return results; |
| 1558 | | - }); |
| 1559 | | - } |
| 1560 | | - |
| 1561 | | - // to a singl match |
| 1562 | | - |
| 1563 | | - var MultiMatchSet = new Set([FuzzyMatch.type, IncludeMatch.type]); |
| 1564 | | - /** |
| 1565 | | - * Command-like searching |
| 1566 | | - * ====================== |
| 1567 | | - * |
| 1568 | | - * Given multiple search terms delimited by spaces.e.g. `^jscript .python$ ruby !java`, |
| 1569 | | - * search in a given text. |
| 1570 | | - * |
| 1571 | | - * Search syntax: |
| 1572 | | - * |
| 1573 | | - * | Token | Match type | Description | |
| 1574 | | - * | ----------- | -------------------------- | -------------------------------------- | |
| 1575 | | - * | `jscript` | fuzzy-match | Items that fuzzy match `jscript` | |
| 1576 | | - * | `=scheme` | exact-match | Items that are `scheme` | |
| 1577 | | - * | `'python` | include-match | Items that include `python` | |
| 1578 | | - * | `!ruby` | inverse-exact-match | Items that do not include `ruby` | |
| 1579 | | - * | `^java` | prefix-exact-match | Items that start with `java` | |
| 1580 | | - * | `!^earlang` | inverse-prefix-exact-match | Items that do not start with `earlang` | |
| 1581 | | - * | `.js$` | suffix-exact-match | Items that end with `.js` | |
| 1582 | | - * | `!.go$` | inverse-suffix-exact-match | Items that do not end with `.go` | |
| 1583 | | - * |
| 1584 | | - * A single pipe character acts as an OR operator. For example, the following |
| 1585 | | - * query matches entries that start with `core` and end with either`go`, `rb`, |
| 1586 | | - * or`py`. |
| 1587 | | - * |
| 1588 | | - * ``` |
| 1589 | | - * ^core go$ | rb$ | py$ |
| 1590 | | - * ``` |
| 1591 | | - */ |
| 1592 | | - |
| 1593 | | - var ExtendedSearch = /*#__PURE__*/function () { |
| 1594 | | - function ExtendedSearch(pattern) { |
| 1595 | | - var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, |
| 1596 | | - _ref$isCaseSensitive = _ref.isCaseSensitive, |
| 1597 | | - isCaseSensitive = _ref$isCaseSensitive === void 0 ? Config.isCaseSensitive : _ref$isCaseSensitive, |
| 1598 | | - _ref$includeMatches = _ref.includeMatches, |
| 1599 | | - includeMatches = _ref$includeMatches === void 0 ? Config.includeMatches : _ref$includeMatches, |
| 1600 | | - _ref$minMatchCharLeng = _ref.minMatchCharLength, |
| 1601 | | - minMatchCharLength = _ref$minMatchCharLeng === void 0 ? Config.minMatchCharLength : _ref$minMatchCharLeng, |
| 1602 | | - _ref$ignoreLocation = _ref.ignoreLocation, |
| 1603 | | - ignoreLocation = _ref$ignoreLocation === void 0 ? Config.ignoreLocation : _ref$ignoreLocation, |
| 1604 | | - _ref$findAllMatches = _ref.findAllMatches, |
| 1605 | | - findAllMatches = _ref$findAllMatches === void 0 ? Config.findAllMatches : _ref$findAllMatches, |
| 1606 | | - _ref$location = _ref.location, |
| 1607 | | - location = _ref$location === void 0 ? Config.location : _ref$location, |
| 1608 | | - _ref$threshold = _ref.threshold, |
| 1609 | | - threshold = _ref$threshold === void 0 ? Config.threshold : _ref$threshold, |
| 1610 | | - _ref$distance = _ref.distance, |
| 1611 | | - distance = _ref$distance === void 0 ? Config.distance : _ref$distance; |
| 1612 | | - |
| 1613 | | - _classCallCheck(this, ExtendedSearch); |
| 1614 | | - |
| 1615 | | - this.query = null; |
| 1616 | | - this.options = { |
| 1617 | | - isCaseSensitive: isCaseSensitive, |
| 1618 | | - includeMatches: includeMatches, |
| 1619 | | - minMatchCharLength: minMatchCharLength, |
| 1620 | | - findAllMatches: findAllMatches, |
| 1621 | | - ignoreLocation: ignoreLocation, |
| 1622 | | - location: location, |
| 1623 | | - threshold: threshold, |
| 1624 | | - distance: distance |
| 1625 | | - }; |
| 1626 | | - this.pattern = isCaseSensitive ? pattern : pattern.toLowerCase(); |
| 1627 | | - this.query = parseQuery(this.pattern, this.options); |
| 1628 | | - } |
| 1629 | | - |
| 1630 | | - _createClass(ExtendedSearch, [{ |
| 1631 | | - key: "searchIn", |
| 1632 | | - value: function searchIn(text) { |
| 1633 | | - var query = this.query; |
| 1634 | | - |
| 1635 | | - if (!query) { |
| 1636 | | - return { |
| 1637 | | - isMatch: false, |
| 1638 | | - score: 1 |
| 1639 | | - }; |
| 1640 | | - } |
| 1641 | | - |
| 1642 | | - var _this$options = this.options, |
| 1643 | | - includeMatches = _this$options.includeMatches, |
| 1644 | | - isCaseSensitive = _this$options.isCaseSensitive; |
| 1645 | | - text = isCaseSensitive ? text : text.toLowerCase(); |
| 1646 | | - var numMatches = 0; |
| 1647 | | - var allIndices = []; |
| 1648 | | - var totalScore = 0; // ORs |
| 1649 | | - |
| 1650 | | - for (var i = 0, qLen = query.length; i < qLen; i += 1) { |
| 1651 | | - var searchers = query[i]; // Reset indices |
| 1652 | | - |
| 1653 | | - allIndices.length = 0; |
| 1654 | | - numMatches = 0; // ANDs |
| 1655 | | - |
| 1656 | | - for (var j = 0, pLen = searchers.length; j < pLen; j += 1) { |
| 1657 | | - var searcher = searchers[j]; |
| 1658 | | - |
| 1659 | | - var _searcher$search = searcher.search(text), |
| 1660 | | - isMatch = _searcher$search.isMatch, |
| 1661 | | - indices = _searcher$search.indices, |
| 1662 | | - score = _searcher$search.score; |
| 1663 | | - |
| 1664 | | - if (isMatch) { |
| 1665 | | - numMatches += 1; |
| 1666 | | - totalScore += score; |
| 1667 | | - |
| 1668 | | - if (includeMatches) { |
| 1669 | | - var type = searcher.constructor.type; |
| 1670 | | - |
| 1671 | | - if (MultiMatchSet.has(type)) { |
| 1672 | | - allIndices = [].concat(_toConsumableArray(allIndices), _toConsumableArray(indices)); |
| 1673 | | - } else { |
| 1674 | | - allIndices.push(indices); |
| 1675 | | - } |
| 1676 | | - } |
| 1677 | | - } else { |
| 1678 | | - totalScore = 0; |
| 1679 | | - numMatches = 0; |
| 1680 | | - allIndices.length = 0; |
| 1681 | | - break; |
| 1682 | | - } |
| 1683 | | - } // OR condition, so if TRUE, return |
| 1684 | | - |
| 1685 | | - |
| 1686 | | - if (numMatches) { |
| 1687 | | - var result = { |
| 1688 | | - isMatch: true, |
| 1689 | | - score: totalScore / numMatches |
| 1690 | | - }; |
| 1691 | | - |
| 1692 | | - if (includeMatches) { |
| 1693 | | - result.indices = allIndices; |
| 1694 | | - } |
| 1695 | | - |
| 1696 | | - return result; |
| 1697 | | - } |
| 1698 | | - } // Nothing was matched |
| 1699 | | - |
| 1700 | | - |
| 1701 | | - return { |
| 1702 | | - isMatch: false, |
| 1703 | | - score: 1 |
| 1704 | | - }; |
| 1705 | | - } |
| 1706 | | - }], [{ |
| 1707 | | - key: "condition", |
| 1708 | | - value: function condition(_, options) { |
| 1709 | | - return options.useExtendedSearch; |
| 1710 | | - } |
| 1711 | | - }]); |
| 1712 | | - |
| 1713 | | - return ExtendedSearch; |
| 1714 | | - }(); |
| 1715 | | - |
| 1716 | | - var registeredSearchers = []; |
| 1717 | | - function register() { |
| 1718 | | - registeredSearchers.push.apply(registeredSearchers, arguments); |
| 1719 | | - } |
| 1720 | | - function createSearcher(pattern, options) { |
| 1721 | | - for (var i = 0, len = registeredSearchers.length; i < len; i += 1) { |
| 1722 | | - var searcherClass = registeredSearchers[i]; |
| 1723 | | - |
| 1724 | | - if (searcherClass.condition(pattern, options)) { |
| 1725 | | - return new searcherClass(pattern, options); |
| 1726 | | - } |
| 1727 | | - } |
| 1728 | | - |
| 1729 | | - return new BitapSearch(pattern, options); |
| 1730 | | - } |
| 1731 | | - |
| 1732 | | - var LogicalOperator = { |
| 1733 | | - AND: '$and', |
| 1734 | | - OR: '$or' |
| 1735 | | - }; |
| 1736 | | - var KeyType = { |
| 1737 | | - PATH: '$path', |
| 1738 | | - PATTERN: '$val' |
| 1739 | | - }; |
| 1740 | | - |
| 1741 | | - var isExpression = function isExpression(query) { |
| 1742 | | - return !!(query[LogicalOperator.AND] || query[LogicalOperator.OR]); |
| 1743 | | - }; |
| 1744 | | - |
| 1745 | | - var isPath = function isPath(query) { |
| 1746 | | - return !!query[KeyType.PATH]; |
| 1747 | | - }; |
| 1748 | | - |
| 1749 | | - var isLeaf = function isLeaf(query) { |
| 1750 | | - return !isArray(query) && isObject(query) && !isExpression(query); |
| 1751 | | - }; |
| 1752 | | - |
| 1753 | | - var convertToExplicit = function convertToExplicit(query) { |
| 1754 | | - return _defineProperty({}, LogicalOperator.AND, Object.keys(query).map(function (key) { |
| 1755 | | - return _defineProperty({}, key, query[key]); |
| 1756 | | - })); |
| 1757 | | - }; // When `auto` is `true`, the parse function will infer and initialize and add |
| 1758 | | - // the appropriate `Searcher` instance |
| 1759 | | - |
| 1760 | | - |
| 1761 | | - function parse(query, options) { |
| 1762 | | - var _ref3 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, |
| 1763 | | - _ref3$auto = _ref3.auto, |
| 1764 | | - auto = _ref3$auto === void 0 ? true : _ref3$auto; |
| 1765 | | - |
| 1766 | | - var next = function next(query) { |
| 1767 | | - var keys = Object.keys(query); |
| 1768 | | - var isQueryPath = isPath(query); |
| 1769 | | - |
| 1770 | | - if (!isQueryPath && keys.length > 1 && !isExpression(query)) { |
| 1771 | | - return next(convertToExplicit(query)); |
| 1772 | | - } |
| 1773 | | - |
| 1774 | | - if (isLeaf(query)) { |
| 1775 | | - var key = isQueryPath ? query[KeyType.PATH] : keys[0]; |
| 1776 | | - var pattern = isQueryPath ? query[KeyType.PATTERN] : query[key]; |
| 1777 | | - |
| 1778 | | - if (!isString(pattern)) { |
| 1779 | | - throw new Error(LOGICAL_SEARCH_INVALID_QUERY_FOR_KEY(key)); |
| 1780 | | - } |
| 1781 | | - |
| 1782 | | - var obj = { |
| 1783 | | - keyId: createKeyId(key), |
| 1784 | | - pattern: pattern |
| 1785 | | - }; |
| 1786 | | - |
| 1787 | | - if (auto) { |
| 1788 | | - obj.searcher = createSearcher(pattern, options); |
| 1789 | | - } |
| 1790 | | - |
| 1791 | | - return obj; |
| 1792 | | - } |
| 1793 | | - |
| 1794 | | - var node = { |
| 1795 | | - children: [], |
| 1796 | | - operator: keys[0] |
| 1797 | | - }; |
| 1798 | | - keys.forEach(function (key) { |
| 1799 | | - var value = query[key]; |
| 1800 | | - |
| 1801 | | - if (isArray(value)) { |
| 1802 | | - value.forEach(function (item) { |
| 1803 | | - node.children.push(next(item)); |
| 1804 | | - }); |
| 1805 | | - } |
| 1806 | | - }); |
| 1807 | | - return node; |
| 1808 | | - }; |
| 1809 | | - |
| 1810 | | - if (!isExpression(query)) { |
| 1811 | | - query = convertToExplicit(query); |
| 1812 | | - } |
| 1813 | | - |
| 1814 | | - return next(query); |
| 1815 | | - } |
| 1816 | | - |
| 1817 | | - function computeScore(results, _ref) { |
| 1818 | | - var _ref$ignoreFieldNorm = _ref.ignoreFieldNorm, |
| 1819 | | - ignoreFieldNorm = _ref$ignoreFieldNorm === void 0 ? Config.ignoreFieldNorm : _ref$ignoreFieldNorm; |
| 1820 | | - results.forEach(function (result) { |
| 1821 | | - var totalScore = 1; |
| 1822 | | - result.matches.forEach(function (_ref2) { |
| 1823 | | - var key = _ref2.key, |
| 1824 | | - norm = _ref2.norm, |
| 1825 | | - score = _ref2.score; |
| 1826 | | - var weight = key ? key.weight : null; |
| 1827 | | - totalScore *= Math.pow(score === 0 && weight ? Number.EPSILON : score, (weight || 1) * (ignoreFieldNorm ? 1 : norm)); |
| 1828 | | - }); |
| 1829 | | - result.score = totalScore; |
| 1830 | | - }); |
| 1831 | | - } |
| 1832 | | - |
| 1833 | | - function transformMatches(result, data) { |
| 1834 | | - var matches = result.matches; |
| 1835 | | - data.matches = []; |
| 1836 | | - |
| 1837 | | - if (!isDefined(matches)) { |
| 1838 | | - return; |
| 1839 | | - } |
| 1840 | | - |
| 1841 | | - matches.forEach(function (match) { |
| 1842 | | - if (!isDefined(match.indices) || !match.indices.length) { |
| 1843 | | - return; |
| 1844 | | - } |
| 1845 | | - |
| 1846 | | - var indices = match.indices, |
| 1847 | | - value = match.value; |
| 1848 | | - var obj = { |
| 1849 | | - indices: indices, |
| 1850 | | - value: value |
| 1851 | | - }; |
| 1852 | | - |
| 1853 | | - if (match.key) { |
| 1854 | | - obj.key = match.key.src; |
| 1855 | | - } |
| 1856 | | - |
| 1857 | | - if (match.idx > -1) { |
| 1858 | | - obj.refIndex = match.idx; |
| 1859 | | - } |
| 1860 | | - |
| 1861 | | - data.matches.push(obj); |
| 1862 | | - }); |
| 1863 | | - } |
| 1864 | | - |
| 1865 | | - function transformScore(result, data) { |
| 1866 | | - data.score = result.score; |
| 1867 | | - } |
| 1868 | | - |
| 1869 | | - function format(results, docs) { |
| 1870 | | - var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, |
| 1871 | | - _ref$includeMatches = _ref.includeMatches, |
| 1872 | | - includeMatches = _ref$includeMatches === void 0 ? Config.includeMatches : _ref$includeMatches, |
| 1873 | | - _ref$includeScore = _ref.includeScore, |
| 1874 | | - includeScore = _ref$includeScore === void 0 ? Config.includeScore : _ref$includeScore; |
| 1875 | | - |
| 1876 | | - var transformers = []; |
| 1877 | | - if (includeMatches) transformers.push(transformMatches); |
| 1878 | | - if (includeScore) transformers.push(transformScore); |
| 1879 | | - return results.map(function (result) { |
| 1880 | | - var idx = result.idx; |
| 1881 | | - var data = { |
| 1882 | | - item: docs[idx], |
| 1883 | | - refIndex: idx |
| 1884 | | - }; |
| 1885 | | - |
| 1886 | | - if (transformers.length) { |
| 1887 | | - transformers.forEach(function (transformer) { |
| 1888 | | - transformer(result, data); |
| 1889 | | - }); |
| 1890 | | - } |
| 1891 | | - |
| 1892 | | - return data; |
| 1893 | | - }); |
| 1894 | | - } |
| 1895 | | - |
| 1896 | | - var Fuse$1 = /*#__PURE__*/function () { |
| 1897 | | - function Fuse(docs) { |
| 1898 | | - var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; |
| 1899 | | - var index = arguments.length > 2 ? arguments[2] : undefined; |
| 1900 | | - |
| 1901 | | - _classCallCheck(this, Fuse); |
| 1902 | | - |
| 1903 | | - this.options = _objectSpread2(_objectSpread2({}, Config), options); |
| 1904 | | - |
| 1905 | | - if (this.options.useExtendedSearch && !true) { |
| 1906 | | - throw new Error(EXTENDED_SEARCH_UNAVAILABLE); |
| 1907 | | - } |
| 1908 | | - |
| 1909 | | - this._keyStore = new KeyStore(this.options.keys); |
| 1910 | | - this.setCollection(docs, index); |
| 1911 | | - } |
| 1912 | | - |
| 1913 | | - _createClass(Fuse, [{ |
| 1914 | | - key: "setCollection", |
| 1915 | | - value: function setCollection(docs, index) { |
| 1916 | | - this._docs = docs; |
| 1917 | | - |
| 1918 | | - if (index && !(index instanceof FuseIndex)) { |
| 1919 | | - throw new Error(INCORRECT_INDEX_TYPE); |
| 1920 | | - } |
| 1921 | | - |
| 1922 | | - this._myIndex = index || createIndex(this.options.keys, this._docs, { |
| 1923 | | - getFn: this.options.getFn, |
| 1924 | | - fieldNormWeight: this.options.fieldNormWeight |
| 1925 | | - }); |
| 1926 | | - } |
| 1927 | | - }, { |
| 1928 | | - key: "add", |
| 1929 | | - value: function add(doc) { |
| 1930 | | - if (!isDefined(doc)) { |
| 1931 | | - return; |
| 1932 | | - } |
| 1933 | | - |
| 1934 | | - this._docs.push(doc); |
| 1935 | | - |
| 1936 | | - this._myIndex.add(doc); |
| 1937 | | - } |
| 1938 | | - }, { |
| 1939 | | - key: "remove", |
| 1940 | | - value: function remove() { |
| 1941 | | - var predicate = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function |
| 1942 | | - /* doc, idx */ |
| 1943 | | - () { |
| 1944 | | - return false; |
| 1945 | | - }; |
| 1946 | | - var results = []; |
| 1947 | | - |
| 1948 | | - for (var i = 0, len = this._docs.length; i < len; i += 1) { |
| 1949 | | - var doc = this._docs[i]; |
| 1950 | | - |
| 1951 | | - if (predicate(doc, i)) { |
| 1952 | | - this.removeAt(i); |
| 1953 | | - i -= 1; |
| 1954 | | - len -= 1; |
| 1955 | | - results.push(doc); |
| 1956 | | - } |
| 1957 | | - } |
| 1958 | | - |
| 1959 | | - return results; |
| 1960 | | - } |
| 1961 | | - }, { |
| 1962 | | - key: "removeAt", |
| 1963 | | - value: function removeAt(idx) { |
| 1964 | | - this._docs.splice(idx, 1); |
| 1965 | | - |
| 1966 | | - this._myIndex.removeAt(idx); |
| 1967 | | - } |
| 1968 | | - }, { |
| 1969 | | - key: "getIndex", |
| 1970 | | - value: function getIndex() { |
| 1971 | | - return this._myIndex; |
| 1972 | | - } |
| 1973 | | - }, { |
| 1974 | | - key: "search", |
| 1975 | | - value: function search(query) { |
| 1976 | | - var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, |
| 1977 | | - _ref$limit = _ref.limit, |
| 1978 | | - limit = _ref$limit === void 0 ? -1 : _ref$limit; |
| 1979 | | - |
| 1980 | | - var _this$options = this.options, |
| 1981 | | - includeMatches = _this$options.includeMatches, |
| 1982 | | - includeScore = _this$options.includeScore, |
| 1983 | | - shouldSort = _this$options.shouldSort, |
| 1984 | | - sortFn = _this$options.sortFn, |
| 1985 | | - ignoreFieldNorm = _this$options.ignoreFieldNorm; |
| 1986 | | - var results = isString(query) ? isString(this._docs[0]) ? this._searchStringList(query) : this._searchObjectList(query) : this._searchLogical(query); |
| 1987 | | - computeScore(results, { |
| 1988 | | - ignoreFieldNorm: ignoreFieldNorm |
| 1989 | | - }); |
| 1990 | | - |
| 1991 | | - if (shouldSort) { |
| 1992 | | - results.sort(sortFn); |
| 1993 | | - } |
| 1994 | | - |
| 1995 | | - if (isNumber(limit) && limit > -1) { |
| 1996 | | - results = results.slice(0, limit); |
| 1997 | | - } |
| 1998 | | - |
| 1999 | | - return format(results, this._docs, { |
| 2000 | | - includeMatches: includeMatches, |
| 2001 | | - includeScore: includeScore |
| 2002 | | - }); |
| 2003 | | - } |
| 2004 | | - }, { |
| 2005 | | - key: "_searchStringList", |
| 2006 | | - value: function _searchStringList(query) { |
| 2007 | | - var searcher = createSearcher(query, this.options); |
| 2008 | | - var records = this._myIndex.records; |
| 2009 | | - var results = []; // Iterate over every string in the index |
| 2010 | | - |
| 2011 | | - records.forEach(function (_ref2) { |
| 2012 | | - var text = _ref2.v, |
| 2013 | | - idx = _ref2.i, |
| 2014 | | - norm = _ref2.n; |
| 2015 | | - |
| 2016 | | - if (!isDefined(text)) { |
| 2017 | | - return; |
| 2018 | | - } |
| 2019 | | - |
| 2020 | | - var _searcher$searchIn = searcher.searchIn(text), |
| 2021 | | - isMatch = _searcher$searchIn.isMatch, |
| 2022 | | - score = _searcher$searchIn.score, |
| 2023 | | - indices = _searcher$searchIn.indices; |
| 2024 | | - |
| 2025 | | - if (isMatch) { |
| 2026 | | - results.push({ |
| 2027 | | - item: text, |
| 2028 | | - idx: idx, |
| 2029 | | - matches: [{ |
| 2030 | | - score: score, |
| 2031 | | - value: text, |
| 2032 | | - norm: norm, |
| 2033 | | - indices: indices |
| 2034 | | - }] |
| 2035 | | - }); |
| 2036 | | - } |
| 2037 | | - }); |
| 2038 | | - return results; |
| 2039 | | - } |
| 2040 | | - }, { |
| 2041 | | - key: "_searchLogical", |
| 2042 | | - value: function _searchLogical(query) { |
| 2043 | | - var _this = this; |
| 2044 | | - |
| 2045 | | - var expression = parse(query, this.options); |
| 2046 | | - |
| 2047 | | - var evaluate = function evaluate(node, item, idx) { |
| 2048 | | - if (!node.children) { |
| 2049 | | - var keyId = node.keyId, |
| 2050 | | - searcher = node.searcher; |
| 2051 | | - |
| 2052 | | - var matches = _this._findMatches({ |
| 2053 | | - key: _this._keyStore.get(keyId), |
| 2054 | | - value: _this._myIndex.getValueForItemAtKeyId(item, keyId), |
| 2055 | | - searcher: searcher |
| 2056 | | - }); |
| 2057 | | - |
| 2058 | | - if (matches && matches.length) { |
| 2059 | | - return [{ |
| 2060 | | - idx: idx, |
| 2061 | | - item: item, |
| 2062 | | - matches: matches |
| 2063 | | - }]; |
| 2064 | | - } |
| 2065 | | - |
| 2066 | | - return []; |
| 2067 | | - } |
| 2068 | | - |
| 2069 | | - var res = []; |
| 2070 | | - |
| 2071 | | - for (var i = 0, len = node.children.length; i < len; i += 1) { |
| 2072 | | - var child = node.children[i]; |
| 2073 | | - var result = evaluate(child, item, idx); |
| 2074 | | - |
| 2075 | | - if (result.length) { |
| 2076 | | - res.push.apply(res, _toConsumableArray(result)); |
| 2077 | | - } else if (node.operator === LogicalOperator.AND) { |
| 2078 | | - return []; |
| 2079 | | - } |
| 2080 | | - } |
| 2081 | | - |
| 2082 | | - return res; |
| 2083 | | - }; |
| 2084 | | - |
| 2085 | | - var records = this._myIndex.records; |
| 2086 | | - var resultMap = {}; |
| 2087 | | - var results = []; |
| 2088 | | - records.forEach(function (_ref3) { |
| 2089 | | - var item = _ref3.$, |
| 2090 | | - idx = _ref3.i; |
| 2091 | | - |
| 2092 | | - if (isDefined(item)) { |
| 2093 | | - var expResults = evaluate(expression, item, idx); |
| 2094 | | - |
| 2095 | | - if (expResults.length) { |
| 2096 | | - // Dedupe when adding |
| 2097 | | - if (!resultMap[idx]) { |
| 2098 | | - resultMap[idx] = { |
| 2099 | | - idx: idx, |
| 2100 | | - item: item, |
| 2101 | | - matches: [] |
| 2102 | | - }; |
| 2103 | | - results.push(resultMap[idx]); |
| 2104 | | - } |
| 2105 | | - |
| 2106 | | - expResults.forEach(function (_ref4) { |
| 2107 | | - var _resultMap$idx$matche; |
| 2108 | | - |
| 2109 | | - var matches = _ref4.matches; |
| 2110 | | - |
| 2111 | | - (_resultMap$idx$matche = resultMap[idx].matches).push.apply(_resultMap$idx$matche, _toConsumableArray(matches)); |
| 2112 | | - }); |
| 2113 | | - } |
| 2114 | | - } |
| 2115 | | - }); |
| 2116 | | - return results; |
| 2117 | | - } |
| 2118 | | - }, { |
| 2119 | | - key: "_searchObjectList", |
| 2120 | | - value: function _searchObjectList(query) { |
| 2121 | | - var _this2 = this; |
| 2122 | | - |
| 2123 | | - var searcher = createSearcher(query, this.options); |
| 2124 | | - var _this$_myIndex = this._myIndex, |
| 2125 | | - keys = _this$_myIndex.keys, |
| 2126 | | - records = _this$_myIndex.records; |
| 2127 | | - var results = []; // List is Array<Object> |
| 2128 | | - |
| 2129 | | - records.forEach(function (_ref5) { |
| 2130 | | - var item = _ref5.$, |
| 2131 | | - idx = _ref5.i; |
| 2132 | | - |
| 2133 | | - if (!isDefined(item)) { |
| 2134 | | - return; |
| 2135 | | - } |
| 2136 | | - |
| 2137 | | - var matches = []; // Iterate over every key (i.e, path), and fetch the value at that key |
| 2138 | | - |
| 2139 | | - keys.forEach(function (key, keyIndex) { |
| 2140 | | - matches.push.apply(matches, _toConsumableArray(_this2._findMatches({ |
| 2141 | | - key: key, |
| 2142 | | - value: item[keyIndex], |
| 2143 | | - searcher: searcher |
| 2144 | | - }))); |
| 2145 | | - }); |
| 2146 | | - |
| 2147 | | - if (matches.length) { |
| 2148 | | - results.push({ |
| 2149 | | - idx: idx, |
| 2150 | | - item: item, |
| 2151 | | - matches: matches |
| 2152 | | - }); |
| 2153 | | - } |
| 2154 | | - }); |
| 2155 | | - return results; |
| 2156 | | - } |
| 2157 | | - }, { |
| 2158 | | - key: "_findMatches", |
| 2159 | | - value: function _findMatches(_ref6) { |
| 2160 | | - var key = _ref6.key, |
| 2161 | | - value = _ref6.value, |
| 2162 | | - searcher = _ref6.searcher; |
| 2163 | | - |
| 2164 | | - if (!isDefined(value)) { |
| 2165 | | - return []; |
| 2166 | | - } |
| 2167 | | - |
| 2168 | | - var matches = []; |
| 2169 | | - |
| 2170 | | - if (isArray(value)) { |
| 2171 | | - value.forEach(function (_ref7) { |
| 2172 | | - var text = _ref7.v, |
| 2173 | | - idx = _ref7.i, |
| 2174 | | - norm = _ref7.n; |
| 2175 | | - |
| 2176 | | - if (!isDefined(text)) { |
| 2177 | | - return; |
| 2178 | | - } |
| 2179 | | - |
| 2180 | | - var _searcher$searchIn2 = searcher.searchIn(text), |
| 2181 | | - isMatch = _searcher$searchIn2.isMatch, |
| 2182 | | - score = _searcher$searchIn2.score, |
| 2183 | | - indices = _searcher$searchIn2.indices; |
| 2184 | | - |
| 2185 | | - if (isMatch) { |
| 2186 | | - matches.push({ |
| 2187 | | - score: score, |
| 2188 | | - key: key, |
| 2189 | | - value: text, |
| 2190 | | - idx: idx, |
| 2191 | | - norm: norm, |
| 2192 | | - indices: indices |
| 2193 | | - }); |
| 2194 | | - } |
| 2195 | | - }); |
| 2196 | | - } else { |
| 2197 | | - var text = value.v, |
| 2198 | | - norm = value.n; |
| 2199 | | - |
| 2200 | | - var _searcher$searchIn3 = searcher.searchIn(text), |
| 2201 | | - isMatch = _searcher$searchIn3.isMatch, |
| 2202 | | - score = _searcher$searchIn3.score, |
| 2203 | | - indices = _searcher$searchIn3.indices; |
| 2204 | | - |
| 2205 | | - if (isMatch) { |
| 2206 | | - matches.push({ |
| 2207 | | - score: score, |
| 2208 | | - key: key, |
| 2209 | | - value: text, |
| 2210 | | - norm: norm, |
| 2211 | | - indices: indices |
| 2212 | | - }); |
| 2213 | | - } |
| 2214 | | - } |
| 2215 | | - |
| 2216 | | - return matches; |
| 2217 | | - } |
| 2218 | | - }]); |
| 2219 | | - |
| 2220 | | - return Fuse; |
| 2221 | | - }(); |
| 2222 | | - |
| 2223 | | - Fuse$1.version = '6.6.2'; |
| 2224 | | - Fuse$1.createIndex = createIndex; |
| 2225 | | - Fuse$1.parseIndex = parseIndex; |
| 2226 | | - Fuse$1.config = Config; |
| 2227 | | - |
| 2228 | | - { |
| 2229 | | - Fuse$1.parseQuery = parse; |
| 2230 | | - } |
| 2231 | | - |
| 2232 | | - { |
| 2233 | | - register(ExtendedSearch); |
| 2234 | | - } |
| 2235 | | - |
| 2236 | | - var Fuse = Fuse$1; |
| 2237 | | - |
| 2238 | | - return Fuse; |
| 2239 | | - |
| 2240 | | -})); |