fuse.basic.js 45 KB

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