fuse.common.js 62 KB

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