vitepress___minisearch.js 87 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216
  1. import './chunk-UXIASGQL.js';
  2. // node_modules/.pnpm/minisearch@6.3.0/node_modules/minisearch/dist/es/index.js
  3. var __assign = function () {
  4. __assign =
  5. Object.assign ||
  6. function __assign2(t) {
  7. for (var s, i = 1, n = arguments.length; i < n; i++) {
  8. s = arguments[i];
  9. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
  10. }
  11. return t;
  12. };
  13. return __assign.apply(this, arguments);
  14. };
  15. function __awaiter(thisArg, _arguments, P, generator) {
  16. function adopt(value) {
  17. return value instanceof P
  18. ? value
  19. : new P(function (resolve) {
  20. resolve(value);
  21. });
  22. }
  23. return new (P || (P = Promise))(function (resolve, reject) {
  24. function fulfilled(value) {
  25. try {
  26. step(generator.next(value));
  27. } catch (e) {
  28. reject(e);
  29. }
  30. }
  31. function rejected(value) {
  32. try {
  33. step(generator['throw'](value));
  34. } catch (e) {
  35. reject(e);
  36. }
  37. }
  38. function step(result) {
  39. result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
  40. }
  41. step((generator = generator.apply(thisArg, _arguments || [])).next());
  42. });
  43. }
  44. function __generator(thisArg, body) {
  45. var _ = {
  46. label: 0,
  47. sent: function () {
  48. if (t[0] & 1) throw t[1];
  49. return t[1];
  50. },
  51. trys: [],
  52. ops: []
  53. },
  54. f,
  55. y,
  56. t,
  57. g;
  58. return (
  59. (g = { next: verb(0), throw: verb(1), return: verb(2) }),
  60. typeof Symbol === 'function' &&
  61. (g[Symbol.iterator] = function () {
  62. return this;
  63. }),
  64. g
  65. );
  66. function verb(n) {
  67. return function (v) {
  68. return step([n, v]);
  69. };
  70. }
  71. function step(op) {
  72. if (f) throw new TypeError('Generator is already executing.');
  73. while ((g && ((g = 0), op[0] && (_ = 0)), _))
  74. try {
  75. if (
  76. ((f = 1),
  77. y &&
  78. (t =
  79. op[0] & 2
  80. ? y['return']
  81. : op[0]
  82. ? y['throw'] || ((t = y['return']) && t.call(y), 0)
  83. : y.next) &&
  84. !(t = t.call(y, op[1])).done)
  85. )
  86. return t;
  87. if (((y = 0), t)) op = [op[0] & 2, t.value];
  88. switch (op[0]) {
  89. case 0:
  90. case 1:
  91. t = op;
  92. break;
  93. case 4:
  94. _.label++;
  95. return { value: op[1], done: false };
  96. case 5:
  97. _.label++;
  98. y = op[1];
  99. op = [0];
  100. continue;
  101. case 7:
  102. op = _.ops.pop();
  103. _.trys.pop();
  104. continue;
  105. default:
  106. if (
  107. !((t = _.trys), (t = t.length > 0 && t[t.length - 1])) &&
  108. (op[0] === 6 || op[0] === 2)
  109. ) {
  110. _ = 0;
  111. continue;
  112. }
  113. if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
  114. _.label = op[1];
  115. break;
  116. }
  117. if (op[0] === 6 && _.label < t[1]) {
  118. _.label = t[1];
  119. t = op;
  120. break;
  121. }
  122. if (t && _.label < t[2]) {
  123. _.label = t[2];
  124. _.ops.push(op);
  125. break;
  126. }
  127. if (t[2]) _.ops.pop();
  128. _.trys.pop();
  129. continue;
  130. }
  131. op = body.call(thisArg, _);
  132. } catch (e) {
  133. op = [6, e];
  134. y = 0;
  135. } finally {
  136. f = t = 0;
  137. }
  138. if (op[0] & 5) throw op[1];
  139. return { value: op[0] ? op[1] : void 0, done: true };
  140. }
  141. }
  142. function __values(o) {
  143. var s = typeof Symbol === 'function' && Symbol.iterator,
  144. m = s && o[s],
  145. i = 0;
  146. if (m) return m.call(o);
  147. if (o && typeof o.length === 'number')
  148. return {
  149. next: function () {
  150. if (o && i >= o.length) o = void 0;
  151. return { value: o && o[i++], done: !o };
  152. }
  153. };
  154. throw new TypeError(s ? 'Object is not iterable.' : 'Symbol.iterator is not defined.');
  155. }
  156. function __read(o, n) {
  157. var m = typeof Symbol === 'function' && o[Symbol.iterator];
  158. if (!m) return o;
  159. var i = m.call(o),
  160. r,
  161. ar = [],
  162. e;
  163. try {
  164. while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
  165. } catch (error) {
  166. e = { error };
  167. } finally {
  168. try {
  169. if (r && !r.done && (m = i['return'])) m.call(i);
  170. } finally {
  171. if (e) throw e.error;
  172. }
  173. }
  174. return ar;
  175. }
  176. var ENTRIES = 'ENTRIES';
  177. var KEYS = 'KEYS';
  178. var VALUES = 'VALUES';
  179. var LEAF = '';
  180. var TreeIterator =
  181. /** @class */
  182. (function () {
  183. function TreeIterator2(set, type) {
  184. var node = set._tree;
  185. var keys = Array.from(node.keys());
  186. this.set = set;
  187. this._type = type;
  188. this._path = keys.length > 0 ? [{ node, keys }] : [];
  189. }
  190. TreeIterator2.prototype.next = function () {
  191. var value = this.dive();
  192. this.backtrack();
  193. return value;
  194. };
  195. TreeIterator2.prototype.dive = function () {
  196. if (this._path.length === 0) {
  197. return { done: true, value: void 0 };
  198. }
  199. var _a2 = last$1(this._path),
  200. node = _a2.node,
  201. keys = _a2.keys;
  202. if (last$1(keys) === LEAF) {
  203. return { done: false, value: this.result() };
  204. }
  205. var child = node.get(last$1(keys));
  206. this._path.push({ node: child, keys: Array.from(child.keys()) });
  207. return this.dive();
  208. };
  209. TreeIterator2.prototype.backtrack = function () {
  210. if (this._path.length === 0) {
  211. return;
  212. }
  213. var keys = last$1(this._path).keys;
  214. keys.pop();
  215. if (keys.length > 0) {
  216. return;
  217. }
  218. this._path.pop();
  219. this.backtrack();
  220. };
  221. TreeIterator2.prototype.key = function () {
  222. return (
  223. this.set._prefix +
  224. this._path
  225. .map(function (_a2) {
  226. var keys = _a2.keys;
  227. return last$1(keys);
  228. })
  229. .filter(function (key) {
  230. return key !== LEAF;
  231. })
  232. .join('')
  233. );
  234. };
  235. TreeIterator2.prototype.value = function () {
  236. return last$1(this._path).node.get(LEAF);
  237. };
  238. TreeIterator2.prototype.result = function () {
  239. switch (this._type) {
  240. case VALUES:
  241. return this.value();
  242. case KEYS:
  243. return this.key();
  244. default:
  245. return [this.key(), this.value()];
  246. }
  247. };
  248. TreeIterator2.prototype[Symbol.iterator] = function () {
  249. return this;
  250. };
  251. return TreeIterator2;
  252. })();
  253. var last$1 = function (array) {
  254. return array[array.length - 1];
  255. };
  256. var fuzzySearch = function (node, query, maxDistance) {
  257. var results = /* @__PURE__ */ new Map();
  258. if (query === void 0) return results;
  259. var n = query.length + 1;
  260. var m = n + maxDistance;
  261. var matrix = new Uint8Array(m * n).fill(maxDistance + 1);
  262. for (var j = 0; j < n; ++j) matrix[j] = j;
  263. for (var i = 1; i < m; ++i) matrix[i * n] = i;
  264. recurse(node, query, maxDistance, results, matrix, 1, n, '');
  265. return results;
  266. };
  267. var recurse = function (node, query, maxDistance, results, matrix, m, n, prefix) {
  268. var e_1, _a2;
  269. var offset = m * n;
  270. try {
  271. key: for (var _b = __values(node.keys()), _c = _b.next(); !_c.done; _c = _b.next()) {
  272. var key = _c.value;
  273. if (key === LEAF) {
  274. var distance = matrix[offset - 1];
  275. if (distance <= maxDistance) {
  276. results.set(prefix, [node.get(key), distance]);
  277. }
  278. } else {
  279. var i = m;
  280. for (var pos = 0; pos < key.length; ++pos, ++i) {
  281. var char = key[pos];
  282. var thisRowOffset = n * i;
  283. var prevRowOffset = thisRowOffset - n;
  284. var minDistance = matrix[thisRowOffset];
  285. var jmin = Math.max(0, i - maxDistance - 1);
  286. var jmax = Math.min(n - 1, i + maxDistance);
  287. for (var j = jmin; j < jmax; ++j) {
  288. var different = char !== query[j];
  289. var rpl = matrix[prevRowOffset + j] + +different;
  290. var del = matrix[prevRowOffset + j + 1] + 1;
  291. var ins = matrix[thisRowOffset + j] + 1;
  292. var dist = (matrix[thisRowOffset + j + 1] = Math.min(rpl, del, ins));
  293. if (dist < minDistance) minDistance = dist;
  294. }
  295. if (minDistance > maxDistance) {
  296. continue key;
  297. }
  298. }
  299. recurse(node.get(key), query, maxDistance, results, matrix, i, n, prefix + key);
  300. }
  301. }
  302. } catch (e_1_1) {
  303. e_1 = { error: e_1_1 };
  304. } finally {
  305. try {
  306. if (_c && !_c.done && (_a2 = _b.return)) _a2.call(_b);
  307. } finally {
  308. if (e_1) throw e_1.error;
  309. }
  310. }
  311. };
  312. var SearchableMap =
  313. /** @class */
  314. (function () {
  315. function SearchableMap2(tree, prefix) {
  316. if (tree === void 0) {
  317. tree = /* @__PURE__ */ new Map();
  318. }
  319. if (prefix === void 0) {
  320. prefix = '';
  321. }
  322. this._size = void 0;
  323. this._tree = tree;
  324. this._prefix = prefix;
  325. }
  326. SearchableMap2.prototype.atPrefix = function (prefix) {
  327. var e_1, _a2;
  328. if (!prefix.startsWith(this._prefix)) {
  329. throw new Error('Mismatched prefix');
  330. }
  331. var _b = __read(trackDown(this._tree, prefix.slice(this._prefix.length)), 2),
  332. node = _b[0],
  333. path = _b[1];
  334. if (node === void 0) {
  335. var _c = __read(last(path), 2),
  336. parentNode = _c[0],
  337. key = _c[1];
  338. try {
  339. for (
  340. var _d = __values(parentNode.keys()), _e = _d.next();
  341. !_e.done;
  342. _e = _d.next()
  343. ) {
  344. var k = _e.value;
  345. if (k !== LEAF && k.startsWith(key)) {
  346. var node_1 = /* @__PURE__ */ new Map();
  347. node_1.set(k.slice(key.length), parentNode.get(k));
  348. return new SearchableMap2(node_1, prefix);
  349. }
  350. }
  351. } catch (e_1_1) {
  352. e_1 = { error: e_1_1 };
  353. } finally {
  354. try {
  355. if (_e && !_e.done && (_a2 = _d.return)) _a2.call(_d);
  356. } finally {
  357. if (e_1) throw e_1.error;
  358. }
  359. }
  360. }
  361. return new SearchableMap2(node, prefix);
  362. };
  363. SearchableMap2.prototype.clear = function () {
  364. this._size = void 0;
  365. this._tree.clear();
  366. };
  367. SearchableMap2.prototype.delete = function (key) {
  368. this._size = void 0;
  369. return remove(this._tree, key);
  370. };
  371. SearchableMap2.prototype.entries = function () {
  372. return new TreeIterator(this, ENTRIES);
  373. };
  374. SearchableMap2.prototype.forEach = function (fn) {
  375. var e_2, _a2;
  376. try {
  377. for (var _b = __values(this), _c = _b.next(); !_c.done; _c = _b.next()) {
  378. var _d = __read(_c.value, 2),
  379. key = _d[0],
  380. value = _d[1];
  381. fn(key, value, this);
  382. }
  383. } catch (e_2_1) {
  384. e_2 = { error: e_2_1 };
  385. } finally {
  386. try {
  387. if (_c && !_c.done && (_a2 = _b.return)) _a2.call(_b);
  388. } finally {
  389. if (e_2) throw e_2.error;
  390. }
  391. }
  392. };
  393. SearchableMap2.prototype.fuzzyGet = function (key, maxEditDistance) {
  394. return fuzzySearch(this._tree, key, maxEditDistance);
  395. };
  396. SearchableMap2.prototype.get = function (key) {
  397. var node = lookup(this._tree, key);
  398. return node !== void 0 ? node.get(LEAF) : void 0;
  399. };
  400. SearchableMap2.prototype.has = function (key) {
  401. var node = lookup(this._tree, key);
  402. return node !== void 0 && node.has(LEAF);
  403. };
  404. SearchableMap2.prototype.keys = function () {
  405. return new TreeIterator(this, KEYS);
  406. };
  407. SearchableMap2.prototype.set = function (key, value) {
  408. if (typeof key !== 'string') {
  409. throw new Error('key must be a string');
  410. }
  411. this._size = void 0;
  412. var node = createPath(this._tree, key);
  413. node.set(LEAF, value);
  414. return this;
  415. };
  416. Object.defineProperty(SearchableMap2.prototype, 'size', {
  417. /**
  418. * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/size
  419. */
  420. get: function () {
  421. if (this._size) {
  422. return this._size;
  423. }
  424. this._size = 0;
  425. var iter = this.entries();
  426. while (!iter.next().done) this._size += 1;
  427. return this._size;
  428. },
  429. enumerable: false,
  430. configurable: true
  431. });
  432. SearchableMap2.prototype.update = function (key, fn) {
  433. if (typeof key !== 'string') {
  434. throw new Error('key must be a string');
  435. }
  436. this._size = void 0;
  437. var node = createPath(this._tree, key);
  438. node.set(LEAF, fn(node.get(LEAF)));
  439. return this;
  440. };
  441. SearchableMap2.prototype.fetch = function (key, initial) {
  442. if (typeof key !== 'string') {
  443. throw new Error('key must be a string');
  444. }
  445. this._size = void 0;
  446. var node = createPath(this._tree, key);
  447. var value = node.get(LEAF);
  448. if (value === void 0) {
  449. node.set(LEAF, (value = initial()));
  450. }
  451. return value;
  452. };
  453. SearchableMap2.prototype.values = function () {
  454. return new TreeIterator(this, VALUES);
  455. };
  456. SearchableMap2.prototype[Symbol.iterator] = function () {
  457. return this.entries();
  458. };
  459. SearchableMap2.from = function (entries) {
  460. var e_3, _a2;
  461. var tree = new SearchableMap2();
  462. try {
  463. for (
  464. var entries_1 = __values(entries), entries_1_1 = entries_1.next();
  465. !entries_1_1.done;
  466. entries_1_1 = entries_1.next()
  467. ) {
  468. var _b = __read(entries_1_1.value, 2),
  469. key = _b[0],
  470. value = _b[1];
  471. tree.set(key, value);
  472. }
  473. } catch (e_3_1) {
  474. e_3 = { error: e_3_1 };
  475. } finally {
  476. try {
  477. if (entries_1_1 && !entries_1_1.done && (_a2 = entries_1.return))
  478. _a2.call(entries_1);
  479. } finally {
  480. if (e_3) throw e_3.error;
  481. }
  482. }
  483. return tree;
  484. };
  485. SearchableMap2.fromObject = function (object) {
  486. return SearchableMap2.from(Object.entries(object));
  487. };
  488. return SearchableMap2;
  489. })();
  490. var trackDown = function (tree, key, path) {
  491. var e_4, _a2;
  492. if (path === void 0) {
  493. path = [];
  494. }
  495. if (key.length === 0 || tree == null) {
  496. return [tree, path];
  497. }
  498. try {
  499. for (var _b = __values(tree.keys()), _c = _b.next(); !_c.done; _c = _b.next()) {
  500. var k = _c.value;
  501. if (k !== LEAF && key.startsWith(k)) {
  502. path.push([tree, k]);
  503. return trackDown(tree.get(k), key.slice(k.length), path);
  504. }
  505. }
  506. } catch (e_4_1) {
  507. e_4 = { error: e_4_1 };
  508. } finally {
  509. try {
  510. if (_c && !_c.done && (_a2 = _b.return)) _a2.call(_b);
  511. } finally {
  512. if (e_4) throw e_4.error;
  513. }
  514. }
  515. path.push([tree, key]);
  516. return trackDown(void 0, '', path);
  517. };
  518. var lookup = function (tree, key) {
  519. var e_5, _a2;
  520. if (key.length === 0 || tree == null) {
  521. return tree;
  522. }
  523. try {
  524. for (var _b = __values(tree.keys()), _c = _b.next(); !_c.done; _c = _b.next()) {
  525. var k = _c.value;
  526. if (k !== LEAF && key.startsWith(k)) {
  527. return lookup(tree.get(k), key.slice(k.length));
  528. }
  529. }
  530. } catch (e_5_1) {
  531. e_5 = { error: e_5_1 };
  532. } finally {
  533. try {
  534. if (_c && !_c.done && (_a2 = _b.return)) _a2.call(_b);
  535. } finally {
  536. if (e_5) throw e_5.error;
  537. }
  538. }
  539. };
  540. var createPath = function (node, key) {
  541. var e_6, _a2;
  542. var keyLength = key.length;
  543. outer: for (var pos = 0; node && pos < keyLength; ) {
  544. try {
  545. for (
  546. var _b = ((e_6 = void 0), __values(node.keys())), _c = _b.next();
  547. !_c.done;
  548. _c = _b.next()
  549. ) {
  550. var k = _c.value;
  551. if (k !== LEAF && key[pos] === k[0]) {
  552. var len = Math.min(keyLength - pos, k.length);
  553. var offset = 1;
  554. while (offset < len && key[pos + offset] === k[offset]) ++offset;
  555. var child_1 = node.get(k);
  556. if (offset === k.length) {
  557. node = child_1;
  558. } else {
  559. var intermediate = /* @__PURE__ */ new Map();
  560. intermediate.set(k.slice(offset), child_1);
  561. node.set(key.slice(pos, pos + offset), intermediate);
  562. node.delete(k);
  563. node = intermediate;
  564. }
  565. pos += offset;
  566. continue outer;
  567. }
  568. }
  569. } catch (e_6_1) {
  570. e_6 = { error: e_6_1 };
  571. } finally {
  572. try {
  573. if (_c && !_c.done && (_a2 = _b.return)) _a2.call(_b);
  574. } finally {
  575. if (e_6) throw e_6.error;
  576. }
  577. }
  578. var child = /* @__PURE__ */ new Map();
  579. node.set(key.slice(pos), child);
  580. return child;
  581. }
  582. return node;
  583. };
  584. var remove = function (tree, key) {
  585. var _a2 = __read(trackDown(tree, key), 2),
  586. node = _a2[0],
  587. path = _a2[1];
  588. if (node === void 0) {
  589. return;
  590. }
  591. node.delete(LEAF);
  592. if (node.size === 0) {
  593. cleanup(path);
  594. } else if (node.size === 1) {
  595. var _b = __read(node.entries().next().value, 2),
  596. key_1 = _b[0],
  597. value = _b[1];
  598. merge(path, key_1, value);
  599. }
  600. };
  601. var cleanup = function (path) {
  602. if (path.length === 0) {
  603. return;
  604. }
  605. var _a2 = __read(last(path), 2),
  606. node = _a2[0],
  607. key = _a2[1];
  608. node.delete(key);
  609. if (node.size === 0) {
  610. cleanup(path.slice(0, -1));
  611. } else if (node.size === 1) {
  612. var _b = __read(node.entries().next().value, 2),
  613. key_2 = _b[0],
  614. value = _b[1];
  615. if (key_2 !== LEAF) {
  616. merge(path.slice(0, -1), key_2, value);
  617. }
  618. }
  619. };
  620. var merge = function (path, key, value) {
  621. if (path.length === 0) {
  622. return;
  623. }
  624. var _a2 = __read(last(path), 2),
  625. node = _a2[0],
  626. nodeKey = _a2[1];
  627. node.set(nodeKey + key, value);
  628. node.delete(nodeKey);
  629. };
  630. var last = function (array) {
  631. return array[array.length - 1];
  632. };
  633. var _a;
  634. var OR = 'or';
  635. var AND = 'and';
  636. var AND_NOT = 'and_not';
  637. var MiniSearch =
  638. /** @class */
  639. (function () {
  640. function MiniSearch2(options) {
  641. if ((options === null || options === void 0 ? void 0 : options.fields) == null) {
  642. throw new Error('MiniSearch: option "fields" must be provided');
  643. }
  644. var autoVacuum =
  645. options.autoVacuum == null || options.autoVacuum === true
  646. ? defaultAutoVacuumOptions
  647. : options.autoVacuum;
  648. this._options = __assign(__assign(__assign({}, defaultOptions), options), {
  649. autoVacuum,
  650. searchOptions: __assign(
  651. __assign({}, defaultSearchOptions),
  652. options.searchOptions || {}
  653. ),
  654. autoSuggestOptions: __assign(
  655. __assign({}, defaultAutoSuggestOptions),
  656. options.autoSuggestOptions || {}
  657. )
  658. });
  659. this._index = new SearchableMap();
  660. this._documentCount = 0;
  661. this._documentIds = /* @__PURE__ */ new Map();
  662. this._idToShortId = /* @__PURE__ */ new Map();
  663. this._fieldIds = {};
  664. this._fieldLength = /* @__PURE__ */ new Map();
  665. this._avgFieldLength = [];
  666. this._nextId = 0;
  667. this._storedFields = /* @__PURE__ */ new Map();
  668. this._dirtCount = 0;
  669. this._currentVacuum = null;
  670. this._enqueuedVacuum = null;
  671. this._enqueuedVacuumConditions = defaultVacuumConditions;
  672. this.addFields(this._options.fields);
  673. }
  674. MiniSearch2.prototype.add = function (document) {
  675. var e_1, _a2, e_2, _b, e_3, _c;
  676. var _d = this._options,
  677. extractField = _d.extractField,
  678. tokenize = _d.tokenize,
  679. processTerm = _d.processTerm,
  680. fields = _d.fields,
  681. idField = _d.idField;
  682. var id = extractField(document, idField);
  683. if (id == null) {
  684. throw new Error(
  685. 'MiniSearch: document does not have ID field "'.concat(idField, '"')
  686. );
  687. }
  688. if (this._idToShortId.has(id)) {
  689. throw new Error('MiniSearch: duplicate ID '.concat(id));
  690. }
  691. var shortDocumentId = this.addDocumentId(id);
  692. this.saveStoredFields(shortDocumentId, document);
  693. try {
  694. for (
  695. var fields_1 = __values(fields), fields_1_1 = fields_1.next();
  696. !fields_1_1.done;
  697. fields_1_1 = fields_1.next()
  698. ) {
  699. var field = fields_1_1.value;
  700. var fieldValue = extractField(document, field);
  701. if (fieldValue == null) continue;
  702. var tokens = tokenize(fieldValue.toString(), field);
  703. var fieldId = this._fieldIds[field];
  704. var uniqueTerms = new Set(tokens).size;
  705. this.addFieldLength(
  706. shortDocumentId,
  707. fieldId,
  708. this._documentCount - 1,
  709. uniqueTerms
  710. );
  711. try {
  712. for (
  713. var tokens_1 = ((e_2 = void 0), __values(tokens)),
  714. tokens_1_1 = tokens_1.next();
  715. !tokens_1_1.done;
  716. tokens_1_1 = tokens_1.next()
  717. ) {
  718. var term = tokens_1_1.value;
  719. var processedTerm = processTerm(term, field);
  720. if (Array.isArray(processedTerm)) {
  721. try {
  722. for (
  723. var processedTerm_1 =
  724. ((e_3 = void 0), __values(processedTerm)),
  725. processedTerm_1_1 = processedTerm_1.next();
  726. !processedTerm_1_1.done;
  727. processedTerm_1_1 = processedTerm_1.next()
  728. ) {
  729. var t = processedTerm_1_1.value;
  730. this.addTerm(fieldId, shortDocumentId, t);
  731. }
  732. } catch (e_3_1) {
  733. e_3 = { error: e_3_1 };
  734. } finally {
  735. try {
  736. if (
  737. processedTerm_1_1 &&
  738. !processedTerm_1_1.done &&
  739. (_c = processedTerm_1.return)
  740. )
  741. _c.call(processedTerm_1);
  742. } finally {
  743. if (e_3) throw e_3.error;
  744. }
  745. }
  746. } else if (processedTerm) {
  747. this.addTerm(fieldId, shortDocumentId, processedTerm);
  748. }
  749. }
  750. } catch (e_2_1) {
  751. e_2 = { error: e_2_1 };
  752. } finally {
  753. try {
  754. if (tokens_1_1 && !tokens_1_1.done && (_b = tokens_1.return))
  755. _b.call(tokens_1);
  756. } finally {
  757. if (e_2) throw e_2.error;
  758. }
  759. }
  760. }
  761. } catch (e_1_1) {
  762. e_1 = { error: e_1_1 };
  763. } finally {
  764. try {
  765. if (fields_1_1 && !fields_1_1.done && (_a2 = fields_1.return))
  766. _a2.call(fields_1);
  767. } finally {
  768. if (e_1) throw e_1.error;
  769. }
  770. }
  771. };
  772. MiniSearch2.prototype.addAll = function (documents) {
  773. var e_4, _a2;
  774. try {
  775. for (
  776. var documents_1 = __values(documents), documents_1_1 = documents_1.next();
  777. !documents_1_1.done;
  778. documents_1_1 = documents_1.next()
  779. ) {
  780. var document_1 = documents_1_1.value;
  781. this.add(document_1);
  782. }
  783. } catch (e_4_1) {
  784. e_4 = { error: e_4_1 };
  785. } finally {
  786. try {
  787. if (documents_1_1 && !documents_1_1.done && (_a2 = documents_1.return))
  788. _a2.call(documents_1);
  789. } finally {
  790. if (e_4) throw e_4.error;
  791. }
  792. }
  793. };
  794. MiniSearch2.prototype.addAllAsync = function (documents, options) {
  795. var _this = this;
  796. if (options === void 0) {
  797. options = {};
  798. }
  799. var _a2 = options.chunkSize,
  800. chunkSize = _a2 === void 0 ? 10 : _a2;
  801. var acc = { chunk: [], promise: Promise.resolve() };
  802. var _b = documents.reduce(function (_a3, document, i) {
  803. var chunk2 = _a3.chunk,
  804. promise2 = _a3.promise;
  805. chunk2.push(document);
  806. if ((i + 1) % chunkSize === 0) {
  807. return {
  808. chunk: [],
  809. promise: promise2
  810. .then(function () {
  811. return new Promise(function (resolve) {
  812. return setTimeout(resolve, 0);
  813. });
  814. })
  815. .then(function () {
  816. return _this.addAll(chunk2);
  817. })
  818. };
  819. } else {
  820. return { chunk: chunk2, promise: promise2 };
  821. }
  822. }, acc),
  823. chunk = _b.chunk,
  824. promise = _b.promise;
  825. return promise.then(function () {
  826. return _this.addAll(chunk);
  827. });
  828. };
  829. MiniSearch2.prototype.remove = function (document) {
  830. var e_5, _a2, e_6, _b, e_7, _c;
  831. var _d = this._options,
  832. tokenize = _d.tokenize,
  833. processTerm = _d.processTerm,
  834. extractField = _d.extractField,
  835. fields = _d.fields,
  836. idField = _d.idField;
  837. var id = extractField(document, idField);
  838. if (id == null) {
  839. throw new Error(
  840. 'MiniSearch: document does not have ID field "'.concat(idField, '"')
  841. );
  842. }
  843. var shortId = this._idToShortId.get(id);
  844. if (shortId == null) {
  845. throw new Error(
  846. 'MiniSearch: cannot remove document with ID '.concat(
  847. id,
  848. ': it is not in the index'
  849. )
  850. );
  851. }
  852. try {
  853. for (
  854. var fields_2 = __values(fields), fields_2_1 = fields_2.next();
  855. !fields_2_1.done;
  856. fields_2_1 = fields_2.next()
  857. ) {
  858. var field = fields_2_1.value;
  859. var fieldValue = extractField(document, field);
  860. if (fieldValue == null) continue;
  861. var tokens = tokenize(fieldValue.toString(), field);
  862. var fieldId = this._fieldIds[field];
  863. var uniqueTerms = new Set(tokens).size;
  864. this.removeFieldLength(shortId, fieldId, this._documentCount, uniqueTerms);
  865. try {
  866. for (
  867. var tokens_2 = ((e_6 = void 0), __values(tokens)),
  868. tokens_2_1 = tokens_2.next();
  869. !tokens_2_1.done;
  870. tokens_2_1 = tokens_2.next()
  871. ) {
  872. var term = tokens_2_1.value;
  873. var processedTerm = processTerm(term, field);
  874. if (Array.isArray(processedTerm)) {
  875. try {
  876. for (
  877. var processedTerm_2 =
  878. ((e_7 = void 0), __values(processedTerm)),
  879. processedTerm_2_1 = processedTerm_2.next();
  880. !processedTerm_2_1.done;
  881. processedTerm_2_1 = processedTerm_2.next()
  882. ) {
  883. var t = processedTerm_2_1.value;
  884. this.removeTerm(fieldId, shortId, t);
  885. }
  886. } catch (e_7_1) {
  887. e_7 = { error: e_7_1 };
  888. } finally {
  889. try {
  890. if (
  891. processedTerm_2_1 &&
  892. !processedTerm_2_1.done &&
  893. (_c = processedTerm_2.return)
  894. )
  895. _c.call(processedTerm_2);
  896. } finally {
  897. if (e_7) throw e_7.error;
  898. }
  899. }
  900. } else if (processedTerm) {
  901. this.removeTerm(fieldId, shortId, processedTerm);
  902. }
  903. }
  904. } catch (e_6_1) {
  905. e_6 = { error: e_6_1 };
  906. } finally {
  907. try {
  908. if (tokens_2_1 && !tokens_2_1.done && (_b = tokens_2.return))
  909. _b.call(tokens_2);
  910. } finally {
  911. if (e_6) throw e_6.error;
  912. }
  913. }
  914. }
  915. } catch (e_5_1) {
  916. e_5 = { error: e_5_1 };
  917. } finally {
  918. try {
  919. if (fields_2_1 && !fields_2_1.done && (_a2 = fields_2.return))
  920. _a2.call(fields_2);
  921. } finally {
  922. if (e_5) throw e_5.error;
  923. }
  924. }
  925. this._storedFields.delete(shortId);
  926. this._documentIds.delete(shortId);
  927. this._idToShortId.delete(id);
  928. this._fieldLength.delete(shortId);
  929. this._documentCount -= 1;
  930. };
  931. MiniSearch2.prototype.removeAll = function (documents) {
  932. var e_8, _a2;
  933. if (documents) {
  934. try {
  935. for (
  936. var documents_2 = __values(documents), documents_2_1 = documents_2.next();
  937. !documents_2_1.done;
  938. documents_2_1 = documents_2.next()
  939. ) {
  940. var document_2 = documents_2_1.value;
  941. this.remove(document_2);
  942. }
  943. } catch (e_8_1) {
  944. e_8 = { error: e_8_1 };
  945. } finally {
  946. try {
  947. if (documents_2_1 && !documents_2_1.done && (_a2 = documents_2.return))
  948. _a2.call(documents_2);
  949. } finally {
  950. if (e_8) throw e_8.error;
  951. }
  952. }
  953. } else if (arguments.length > 0) {
  954. throw new Error(
  955. 'Expected documents to be present. Omit the argument to remove all documents.'
  956. );
  957. } else {
  958. this._index = new SearchableMap();
  959. this._documentCount = 0;
  960. this._documentIds = /* @__PURE__ */ new Map();
  961. this._idToShortId = /* @__PURE__ */ new Map();
  962. this._fieldLength = /* @__PURE__ */ new Map();
  963. this._avgFieldLength = [];
  964. this._storedFields = /* @__PURE__ */ new Map();
  965. this._nextId = 0;
  966. }
  967. };
  968. MiniSearch2.prototype.discard = function (id) {
  969. var _this = this;
  970. var shortId = this._idToShortId.get(id);
  971. if (shortId == null) {
  972. throw new Error(
  973. 'MiniSearch: cannot discard document with ID '.concat(
  974. id,
  975. ': it is not in the index'
  976. )
  977. );
  978. }
  979. this._idToShortId.delete(id);
  980. this._documentIds.delete(shortId);
  981. this._storedFields.delete(shortId);
  982. (this._fieldLength.get(shortId) || []).forEach(function (fieldLength, fieldId) {
  983. _this.removeFieldLength(shortId, fieldId, _this._documentCount, fieldLength);
  984. });
  985. this._fieldLength.delete(shortId);
  986. this._documentCount -= 1;
  987. this._dirtCount += 1;
  988. this.maybeAutoVacuum();
  989. };
  990. MiniSearch2.prototype.maybeAutoVacuum = function () {
  991. if (this._options.autoVacuum === false) {
  992. return;
  993. }
  994. var _a2 = this._options.autoVacuum,
  995. minDirtFactor = _a2.minDirtFactor,
  996. minDirtCount = _a2.minDirtCount,
  997. batchSize = _a2.batchSize,
  998. batchWait = _a2.batchWait;
  999. this.conditionalVacuum({ batchSize, batchWait }, { minDirtCount, minDirtFactor });
  1000. };
  1001. MiniSearch2.prototype.discardAll = function (ids) {
  1002. var e_9, _a2;
  1003. var autoVacuum = this._options.autoVacuum;
  1004. try {
  1005. this._options.autoVacuum = false;
  1006. try {
  1007. for (
  1008. var ids_1 = __values(ids), ids_1_1 = ids_1.next();
  1009. !ids_1_1.done;
  1010. ids_1_1 = ids_1.next()
  1011. ) {
  1012. var id = ids_1_1.value;
  1013. this.discard(id);
  1014. }
  1015. } catch (e_9_1) {
  1016. e_9 = { error: e_9_1 };
  1017. } finally {
  1018. try {
  1019. if (ids_1_1 && !ids_1_1.done && (_a2 = ids_1.return)) _a2.call(ids_1);
  1020. } finally {
  1021. if (e_9) throw e_9.error;
  1022. }
  1023. }
  1024. } finally {
  1025. this._options.autoVacuum = autoVacuum;
  1026. }
  1027. this.maybeAutoVacuum();
  1028. };
  1029. MiniSearch2.prototype.replace = function (updatedDocument) {
  1030. var _a2 = this._options,
  1031. idField = _a2.idField,
  1032. extractField = _a2.extractField;
  1033. var id = extractField(updatedDocument, idField);
  1034. this.discard(id);
  1035. this.add(updatedDocument);
  1036. };
  1037. MiniSearch2.prototype.vacuum = function (options) {
  1038. if (options === void 0) {
  1039. options = {};
  1040. }
  1041. return this.conditionalVacuum(options);
  1042. };
  1043. MiniSearch2.prototype.conditionalVacuum = function (options, conditions) {
  1044. var _this = this;
  1045. if (this._currentVacuum) {
  1046. this._enqueuedVacuumConditions = this._enqueuedVacuumConditions && conditions;
  1047. if (this._enqueuedVacuum != null) {
  1048. return this._enqueuedVacuum;
  1049. }
  1050. this._enqueuedVacuum = this._currentVacuum.then(function () {
  1051. var conditions2 = _this._enqueuedVacuumConditions;
  1052. _this._enqueuedVacuumConditions = defaultVacuumConditions;
  1053. return _this.performVacuuming(options, conditions2);
  1054. });
  1055. return this._enqueuedVacuum;
  1056. }
  1057. if (this.vacuumConditionsMet(conditions) === false) {
  1058. return Promise.resolve();
  1059. }
  1060. this._currentVacuum = this.performVacuuming(options);
  1061. return this._currentVacuum;
  1062. };
  1063. MiniSearch2.prototype.performVacuuming = function (options, conditions) {
  1064. return __awaiter(this, void 0, void 0, function () {
  1065. var initialDirtCount,
  1066. batchSize,
  1067. batchWait_1,
  1068. i,
  1069. _a2,
  1070. _b,
  1071. _c,
  1072. term,
  1073. fieldsData,
  1074. fieldsData_1,
  1075. fieldsData_1_1,
  1076. _d,
  1077. fieldId,
  1078. fieldIndex,
  1079. fieldIndex_1,
  1080. fieldIndex_1_1,
  1081. _e,
  1082. shortId,
  1083. e_10_1;
  1084. var e_10, _f, e_11, _g, e_12, _h;
  1085. return __generator(this, function (_j) {
  1086. switch (_j.label) {
  1087. case 0:
  1088. initialDirtCount = this._dirtCount;
  1089. if (!this.vacuumConditionsMet(conditions)) return [3, 10];
  1090. batchSize = options.batchSize || defaultVacuumOptions.batchSize;
  1091. batchWait_1 = options.batchWait || defaultVacuumOptions.batchWait;
  1092. i = 1;
  1093. _j.label = 1;
  1094. case 1:
  1095. _j.trys.push([1, 7, 8, 9]);
  1096. (_a2 = __values(this._index)), (_b = _a2.next());
  1097. _j.label = 2;
  1098. case 2:
  1099. if (!!_b.done) return [3, 6];
  1100. (_c = __read(_b.value, 2)), (term = _c[0]), (fieldsData = _c[1]);
  1101. try {
  1102. for (
  1103. fieldsData_1 = ((e_11 = void 0), __values(fieldsData)),
  1104. fieldsData_1_1 = fieldsData_1.next();
  1105. !fieldsData_1_1.done;
  1106. fieldsData_1_1 = fieldsData_1.next()
  1107. ) {
  1108. (_d = __read(fieldsData_1_1.value, 2)),
  1109. (fieldId = _d[0]),
  1110. (fieldIndex = _d[1]);
  1111. try {
  1112. for (
  1113. fieldIndex_1 = ((e_12 = void 0), __values(fieldIndex)),
  1114. fieldIndex_1_1 = fieldIndex_1.next();
  1115. !fieldIndex_1_1.done;
  1116. fieldIndex_1_1 = fieldIndex_1.next()
  1117. ) {
  1118. (_e = __read(fieldIndex_1_1.value, 1)),
  1119. (shortId = _e[0]);
  1120. if (this._documentIds.has(shortId)) {
  1121. continue;
  1122. }
  1123. if (fieldIndex.size <= 1) {
  1124. fieldsData.delete(fieldId);
  1125. } else {
  1126. fieldIndex.delete(shortId);
  1127. }
  1128. }
  1129. } catch (e_12_1) {
  1130. e_12 = { error: e_12_1 };
  1131. } finally {
  1132. try {
  1133. if (
  1134. fieldIndex_1_1 &&
  1135. !fieldIndex_1_1.done &&
  1136. (_h = fieldIndex_1.return)
  1137. )
  1138. _h.call(fieldIndex_1);
  1139. } finally {
  1140. if (e_12) throw e_12.error;
  1141. }
  1142. }
  1143. }
  1144. } catch (e_11_1) {
  1145. e_11 = { error: e_11_1 };
  1146. } finally {
  1147. try {
  1148. if (
  1149. fieldsData_1_1 &&
  1150. !fieldsData_1_1.done &&
  1151. (_g = fieldsData_1.return)
  1152. )
  1153. _g.call(fieldsData_1);
  1154. } finally {
  1155. if (e_11) throw e_11.error;
  1156. }
  1157. }
  1158. if (this._index.get(term).size === 0) {
  1159. this._index.delete(term);
  1160. }
  1161. if (!(i % batchSize === 0)) return [3, 4];
  1162. return [
  1163. 4,
  1164. new Promise(function (resolve) {
  1165. return setTimeout(resolve, batchWait_1);
  1166. })
  1167. ];
  1168. case 3:
  1169. _j.sent();
  1170. _j.label = 4;
  1171. case 4:
  1172. i += 1;
  1173. _j.label = 5;
  1174. case 5:
  1175. _b = _a2.next();
  1176. return [3, 2];
  1177. case 6:
  1178. return [3, 9];
  1179. case 7:
  1180. e_10_1 = _j.sent();
  1181. e_10 = { error: e_10_1 };
  1182. return [3, 9];
  1183. case 8:
  1184. try {
  1185. if (_b && !_b.done && (_f = _a2.return)) _f.call(_a2);
  1186. } finally {
  1187. if (e_10) throw e_10.error;
  1188. }
  1189. return [
  1190. 7
  1191. /*endfinally*/
  1192. ];
  1193. case 9:
  1194. this._dirtCount -= initialDirtCount;
  1195. _j.label = 10;
  1196. case 10:
  1197. return [4, null];
  1198. case 11:
  1199. _j.sent();
  1200. this._currentVacuum = this._enqueuedVacuum;
  1201. this._enqueuedVacuum = null;
  1202. return [
  1203. 2
  1204. /*return*/
  1205. ];
  1206. }
  1207. });
  1208. });
  1209. };
  1210. MiniSearch2.prototype.vacuumConditionsMet = function (conditions) {
  1211. if (conditions == null) {
  1212. return true;
  1213. }
  1214. var minDirtCount = conditions.minDirtCount,
  1215. minDirtFactor = conditions.minDirtFactor;
  1216. minDirtCount = minDirtCount || defaultAutoVacuumOptions.minDirtCount;
  1217. minDirtFactor = minDirtFactor || defaultAutoVacuumOptions.minDirtFactor;
  1218. return this.dirtCount >= minDirtCount && this.dirtFactor >= minDirtFactor;
  1219. };
  1220. Object.defineProperty(MiniSearch2.prototype, 'isVacuuming', {
  1221. /**
  1222. * Is `true` if a vacuuming operation is ongoing, `false` otherwise
  1223. */
  1224. get: function () {
  1225. return this._currentVacuum != null;
  1226. },
  1227. enumerable: false,
  1228. configurable: true
  1229. });
  1230. Object.defineProperty(MiniSearch2.prototype, 'dirtCount', {
  1231. /**
  1232. * The number of documents discarded since the most recent vacuuming
  1233. */
  1234. get: function () {
  1235. return this._dirtCount;
  1236. },
  1237. enumerable: false,
  1238. configurable: true
  1239. });
  1240. Object.defineProperty(MiniSearch2.prototype, 'dirtFactor', {
  1241. /**
  1242. * A number between 0 and 1 giving an indication about the proportion of
  1243. * documents that are discarded, and can therefore be cleaned up by vacuuming.
  1244. * A value close to 0 means that the index is relatively clean, while a higher
  1245. * value means that the index is relatively dirty, and vacuuming could release
  1246. * memory.
  1247. */
  1248. get: function () {
  1249. return this._dirtCount / (1 + this._documentCount + this._dirtCount);
  1250. },
  1251. enumerable: false,
  1252. configurable: true
  1253. });
  1254. MiniSearch2.prototype.has = function (id) {
  1255. return this._idToShortId.has(id);
  1256. };
  1257. MiniSearch2.prototype.getStoredFields = function (id) {
  1258. var shortId = this._idToShortId.get(id);
  1259. if (shortId == null) {
  1260. return void 0;
  1261. }
  1262. return this._storedFields.get(shortId);
  1263. };
  1264. MiniSearch2.prototype.search = function (query, searchOptions) {
  1265. var e_13, _a2;
  1266. if (searchOptions === void 0) {
  1267. searchOptions = {};
  1268. }
  1269. var rawResults = this.executeQuery(query, searchOptions);
  1270. var results = [];
  1271. try {
  1272. for (
  1273. var rawResults_1 = __values(rawResults), rawResults_1_1 = rawResults_1.next();
  1274. !rawResults_1_1.done;
  1275. rawResults_1_1 = rawResults_1.next()
  1276. ) {
  1277. var _b = __read(rawResults_1_1.value, 2),
  1278. docId = _b[0],
  1279. _c = _b[1],
  1280. score = _c.score,
  1281. terms = _c.terms,
  1282. match = _c.match;
  1283. var quality = terms.length || 1;
  1284. var result = {
  1285. id: this._documentIds.get(docId),
  1286. score: score * quality,
  1287. terms: Object.keys(match),
  1288. queryTerms: terms,
  1289. match
  1290. };
  1291. Object.assign(result, this._storedFields.get(docId));
  1292. if (searchOptions.filter == null || searchOptions.filter(result)) {
  1293. results.push(result);
  1294. }
  1295. }
  1296. } catch (e_13_1) {
  1297. e_13 = { error: e_13_1 };
  1298. } finally {
  1299. try {
  1300. if (rawResults_1_1 && !rawResults_1_1.done && (_a2 = rawResults_1.return))
  1301. _a2.call(rawResults_1);
  1302. } finally {
  1303. if (e_13) throw e_13.error;
  1304. }
  1305. }
  1306. if (
  1307. query === MiniSearch2.wildcard &&
  1308. searchOptions.boostDocument == null &&
  1309. this._options.searchOptions.boostDocument == null
  1310. ) {
  1311. return results;
  1312. }
  1313. results.sort(byScore);
  1314. return results;
  1315. };
  1316. MiniSearch2.prototype.autoSuggest = function (queryString, options) {
  1317. var e_14, _a2, e_15, _b;
  1318. if (options === void 0) {
  1319. options = {};
  1320. }
  1321. options = __assign(__assign({}, this._options.autoSuggestOptions), options);
  1322. var suggestions = /* @__PURE__ */ new Map();
  1323. try {
  1324. for (
  1325. var _c = __values(this.search(queryString, options)), _d = _c.next();
  1326. !_d.done;
  1327. _d = _c.next()
  1328. ) {
  1329. var _e = _d.value,
  1330. score = _e.score,
  1331. terms = _e.terms;
  1332. var phrase = terms.join(' ');
  1333. var suggestion = suggestions.get(phrase);
  1334. if (suggestion != null) {
  1335. suggestion.score += score;
  1336. suggestion.count += 1;
  1337. } else {
  1338. suggestions.set(phrase, { score, terms, count: 1 });
  1339. }
  1340. }
  1341. } catch (e_14_1) {
  1342. e_14 = { error: e_14_1 };
  1343. } finally {
  1344. try {
  1345. if (_d && !_d.done && (_a2 = _c.return)) _a2.call(_c);
  1346. } finally {
  1347. if (e_14) throw e_14.error;
  1348. }
  1349. }
  1350. var results = [];
  1351. try {
  1352. for (
  1353. var suggestions_1 = __values(suggestions),
  1354. suggestions_1_1 = suggestions_1.next();
  1355. !suggestions_1_1.done;
  1356. suggestions_1_1 = suggestions_1.next()
  1357. ) {
  1358. var _f = __read(suggestions_1_1.value, 2),
  1359. suggestion = _f[0],
  1360. _g = _f[1],
  1361. score = _g.score,
  1362. terms = _g.terms,
  1363. count = _g.count;
  1364. results.push({ suggestion, terms, score: score / count });
  1365. }
  1366. } catch (e_15_1) {
  1367. e_15 = { error: e_15_1 };
  1368. } finally {
  1369. try {
  1370. if (suggestions_1_1 && !suggestions_1_1.done && (_b = suggestions_1.return))
  1371. _b.call(suggestions_1);
  1372. } finally {
  1373. if (e_15) throw e_15.error;
  1374. }
  1375. }
  1376. results.sort(byScore);
  1377. return results;
  1378. };
  1379. Object.defineProperty(MiniSearch2.prototype, 'documentCount', {
  1380. /**
  1381. * Total number of documents available to search
  1382. */
  1383. get: function () {
  1384. return this._documentCount;
  1385. },
  1386. enumerable: false,
  1387. configurable: true
  1388. });
  1389. Object.defineProperty(MiniSearch2.prototype, 'termCount', {
  1390. /**
  1391. * Number of terms in the index
  1392. */
  1393. get: function () {
  1394. return this._index.size;
  1395. },
  1396. enumerable: false,
  1397. configurable: true
  1398. });
  1399. MiniSearch2.loadJSON = function (json, options) {
  1400. if (options == null) {
  1401. throw new Error(
  1402. 'MiniSearch: loadJSON should be given the same options used when serializing the index'
  1403. );
  1404. }
  1405. return this.loadJS(JSON.parse(json), options);
  1406. };
  1407. MiniSearch2.getDefault = function (optionName) {
  1408. if (defaultOptions.hasOwnProperty(optionName)) {
  1409. return getOwnProperty(defaultOptions, optionName);
  1410. } else {
  1411. throw new Error('MiniSearch: unknown option "'.concat(optionName, '"'));
  1412. }
  1413. };
  1414. MiniSearch2.loadJS = function (js, options) {
  1415. var e_16, _a2, e_17, _b, e_18, _c;
  1416. var index = js.index,
  1417. documentCount = js.documentCount,
  1418. nextId = js.nextId,
  1419. documentIds = js.documentIds,
  1420. fieldIds = js.fieldIds,
  1421. fieldLength = js.fieldLength,
  1422. averageFieldLength = js.averageFieldLength,
  1423. storedFields = js.storedFields,
  1424. dirtCount = js.dirtCount,
  1425. serializationVersion = js.serializationVersion;
  1426. if (serializationVersion !== 1 && serializationVersion !== 2) {
  1427. throw new Error(
  1428. 'MiniSearch: cannot deserialize an index created with an incompatible version'
  1429. );
  1430. }
  1431. var miniSearch = new MiniSearch2(options);
  1432. miniSearch._documentCount = documentCount;
  1433. miniSearch._nextId = nextId;
  1434. miniSearch._documentIds = objectToNumericMap(documentIds);
  1435. miniSearch._idToShortId = /* @__PURE__ */ new Map();
  1436. miniSearch._fieldIds = fieldIds;
  1437. miniSearch._fieldLength = objectToNumericMap(fieldLength);
  1438. miniSearch._avgFieldLength = averageFieldLength;
  1439. miniSearch._storedFields = objectToNumericMap(storedFields);
  1440. miniSearch._dirtCount = dirtCount || 0;
  1441. miniSearch._index = new SearchableMap();
  1442. try {
  1443. for (
  1444. var _d = __values(miniSearch._documentIds), _e = _d.next();
  1445. !_e.done;
  1446. _e = _d.next()
  1447. ) {
  1448. var _f = __read(_e.value, 2),
  1449. shortId = _f[0],
  1450. id = _f[1];
  1451. miniSearch._idToShortId.set(id, shortId);
  1452. }
  1453. } catch (e_16_1) {
  1454. e_16 = { error: e_16_1 };
  1455. } finally {
  1456. try {
  1457. if (_e && !_e.done && (_a2 = _d.return)) _a2.call(_d);
  1458. } finally {
  1459. if (e_16) throw e_16.error;
  1460. }
  1461. }
  1462. try {
  1463. for (
  1464. var index_1 = __values(index), index_1_1 = index_1.next();
  1465. !index_1_1.done;
  1466. index_1_1 = index_1.next()
  1467. ) {
  1468. var _g = __read(index_1_1.value, 2),
  1469. term = _g[0],
  1470. data = _g[1];
  1471. var dataMap = /* @__PURE__ */ new Map();
  1472. try {
  1473. for (
  1474. var _h = ((e_18 = void 0), __values(Object.keys(data))), _j = _h.next();
  1475. !_j.done;
  1476. _j = _h.next()
  1477. ) {
  1478. var fieldId = _j.value;
  1479. var indexEntry = data[fieldId];
  1480. if (serializationVersion === 1) {
  1481. indexEntry = indexEntry.ds;
  1482. }
  1483. dataMap.set(parseInt(fieldId, 10), objectToNumericMap(indexEntry));
  1484. }
  1485. } catch (e_18_1) {
  1486. e_18 = { error: e_18_1 };
  1487. } finally {
  1488. try {
  1489. if (_j && !_j.done && (_c = _h.return)) _c.call(_h);
  1490. } finally {
  1491. if (e_18) throw e_18.error;
  1492. }
  1493. }
  1494. miniSearch._index.set(term, dataMap);
  1495. }
  1496. } catch (e_17_1) {
  1497. e_17 = { error: e_17_1 };
  1498. } finally {
  1499. try {
  1500. if (index_1_1 && !index_1_1.done && (_b = index_1.return)) _b.call(index_1);
  1501. } finally {
  1502. if (e_17) throw e_17.error;
  1503. }
  1504. }
  1505. return miniSearch;
  1506. };
  1507. MiniSearch2.prototype.executeQuery = function (query, searchOptions) {
  1508. var _this = this;
  1509. if (searchOptions === void 0) {
  1510. searchOptions = {};
  1511. }
  1512. if (query === MiniSearch2.wildcard) {
  1513. return this.executeWildcardQuery(searchOptions);
  1514. }
  1515. if (typeof query !== 'string') {
  1516. var options_1 = __assign(__assign(__assign({}, searchOptions), query), {
  1517. queries: void 0
  1518. });
  1519. var results_1 = query.queries.map(function (subquery) {
  1520. return _this.executeQuery(subquery, options_1);
  1521. });
  1522. return this.combineResults(results_1, options_1.combineWith);
  1523. }
  1524. var _a2 = this._options,
  1525. tokenize = _a2.tokenize,
  1526. processTerm = _a2.processTerm,
  1527. globalSearchOptions = _a2.searchOptions;
  1528. var options = __assign(
  1529. __assign({ tokenize, processTerm }, globalSearchOptions),
  1530. searchOptions
  1531. );
  1532. var searchTokenize = options.tokenize,
  1533. searchProcessTerm = options.processTerm;
  1534. var terms = searchTokenize(query)
  1535. .flatMap(function (term) {
  1536. return searchProcessTerm(term);
  1537. })
  1538. .filter(function (term) {
  1539. return !!term;
  1540. });
  1541. var queries = terms.map(termToQuerySpec(options));
  1542. var results = queries.map(function (query2) {
  1543. return _this.executeQuerySpec(query2, options);
  1544. });
  1545. return this.combineResults(results, options.combineWith);
  1546. };
  1547. MiniSearch2.prototype.executeQuerySpec = function (query, searchOptions) {
  1548. var e_19, _a2, e_20, _b;
  1549. var options = __assign(__assign({}, this._options.searchOptions), searchOptions);
  1550. var boosts = (options.fields || this._options.fields).reduce(function (boosts2, field) {
  1551. var _a3;
  1552. return __assign(
  1553. __assign({}, boosts2),
  1554. ((_a3 = {}), (_a3[field] = getOwnProperty(options.boost, field) || 1), _a3)
  1555. );
  1556. }, {});
  1557. var boostDocument = options.boostDocument,
  1558. weights = options.weights,
  1559. maxFuzzy = options.maxFuzzy,
  1560. bm25params = options.bm25;
  1561. var _c = __assign(__assign({}, defaultSearchOptions.weights), weights),
  1562. fuzzyWeight = _c.fuzzy,
  1563. prefixWeight = _c.prefix;
  1564. var data = this._index.get(query.term);
  1565. var results = this.termResults(
  1566. query.term,
  1567. query.term,
  1568. 1,
  1569. data,
  1570. boosts,
  1571. boostDocument,
  1572. bm25params
  1573. );
  1574. var prefixMatches;
  1575. var fuzzyMatches;
  1576. if (query.prefix) {
  1577. prefixMatches = this._index.atPrefix(query.term);
  1578. }
  1579. if (query.fuzzy) {
  1580. var fuzzy = query.fuzzy === true ? 0.2 : query.fuzzy;
  1581. var maxDistance =
  1582. fuzzy < 1 ? Math.min(maxFuzzy, Math.round(query.term.length * fuzzy)) : fuzzy;
  1583. if (maxDistance) fuzzyMatches = this._index.fuzzyGet(query.term, maxDistance);
  1584. }
  1585. if (prefixMatches) {
  1586. try {
  1587. for (
  1588. var prefixMatches_1 = __values(prefixMatches),
  1589. prefixMatches_1_1 = prefixMatches_1.next();
  1590. !prefixMatches_1_1.done;
  1591. prefixMatches_1_1 = prefixMatches_1.next()
  1592. ) {
  1593. var _d = __read(prefixMatches_1_1.value, 2),
  1594. term = _d[0],
  1595. data_1 = _d[1];
  1596. var distance = term.length - query.term.length;
  1597. if (!distance) {
  1598. continue;
  1599. }
  1600. fuzzyMatches === null || fuzzyMatches === void 0
  1601. ? void 0
  1602. : fuzzyMatches.delete(term);
  1603. var weight = (prefixWeight * term.length) / (term.length + 0.3 * distance);
  1604. this.termResults(
  1605. query.term,
  1606. term,
  1607. weight,
  1608. data_1,
  1609. boosts,
  1610. boostDocument,
  1611. bm25params,
  1612. results
  1613. );
  1614. }
  1615. } catch (e_19_1) {
  1616. e_19 = { error: e_19_1 };
  1617. } finally {
  1618. try {
  1619. if (
  1620. prefixMatches_1_1 &&
  1621. !prefixMatches_1_1.done &&
  1622. (_a2 = prefixMatches_1.return)
  1623. )
  1624. _a2.call(prefixMatches_1);
  1625. } finally {
  1626. if (e_19) throw e_19.error;
  1627. }
  1628. }
  1629. }
  1630. if (fuzzyMatches) {
  1631. try {
  1632. for (
  1633. var _e = __values(fuzzyMatches.keys()), _f = _e.next();
  1634. !_f.done;
  1635. _f = _e.next()
  1636. ) {
  1637. var term = _f.value;
  1638. var _g = __read(fuzzyMatches.get(term), 2),
  1639. data_2 = _g[0],
  1640. distance = _g[1];
  1641. if (!distance) {
  1642. continue;
  1643. }
  1644. var weight = (fuzzyWeight * term.length) / (term.length + distance);
  1645. this.termResults(
  1646. query.term,
  1647. term,
  1648. weight,
  1649. data_2,
  1650. boosts,
  1651. boostDocument,
  1652. bm25params,
  1653. results
  1654. );
  1655. }
  1656. } catch (e_20_1) {
  1657. e_20 = { error: e_20_1 };
  1658. } finally {
  1659. try {
  1660. if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
  1661. } finally {
  1662. if (e_20) throw e_20.error;
  1663. }
  1664. }
  1665. }
  1666. return results;
  1667. };
  1668. MiniSearch2.prototype.executeWildcardQuery = function (searchOptions) {
  1669. var e_21, _a2;
  1670. var results = /* @__PURE__ */ new Map();
  1671. var options = __assign(__assign({}, this._options.searchOptions), searchOptions);
  1672. try {
  1673. for (
  1674. var _b = __values(this._documentIds), _c = _b.next();
  1675. !_c.done;
  1676. _c = _b.next()
  1677. ) {
  1678. var _d = __read(_c.value, 2),
  1679. shortId = _d[0],
  1680. id = _d[1];
  1681. var score = options.boostDocument
  1682. ? options.boostDocument(id, '', this._storedFields.get(shortId))
  1683. : 1;
  1684. results.set(shortId, {
  1685. score,
  1686. terms: [],
  1687. match: {}
  1688. });
  1689. }
  1690. } catch (e_21_1) {
  1691. e_21 = { error: e_21_1 };
  1692. } finally {
  1693. try {
  1694. if (_c && !_c.done && (_a2 = _b.return)) _a2.call(_b);
  1695. } finally {
  1696. if (e_21) throw e_21.error;
  1697. }
  1698. }
  1699. return results;
  1700. };
  1701. MiniSearch2.prototype.combineResults = function (results, combineWith) {
  1702. if (combineWith === void 0) {
  1703. combineWith = OR;
  1704. }
  1705. if (results.length === 0) {
  1706. return /* @__PURE__ */ new Map();
  1707. }
  1708. var operator = combineWith.toLowerCase();
  1709. return results.reduce(combinators[operator]) || /* @__PURE__ */ new Map();
  1710. };
  1711. MiniSearch2.prototype.toJSON = function () {
  1712. var e_22, _a2, e_23, _b;
  1713. var index = [];
  1714. try {
  1715. for (var _c = __values(this._index), _d = _c.next(); !_d.done; _d = _c.next()) {
  1716. var _e = __read(_d.value, 2),
  1717. term = _e[0],
  1718. fieldIndex = _e[1];
  1719. var data = {};
  1720. try {
  1721. for (
  1722. var fieldIndex_2 = ((e_23 = void 0), __values(fieldIndex)),
  1723. fieldIndex_2_1 = fieldIndex_2.next();
  1724. !fieldIndex_2_1.done;
  1725. fieldIndex_2_1 = fieldIndex_2.next()
  1726. ) {
  1727. var _f = __read(fieldIndex_2_1.value, 2),
  1728. fieldId = _f[0],
  1729. freqs = _f[1];
  1730. data[fieldId] = Object.fromEntries(freqs);
  1731. }
  1732. } catch (e_23_1) {
  1733. e_23 = { error: e_23_1 };
  1734. } finally {
  1735. try {
  1736. if (
  1737. fieldIndex_2_1 &&
  1738. !fieldIndex_2_1.done &&
  1739. (_b = fieldIndex_2.return)
  1740. )
  1741. _b.call(fieldIndex_2);
  1742. } finally {
  1743. if (e_23) throw e_23.error;
  1744. }
  1745. }
  1746. index.push([term, data]);
  1747. }
  1748. } catch (e_22_1) {
  1749. e_22 = { error: e_22_1 };
  1750. } finally {
  1751. try {
  1752. if (_d && !_d.done && (_a2 = _c.return)) _a2.call(_c);
  1753. } finally {
  1754. if (e_22) throw e_22.error;
  1755. }
  1756. }
  1757. return {
  1758. documentCount: this._documentCount,
  1759. nextId: this._nextId,
  1760. documentIds: Object.fromEntries(this._documentIds),
  1761. fieldIds: this._fieldIds,
  1762. fieldLength: Object.fromEntries(this._fieldLength),
  1763. averageFieldLength: this._avgFieldLength,
  1764. storedFields: Object.fromEntries(this._storedFields),
  1765. dirtCount: this._dirtCount,
  1766. index,
  1767. serializationVersion: 2
  1768. };
  1769. };
  1770. MiniSearch2.prototype.termResults = function (
  1771. sourceTerm,
  1772. derivedTerm,
  1773. termWeight,
  1774. fieldTermData,
  1775. fieldBoosts,
  1776. boostDocumentFn,
  1777. bm25params,
  1778. results
  1779. ) {
  1780. var e_24, _a2, e_25, _b, _c;
  1781. if (results === void 0) {
  1782. results = /* @__PURE__ */ new Map();
  1783. }
  1784. if (fieldTermData == null) return results;
  1785. try {
  1786. for (
  1787. var _d = __values(Object.keys(fieldBoosts)), _e = _d.next();
  1788. !_e.done;
  1789. _e = _d.next()
  1790. ) {
  1791. var field = _e.value;
  1792. var fieldBoost = fieldBoosts[field];
  1793. var fieldId = this._fieldIds[field];
  1794. var fieldTermFreqs = fieldTermData.get(fieldId);
  1795. if (fieldTermFreqs == null) continue;
  1796. var matchingFields = fieldTermFreqs.size;
  1797. var avgFieldLength = this._avgFieldLength[fieldId];
  1798. try {
  1799. for (
  1800. var _f = ((e_25 = void 0), __values(fieldTermFreqs.keys())),
  1801. _g = _f.next();
  1802. !_g.done;
  1803. _g = _f.next()
  1804. ) {
  1805. var docId = _g.value;
  1806. if (!this._documentIds.has(docId)) {
  1807. this.removeTerm(fieldId, docId, derivedTerm);
  1808. matchingFields -= 1;
  1809. continue;
  1810. }
  1811. var docBoost = boostDocumentFn
  1812. ? boostDocumentFn(
  1813. this._documentIds.get(docId),
  1814. derivedTerm,
  1815. this._storedFields.get(docId)
  1816. )
  1817. : 1;
  1818. if (!docBoost) continue;
  1819. var termFreq = fieldTermFreqs.get(docId);
  1820. var fieldLength = this._fieldLength.get(docId)[fieldId];
  1821. var rawScore = calcBM25Score(
  1822. termFreq,
  1823. matchingFields,
  1824. this._documentCount,
  1825. fieldLength,
  1826. avgFieldLength,
  1827. bm25params
  1828. );
  1829. var weightedScore = termWeight * fieldBoost * docBoost * rawScore;
  1830. var result = results.get(docId);
  1831. if (result) {
  1832. result.score += weightedScore;
  1833. assignUniqueTerm(result.terms, sourceTerm);
  1834. var match = getOwnProperty(result.match, derivedTerm);
  1835. if (match) {
  1836. match.push(field);
  1837. } else {
  1838. result.match[derivedTerm] = [field];
  1839. }
  1840. } else {
  1841. results.set(docId, {
  1842. score: weightedScore,
  1843. terms: [sourceTerm],
  1844. match: ((_c = {}), (_c[derivedTerm] = [field]), _c)
  1845. });
  1846. }
  1847. }
  1848. } catch (e_25_1) {
  1849. e_25 = { error: e_25_1 };
  1850. } finally {
  1851. try {
  1852. if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
  1853. } finally {
  1854. if (e_25) throw e_25.error;
  1855. }
  1856. }
  1857. }
  1858. } catch (e_24_1) {
  1859. e_24 = { error: e_24_1 };
  1860. } finally {
  1861. try {
  1862. if (_e && !_e.done && (_a2 = _d.return)) _a2.call(_d);
  1863. } finally {
  1864. if (e_24) throw e_24.error;
  1865. }
  1866. }
  1867. return results;
  1868. };
  1869. MiniSearch2.prototype.addTerm = function (fieldId, documentId, term) {
  1870. var indexData = this._index.fetch(term, createMap);
  1871. var fieldIndex = indexData.get(fieldId);
  1872. if (fieldIndex == null) {
  1873. fieldIndex = /* @__PURE__ */ new Map();
  1874. fieldIndex.set(documentId, 1);
  1875. indexData.set(fieldId, fieldIndex);
  1876. } else {
  1877. var docs = fieldIndex.get(documentId);
  1878. fieldIndex.set(documentId, (docs || 0) + 1);
  1879. }
  1880. };
  1881. MiniSearch2.prototype.removeTerm = function (fieldId, documentId, term) {
  1882. if (!this._index.has(term)) {
  1883. this.warnDocumentChanged(documentId, fieldId, term);
  1884. return;
  1885. }
  1886. var indexData = this._index.fetch(term, createMap);
  1887. var fieldIndex = indexData.get(fieldId);
  1888. if (fieldIndex == null || fieldIndex.get(documentId) == null) {
  1889. this.warnDocumentChanged(documentId, fieldId, term);
  1890. } else if (fieldIndex.get(documentId) <= 1) {
  1891. if (fieldIndex.size <= 1) {
  1892. indexData.delete(fieldId);
  1893. } else {
  1894. fieldIndex.delete(documentId);
  1895. }
  1896. } else {
  1897. fieldIndex.set(documentId, fieldIndex.get(documentId) - 1);
  1898. }
  1899. if (this._index.get(term).size === 0) {
  1900. this._index.delete(term);
  1901. }
  1902. };
  1903. MiniSearch2.prototype.warnDocumentChanged = function (shortDocumentId, fieldId, term) {
  1904. var e_26, _a2;
  1905. try {
  1906. for (
  1907. var _b = __values(Object.keys(this._fieldIds)), _c = _b.next();
  1908. !_c.done;
  1909. _c = _b.next()
  1910. ) {
  1911. var fieldName = _c.value;
  1912. if (this._fieldIds[fieldName] === fieldId) {
  1913. this._options.logger(
  1914. 'warn',
  1915. 'MiniSearch: document with ID '
  1916. .concat(
  1917. this._documentIds.get(shortDocumentId),
  1918. ' has changed before removal: term "'
  1919. )
  1920. .concat(term, '" was not present in field "')
  1921. .concat(
  1922. fieldName,
  1923. '". Removing a document after it has changed can corrupt the index!'
  1924. ),
  1925. 'version_conflict'
  1926. );
  1927. return;
  1928. }
  1929. }
  1930. } catch (e_26_1) {
  1931. e_26 = { error: e_26_1 };
  1932. } finally {
  1933. try {
  1934. if (_c && !_c.done && (_a2 = _b.return)) _a2.call(_b);
  1935. } finally {
  1936. if (e_26) throw e_26.error;
  1937. }
  1938. }
  1939. };
  1940. MiniSearch2.prototype.addDocumentId = function (documentId) {
  1941. var shortDocumentId = this._nextId;
  1942. this._idToShortId.set(documentId, shortDocumentId);
  1943. this._documentIds.set(shortDocumentId, documentId);
  1944. this._documentCount += 1;
  1945. this._nextId += 1;
  1946. return shortDocumentId;
  1947. };
  1948. MiniSearch2.prototype.addFields = function (fields) {
  1949. for (var i = 0; i < fields.length; i++) {
  1950. this._fieldIds[fields[i]] = i;
  1951. }
  1952. };
  1953. MiniSearch2.prototype.addFieldLength = function (documentId, fieldId, count, length) {
  1954. var fieldLengths = this._fieldLength.get(documentId);
  1955. if (fieldLengths == null) this._fieldLength.set(documentId, (fieldLengths = []));
  1956. fieldLengths[fieldId] = length;
  1957. var averageFieldLength = this._avgFieldLength[fieldId] || 0;
  1958. var totalFieldLength = averageFieldLength * count + length;
  1959. this._avgFieldLength[fieldId] = totalFieldLength / (count + 1);
  1960. };
  1961. MiniSearch2.prototype.removeFieldLength = function (documentId, fieldId, count, length) {
  1962. if (count === 1) {
  1963. this._avgFieldLength[fieldId] = 0;
  1964. return;
  1965. }
  1966. var totalFieldLength = this._avgFieldLength[fieldId] * count - length;
  1967. this._avgFieldLength[fieldId] = totalFieldLength / (count - 1);
  1968. };
  1969. MiniSearch2.prototype.saveStoredFields = function (documentId, doc) {
  1970. var e_27, _a2;
  1971. var _b = this._options,
  1972. storeFields = _b.storeFields,
  1973. extractField = _b.extractField;
  1974. if (storeFields == null || storeFields.length === 0) {
  1975. return;
  1976. }
  1977. var documentFields = this._storedFields.get(documentId);
  1978. if (documentFields == null) this._storedFields.set(documentId, (documentFields = {}));
  1979. try {
  1980. for (
  1981. var storeFields_1 = __values(storeFields),
  1982. storeFields_1_1 = storeFields_1.next();
  1983. !storeFields_1_1.done;
  1984. storeFields_1_1 = storeFields_1.next()
  1985. ) {
  1986. var fieldName = storeFields_1_1.value;
  1987. var fieldValue = extractField(doc, fieldName);
  1988. if (fieldValue !== void 0) documentFields[fieldName] = fieldValue;
  1989. }
  1990. } catch (e_27_1) {
  1991. e_27 = { error: e_27_1 };
  1992. } finally {
  1993. try {
  1994. if (storeFields_1_1 && !storeFields_1_1.done && (_a2 = storeFields_1.return))
  1995. _a2.call(storeFields_1);
  1996. } finally {
  1997. if (e_27) throw e_27.error;
  1998. }
  1999. }
  2000. };
  2001. MiniSearch2.wildcard = Symbol('*');
  2002. return MiniSearch2;
  2003. })();
  2004. var getOwnProperty = function (object, property) {
  2005. return Object.prototype.hasOwnProperty.call(object, property) ? object[property] : void 0;
  2006. };
  2007. var combinators =
  2008. ((_a = {}),
  2009. (_a[OR] = function (a, b) {
  2010. var e_28, _a2;
  2011. try {
  2012. for (var _b = __values(b.keys()), _c = _b.next(); !_c.done; _c = _b.next()) {
  2013. var docId = _c.value;
  2014. var existing = a.get(docId);
  2015. if (existing == null) {
  2016. a.set(docId, b.get(docId));
  2017. } else {
  2018. var _d = b.get(docId),
  2019. score = _d.score,
  2020. terms = _d.terms,
  2021. match = _d.match;
  2022. existing.score = existing.score + score;
  2023. existing.match = Object.assign(existing.match, match);
  2024. assignUniqueTerms(existing.terms, terms);
  2025. }
  2026. }
  2027. } catch (e_28_1) {
  2028. e_28 = { error: e_28_1 };
  2029. } finally {
  2030. try {
  2031. if (_c && !_c.done && (_a2 = _b.return)) _a2.call(_b);
  2032. } finally {
  2033. if (e_28) throw e_28.error;
  2034. }
  2035. }
  2036. return a;
  2037. }),
  2038. (_a[AND] = function (a, b) {
  2039. var e_29, _a2;
  2040. var combined = /* @__PURE__ */ new Map();
  2041. try {
  2042. for (var _b = __values(b.keys()), _c = _b.next(); !_c.done; _c = _b.next()) {
  2043. var docId = _c.value;
  2044. var existing = a.get(docId);
  2045. if (existing == null) continue;
  2046. var _d = b.get(docId),
  2047. score = _d.score,
  2048. terms = _d.terms,
  2049. match = _d.match;
  2050. assignUniqueTerms(existing.terms, terms);
  2051. combined.set(docId, {
  2052. score: existing.score + score,
  2053. terms: existing.terms,
  2054. match: Object.assign(existing.match, match)
  2055. });
  2056. }
  2057. } catch (e_29_1) {
  2058. e_29 = { error: e_29_1 };
  2059. } finally {
  2060. try {
  2061. if (_c && !_c.done && (_a2 = _b.return)) _a2.call(_b);
  2062. } finally {
  2063. if (e_29) throw e_29.error;
  2064. }
  2065. }
  2066. return combined;
  2067. }),
  2068. (_a[AND_NOT] = function (a, b) {
  2069. var e_30, _a2;
  2070. try {
  2071. for (var _b = __values(b.keys()), _c = _b.next(); !_c.done; _c = _b.next()) {
  2072. var docId = _c.value;
  2073. a.delete(docId);
  2074. }
  2075. } catch (e_30_1) {
  2076. e_30 = { error: e_30_1 };
  2077. } finally {
  2078. try {
  2079. if (_c && !_c.done && (_a2 = _b.return)) _a2.call(_b);
  2080. } finally {
  2081. if (e_30) throw e_30.error;
  2082. }
  2083. }
  2084. return a;
  2085. }),
  2086. _a);
  2087. var defaultBM25params = { k: 1.2, b: 0.7, d: 0.5 };
  2088. var calcBM25Score = function (
  2089. termFreq,
  2090. matchingCount,
  2091. totalCount,
  2092. fieldLength,
  2093. avgFieldLength,
  2094. bm25params
  2095. ) {
  2096. var k = bm25params.k,
  2097. b = bm25params.b,
  2098. d = bm25params.d;
  2099. var invDocFreq = Math.log(1 + (totalCount - matchingCount + 0.5) / (matchingCount + 0.5));
  2100. return (
  2101. invDocFreq *
  2102. (d + (termFreq * (k + 1)) / (termFreq + k * (1 - b + (b * fieldLength) / avgFieldLength)))
  2103. );
  2104. };
  2105. var termToQuerySpec = function (options) {
  2106. return function (term, i, terms) {
  2107. var fuzzy =
  2108. typeof options.fuzzy === 'function'
  2109. ? options.fuzzy(term, i, terms)
  2110. : options.fuzzy || false;
  2111. var prefix =
  2112. typeof options.prefix === 'function'
  2113. ? options.prefix(term, i, terms)
  2114. : options.prefix === true;
  2115. return { term, fuzzy, prefix };
  2116. };
  2117. };
  2118. var defaultOptions = {
  2119. idField: 'id',
  2120. extractField: function (document, fieldName) {
  2121. return document[fieldName];
  2122. },
  2123. tokenize: function (text) {
  2124. return text.split(SPACE_OR_PUNCTUATION);
  2125. },
  2126. processTerm: function (term) {
  2127. return term.toLowerCase();
  2128. },
  2129. fields: void 0,
  2130. searchOptions: void 0,
  2131. storeFields: [],
  2132. logger: function (level, message) {
  2133. if (
  2134. typeof (console === null || console === void 0 ? void 0 : console[level]) === 'function'
  2135. )
  2136. console[level](message);
  2137. },
  2138. autoVacuum: true
  2139. };
  2140. var defaultSearchOptions = {
  2141. combineWith: OR,
  2142. prefix: false,
  2143. fuzzy: false,
  2144. maxFuzzy: 6,
  2145. boost: {},
  2146. weights: { fuzzy: 0.45, prefix: 0.375 },
  2147. bm25: defaultBM25params
  2148. };
  2149. var defaultAutoSuggestOptions = {
  2150. combineWith: AND,
  2151. prefix: function (term, i, terms) {
  2152. return i === terms.length - 1;
  2153. }
  2154. };
  2155. var defaultVacuumOptions = { batchSize: 1e3, batchWait: 10 };
  2156. var defaultVacuumConditions = { minDirtFactor: 0.1, minDirtCount: 20 };
  2157. var defaultAutoVacuumOptions = __assign(
  2158. __assign({}, defaultVacuumOptions),
  2159. defaultVacuumConditions
  2160. );
  2161. var assignUniqueTerm = function (target, term) {
  2162. if (!target.includes(term)) target.push(term);
  2163. };
  2164. var assignUniqueTerms = function (target, source) {
  2165. var e_31, _a2;
  2166. try {
  2167. for (
  2168. var source_1 = __values(source), source_1_1 = source_1.next();
  2169. !source_1_1.done;
  2170. source_1_1 = source_1.next()
  2171. ) {
  2172. var term = source_1_1.value;
  2173. if (!target.includes(term)) target.push(term);
  2174. }
  2175. } catch (e_31_1) {
  2176. e_31 = { error: e_31_1 };
  2177. } finally {
  2178. try {
  2179. if (source_1_1 && !source_1_1.done && (_a2 = source_1.return)) _a2.call(source_1);
  2180. } finally {
  2181. if (e_31) throw e_31.error;
  2182. }
  2183. }
  2184. };
  2185. var byScore = function (_a2, _b) {
  2186. var a = _a2.score;
  2187. var b = _b.score;
  2188. return b - a;
  2189. };
  2190. var createMap = function () {
  2191. return /* @__PURE__ */ new Map();
  2192. };
  2193. var objectToNumericMap = function (object) {
  2194. var e_32, _a2;
  2195. var map = /* @__PURE__ */ new Map();
  2196. try {
  2197. for (var _b = __values(Object.keys(object)), _c = _b.next(); !_c.done; _c = _b.next()) {
  2198. var key = _c.value;
  2199. map.set(parseInt(key, 10), object[key]);
  2200. }
  2201. } catch (e_32_1) {
  2202. e_32 = { error: e_32_1 };
  2203. } finally {
  2204. try {
  2205. if (_c && !_c.done && (_a2 = _b.return)) _a2.call(_b);
  2206. } finally {
  2207. if (e_32) throw e_32.error;
  2208. }
  2209. }
  2210. return map;
  2211. };
  2212. var SPACE_OR_PUNCTUATION =
  2213. /[\n\r -#%-*,-/:;?@[-\]_{}\u00A0\u00A1\u00A7\u00AB\u00B6\u00B7\u00BB\u00BF\u037E\u0387\u055A-\u055F\u0589\u058A\u05BE\u05C0\u05C3\u05C6\u05F3\u05F4\u0609\u060A\u060C\u060D\u061B\u061E\u061F\u066A-\u066D\u06D4\u0700-\u070D\u07F7-\u07F9\u0830-\u083E\u085E\u0964\u0965\u0970\u09FD\u0A76\u0AF0\u0C77\u0C84\u0DF4\u0E4F\u0E5A\u0E5B\u0F04-\u0F12\u0F14\u0F3A-\u0F3D\u0F85\u0FD0-\u0FD4\u0FD9\u0FDA\u104A-\u104F\u10FB\u1360-\u1368\u1400\u166E\u1680\u169B\u169C\u16EB-\u16ED\u1735\u1736\u17D4-\u17D6\u17D8-\u17DA\u1800-\u180A\u1944\u1945\u1A1E\u1A1F\u1AA0-\u1AA6\u1AA8-\u1AAD\u1B5A-\u1B60\u1BFC-\u1BFF\u1C3B-\u1C3F\u1C7E\u1C7F\u1CC0-\u1CC7\u1CD3\u2000-\u200A\u2010-\u2029\u202F-\u2043\u2045-\u2051\u2053-\u205F\u207D\u207E\u208D\u208E\u2308-\u230B\u2329\u232A\u2768-\u2775\u27C5\u27C6\u27E6-\u27EF\u2983-\u2998\u29D8-\u29DB\u29FC\u29FD\u2CF9-\u2CFC\u2CFE\u2CFF\u2D70\u2E00-\u2E2E\u2E30-\u2E4F\u3000-\u3003\u3008-\u3011\u3014-\u301F\u3030\u303D\u30A0\u30FB\uA4FE\uA4FF\uA60D-\uA60F\uA673\uA67E\uA6F2-\uA6F7\uA874-\uA877\uA8CE\uA8CF\uA8F8-\uA8FA\uA8FC\uA92E\uA92F\uA95F\uA9C1-\uA9CD\uA9DE\uA9DF\uAA5C-\uAA5F\uAADE\uAADF\uAAF0\uAAF1\uABEB\uFD3E\uFD3F\uFE10-\uFE19\uFE30-\uFE52\uFE54-\uFE61\uFE63\uFE68\uFE6A\uFE6B\uFF01-\uFF03\uFF05-\uFF0A\uFF0C-\uFF0F\uFF1A\uFF1B\uFF1F\uFF20\uFF3B-\uFF3D\uFF3F\uFF5B\uFF5D\uFF5F-\uFF65]+/u;
  2214. export { MiniSearch as default };
  2215. //# sourceMappingURL=vitepress___minisearch.js.map