fuse.basic.common.js 42 KB

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