@delali/narsil 0.3.1-next.145 → 0.3.1-next.146

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (207) hide show
  1. package/dist/adapters/filesystem.mjs +2 -2
  2. package/dist/adapters/gcs.mjs +2 -2
  3. package/dist/adapters/indexeddb.mjs +1 -1
  4. package/dist/adapters/s3.mjs +2 -2
  5. package/dist/analysis-change-ZCJNYBJM.mjs +39 -0
  6. package/dist/{analysis-change-entry-V4SQQSXQ.mjs → analysis-change-entry-YN3ELL6C.mjs} +1 -1
  7. package/dist/browser/{analysis-change-QTCQ5ETU.mjs → analysis-change-M65AZQQG.mjs} +8 -5
  8. package/dist/browser/{analysis-change-entry-KYEQSP3I.mjs → analysis-change-entry-H3YIOLXZ.mjs} +1 -1
  9. package/dist/browser/{chunk-GP4QLUQM.mjs → chunk-2JABMB4S.mjs} +10 -6
  10. package/dist/browser/{chunk-5WYWLTM5.mjs → chunk-4DYLCICG.mjs} +2 -2
  11. package/dist/browser/{chunk-75PMIFQA.mjs → chunk-4RD3AFSB.mjs} +1 -1
  12. package/dist/browser/{chunk-XWMEGKDC.mjs → chunk-5V74FFZE.mjs} +2 -2
  13. package/dist/browser/{chunk-PMBSBSCN.mjs → chunk-6OWX3OP2.mjs} +2 -2
  14. package/dist/browser/chunk-BRWY3JCN.mjs +678 -0
  15. package/dist/browser/{chunk-ZALEKEUH.mjs → chunk-BVX2MEHA.mjs} +306 -607
  16. package/dist/browser/{chunk-FXPMF65P.mjs → chunk-D6UFGBF5.mjs} +15 -45
  17. package/dist/browser/{chunk-QNDWMPV2.mjs → chunk-IAXZAVYL.mjs} +25 -66
  18. package/dist/browser/chunk-JNOAKDUM.mjs +31 -0
  19. package/dist/browser/{chunk-BTMRV5MY.mjs → chunk-KAEVGLYN.mjs} +2 -2
  20. package/dist/browser/{chunk-FHO5N7FD.mjs → chunk-LURXVCHG.mjs} +1 -1
  21. package/dist/browser/chunk-MPK76GVS.mjs +63 -0
  22. package/dist/browser/{chunk-6OFS7RUN.mjs → chunk-NVEJJP4R.mjs} +1 -1
  23. package/dist/browser/{chunk-U77XQJOY.mjs → chunk-ODQP7P3H.mjs} +455 -66
  24. package/dist/browser/{chunk-IFGTRRPU.mjs → chunk-PIS7ZAP7.mjs} +3 -25
  25. package/dist/browser/{chunk-XIHLIMFX.mjs → chunk-QMNZFFD3.mjs} +4 -3
  26. package/dist/browser/{chunk-AOKLYVTT.mjs → chunk-SRL47USS.mjs} +2 -2
  27. package/dist/browser/chunk-TY7L6OXO.mjs +69 -0
  28. package/dist/browser/{chunk-LGJ6XMH5.mjs → chunk-W643QV3L.mjs} +6 -5
  29. package/dist/browser/chunk-WXLBZJMT.mjs +25 -0
  30. package/dist/browser/{chunk-ZKVDQ5ZH.mjs → chunk-XILIT5MT.mjs} +8 -8
  31. package/dist/browser/{cold-module-Y2IJAP7S.mjs → cold-module-A5S6JFDN.mjs} +20 -20
  32. package/dist/browser/{durability-wiring-MLXZ5QQF.mjs → durability-wiring-W5AVV3RF.mjs} +53 -30
  33. package/dist/browser/gzip-5S7ROJFJ.mjs +1 -0
  34. package/dist/browser/import-PTT63AGK.mjs +12 -0
  35. package/dist/browser/{module-5LMDGXQH.mjs → module-CEKA7MQH.mjs} +13 -10
  36. package/dist/browser/module-X5PGOE47.mjs +4288 -0
  37. package/dist/browser/{phrase-module-KXNRTWCS.mjs → phrase-module-CNKMUY4U.mjs} +2 -1
  38. package/dist/browser/pool-DTYSPBMQ.mjs +296 -0
  39. package/dist/{restore-queue-UAVGBSJG.mjs → browser/restore-queue-DD4LWZK7.mjs} +2 -2
  40. package/dist/browser/{runtime-ZNEGK33G.mjs → runtime-D2ULZGCN.mjs} +3 -2
  41. package/dist/browser/{snapshot-2EGS2FYU.mjs → snapshot-DQ6A4PQP.mjs} +18 -14
  42. package/dist/browser/{write-WMZA6NSF.mjs → write-MAGRAIEH.mjs} +14 -11
  43. package/dist/{capabilities-CNnzGtqP.d.ts → capabilities-BT-HLDC8.d.ts} +2 -2
  44. package/dist/{chunk-FRJ5RGX7.mjs → chunk-2HJWQPR6.mjs} +2 -2
  45. package/dist/{chunk-DKMZ7JFW.mjs → chunk-3BVGJ4JR.mjs} +10 -4
  46. package/dist/{chunk-QYMAYU7M.mjs → chunk-3HV7M5OJ.mjs} +155 -149
  47. package/dist/chunk-3MXV3VHR.mjs +46 -0
  48. package/dist/{chunk-6FOJKNUR.mjs → chunk-3SBJVQLL.mjs} +2 -2
  49. package/dist/{chunk-PRID7CA6.mjs → chunk-3TVDTACC.mjs} +1 -1
  50. package/dist/{chunk-RTVAWNUL.mjs → chunk-5WB2A3XU.mjs} +9 -6
  51. package/dist/{chunk-LWFK3TC2.mjs → chunk-65WCV5JO.mjs} +1 -1
  52. package/dist/{chunk-G6Q5DEF5.mjs → chunk-6BWLDLS3.mjs} +3 -46
  53. package/dist/{chunk-W6M4RRAT.mjs → chunk-6C5EX2QR.mjs} +3 -3
  54. package/dist/{chunk-HOC5JP2H.mjs → chunk-6F6USYII.mjs} +119 -11
  55. package/dist/{chunk-7523VCM4.mjs → chunk-7HKWO4BJ.mjs} +7 -7
  56. package/dist/{chunk-ONDEEBTA.mjs → chunk-7N223GWV.mjs} +2 -2
  57. package/dist/{chunk-UGQULMSU.mjs → chunk-ADBS5XRI.mjs} +10 -10
  58. package/dist/{chunk-MJTEU2XK.mjs → chunk-AWNHDBKV.mjs} +429 -73
  59. package/dist/{chunk-2E2ZFOPT.mjs → chunk-B2FTZNNF.mjs} +2 -2
  60. package/dist/{chunk-NWTEJ2T7.mjs → chunk-B7XIOAMK.mjs} +3 -3
  61. package/dist/{chunk-W55X2BYN.mjs → chunk-BEZH7VEH.mjs} +1 -1
  62. package/dist/chunk-BTPGQC6Z.mjs +27 -0
  63. package/dist/{chunk-KG5N7LE6.mjs → chunk-CYYSZPVV.mjs} +11 -11
  64. package/dist/{chunk-HTMUGEFU.mjs → chunk-DOY6EG76.mjs} +6 -6
  65. package/dist/{chunk-UHVTEVF5.mjs → chunk-F22IOCR2.mjs} +10 -6
  66. package/dist/{chunk-FTQLF5JI.mjs → chunk-IRWP524D.mjs} +1 -1
  67. package/dist/{chunk-XLAI4OIO.mjs → chunk-IZT3G24Q.mjs} +2 -2
  68. package/dist/{chunk-SE7MKJVK.mjs → chunk-J7M73VY7.mjs} +1 -1
  69. package/dist/chunk-KAKQ74LS.mjs +53 -0
  70. package/dist/{chunk-GVPYMSLO.mjs → chunk-KYVRZAYP.mjs} +1 -1
  71. package/dist/{chunk-F442VZUL.mjs → chunk-KZ5GQE4Z.mjs} +5 -5
  72. package/dist/{chunk-WDEWU46C.mjs → chunk-KZQIVGW7.mjs} +2 -2
  73. package/dist/{chunk-7AJAW6NN.mjs → chunk-L7TIAYPX.mjs} +8 -8
  74. package/dist/{chunk-GRFXSEFF.mjs → chunk-LDGGR7YT.mjs} +4 -81
  75. package/dist/{chunk-WMIV7PJ7.mjs → chunk-LJ4ENXOD.mjs} +15 -14
  76. package/dist/chunk-LQG5G2LY.mjs +39 -0
  77. package/dist/{chunk-IQHZMCLX.mjs → chunk-MDF6PDIA.mjs} +2 -0
  78. package/dist/{chunk-QXH2CS4V.mjs → chunk-NVTFQFUL.mjs} +7 -26
  79. package/dist/{chunk-5K2JHKM3.mjs → chunk-NYSONUB7.mjs} +1 -1
  80. package/dist/{chunk-OH7SX5MY.mjs → chunk-O4KUNDVF.mjs} +12 -10
  81. package/dist/{chunk-EBIHRL7B.mjs → chunk-Q2UL2TPC.mjs} +1 -1
  82. package/dist/{chunk-RNUP6WZ6.mjs → chunk-QEYF2SQ6.mjs} +2 -2
  83. package/dist/{chunk-RVBUQITB.mjs → chunk-QN5WVV5K.mjs} +7 -7
  84. package/dist/{chunk-RIIUZJQ3.mjs → chunk-QYRNLLLI.mjs} +1 -1
  85. package/dist/{chunk-BTARFTEN.mjs → chunk-SOUZMPME.mjs} +4 -4
  86. package/dist/{chunk-ISUOSACK.mjs → chunk-T4CJDBBE.mjs} +1 -1
  87. package/dist/{chunk-DHEJAGVW.mjs → chunk-TTCKT2RT.mjs} +5 -5
  88. package/dist/{chunk-QU2XF7VI.mjs → chunk-U2726TL5.mjs} +5 -4
  89. package/dist/{chunk-LYKUJNAV.mjs → chunk-U46IZNCW.mjs} +2 -2
  90. package/dist/{chunk-SNB4DYL3.mjs → chunk-U6NE6RCV.mjs} +4 -4
  91. package/dist/{chunk-SA52N7G3.mjs → chunk-VP6XRMWR.mjs} +4 -4
  92. package/dist/{chunk-YUCGFPMS.mjs → chunk-VQDZVWN3.mjs} +449 -405
  93. package/dist/{chunk-IWVEG5CX.mjs → chunk-XIHUI4KB.mjs} +2 -2
  94. package/dist/{chunk-IV2XTSS2.mjs → chunk-XKPNKR3V.mjs} +16 -46
  95. package/dist/{chunk-UQS5PAS5.mjs → chunk-YGQOPB2Z.mjs} +1 -1
  96. package/dist/{chunk-SVO6NV4D.mjs → chunk-YKEHQUSZ.mjs} +4 -4
  97. package/dist/{chunk-6Z22L5RN.mjs → chunk-ZAYWOHVG.mjs} +1 -1
  98. package/dist/{chunk-QLDLQW36.mjs → chunk-ZEKDO7YX.mjs} +2 -2
  99. package/dist/chunk-ZXNNR73R.mjs +31 -0
  100. package/dist/{chunk-VJS4JFBQ.mjs → chunk-ZXX5GZEX.mjs} +3 -1
  101. package/dist/{chunk-X5SBWARI.mjs → chunk-ZYKUD5NX.mjs} +9 -7
  102. package/dist/{client-DoYPHcUn.d.ts → client-Cn3gNxUU.d.ts} +3 -3
  103. package/dist/client.d.ts +5 -5
  104. package/dist/client.mjs +2 -0
  105. package/dist/{cold-module-NUD332YD.mjs → cold-module-2WWGBFJC.mjs} +36 -33
  106. package/dist/{config-CuUfls_H.d.ts → config-CfhH1IWQ.d.ts} +1 -1
  107. package/dist/{config-Dzs46im6.d.ts → config-aIsy7mcL.d.ts} +52 -1
  108. package/dist/direct-executor-QLVHMELJ.mjs +24 -0
  109. package/dist/distribution/coordinator/etcd.mjs +1 -1
  110. package/dist/distribution/transport/grpc.mjs +1 -1
  111. package/dist/distribution.d.ts +4 -4
  112. package/dist/distribution.mjs +150 -255
  113. package/dist/{durability-wiring-K7RDXWL6.mjs → durability-wiring-GNWQSZI3.mjs} +67 -42
  114. package/dist/embeddings/openai.mjs +2 -2
  115. package/dist/{engine-C0ifUEcm.d.ts → engine-CJRUHXgf.d.ts} +1 -1
  116. package/dist/gzip-F4HMIEEQ.mjs +1 -0
  117. package/dist/import-DX55PN4G.mjs +41 -0
  118. package/dist/index.browser.mjs +7 -4
  119. package/dist/index.d.ts +539 -5
  120. package/dist/index.mjs +22 -16
  121. package/dist/index.react-native.mjs +19 -0
  122. package/dist/{long-query-thread-FKVHRCHF.mjs → long-query-thread-SCUE62TO.mjs} +20 -17
  123. package/dist/{module-GJUKW5VU.mjs → module-HW6IXUM6.mjs} +601 -108
  124. package/dist/{module-TMFIWOD2.mjs → module-V5K4ZP23.mjs} +29 -23
  125. package/dist/{paged-partition-archive-WNUEMYWM.mjs → paged-partition-archive-FDIIWZNR.mjs} +31 -25
  126. package/dist/partial-words.mjs +5 -5
  127. package/dist/pattern.mjs +3 -3
  128. package/dist/persistence/durability/checkpoint-worker.mjs +28 -22
  129. package/dist/{phrase-module-OMY3QQV7.mjs → phrase-module-OUQIRUQU.mjs} +1 -1
  130. package/dist/pool-UPV5PVPY.mjs +298 -0
  131. package/dist/react-native/chunks/analysis-change-HGW3L6NY.mjs +893 -0
  132. package/dist/react-native/chunks/analysis-change-entry-BNRU6STO.mjs +1 -0
  133. package/dist/react-native/chunks/chunk-2J2727V4.mjs +495 -0
  134. package/dist/react-native/chunks/chunk-3CTWSQRW.mjs +1251 -0
  135. package/dist/react-native/chunks/chunk-5FV4ZEVA.mjs +2619 -0
  136. package/dist/react-native/chunks/chunk-7VWQLEFV.mjs +642 -0
  137. package/dist/react-native/chunks/chunk-AAAETEJK.mjs +27 -0
  138. package/dist/react-native/chunks/chunk-AM7RSBPF.mjs +32 -0
  139. package/dist/react-native/chunks/chunk-B6OD63Z3.mjs +997 -0
  140. package/dist/react-native/chunks/chunk-BRNAVOKP.mjs +177 -0
  141. package/dist/react-native/chunks/chunk-DKJTZ625.mjs +207 -0
  142. package/dist/react-native/chunks/chunk-FKGG4UOF.mjs +177 -0
  143. package/dist/{browser/chunk-K7UFXEJS.mjs → react-native/chunks/chunk-GV5KFQ6M.mjs} +12 -6
  144. package/dist/react-native/chunks/chunk-HURV3ASY.mjs +4416 -0
  145. package/dist/react-native/chunks/chunk-IO2SMUQD.mjs +10 -0
  146. package/dist/react-native/chunks/chunk-JV6VQY2S.mjs +17 -0
  147. package/dist/react-native/chunks/chunk-KUJOBRKS.mjs +217 -0
  148. package/dist/react-native/chunks/chunk-KWRW5U65.mjs +226 -0
  149. package/dist/react-native/chunks/chunk-L4M7QJNP.mjs +110 -0
  150. package/dist/react-native/chunks/chunk-LQ6Q4L5B.mjs +360 -0
  151. package/dist/react-native/chunks/chunk-LQAKO5QV.mjs +523 -0
  152. package/dist/react-native/chunks/chunk-LRGWK367.mjs +11 -0
  153. package/dist/react-native/chunks/chunk-LVIKKAA6.mjs +93 -0
  154. package/dist/react-native/chunks/chunk-NFGBOI46.mjs +14 -0
  155. package/dist/react-native/chunks/chunk-NNE4VDMM.mjs +8 -0
  156. package/dist/react-native/chunks/chunk-PPEPTUVV.mjs +56 -0
  157. package/dist/react-native/chunks/chunk-PSWKQVVT.mjs +9 -0
  158. package/dist/react-native/chunks/chunk-PU55IOG4.mjs +910 -0
  159. package/dist/react-native/chunks/chunk-QC4ZRBSX.mjs +270 -0
  160. package/dist/react-native/chunks/chunk-R4EEMYM6.mjs +21 -0
  161. package/dist/react-native/chunks/chunk-R4OPUZQ5.mjs +86 -0
  162. package/dist/react-native/chunks/chunk-SLGIAD6B.mjs +2634 -0
  163. package/dist/react-native/chunks/chunk-TJMSKBEM.mjs +25 -0
  164. package/dist/react-native/chunks/chunk-TLYD7IJ2.mjs +23 -0
  165. package/dist/react-native/chunks/chunk-UFNCLEQM.mjs +73 -0
  166. package/dist/react-native/chunks/chunk-YH7W556M.mjs +179 -0
  167. package/dist/react-native/chunks/chunk-YJSMEKRE.mjs +22385 -0
  168. package/dist/react-native/chunks/chunk-ZCKNBPQ4.mjs +79 -0
  169. package/dist/react-native/chunks/cold-module-TSFWLYWC.mjs +755 -0
  170. package/dist/react-native/chunks/durability-wiring-PZR6KOQK.mjs +4509 -0
  171. package/dist/react-native/chunks/gzip.react-native-7JWCLVOB.mjs +3 -0
  172. package/dist/react-native/chunks/import-VTODLPLO.mjs +22 -0
  173. package/dist/{browser/module-Q6VFGLMG.mjs → react-native/chunks/module-JBBH6PZH.mjs} +609 -144
  174. package/dist/react-native/chunks/module-VEK2KCKU.mjs +25 -0
  175. package/dist/react-native/chunks/phrase-module-76UAPPSG.mjs +329 -0
  176. package/dist/react-native/chunks/pool-CD4ANYUI.mjs +296 -0
  177. package/dist/react-native/chunks/release-D7ZTIANM.mjs +33 -0
  178. package/dist/react-native/chunks/replace-IMZUVUOE.mjs +57 -0
  179. package/dist/{browser/restore-queue-SOAHKZSQ.mjs → react-native/chunks/restore-queue-OI5EH7R3.mjs} +2 -2
  180. package/dist/react-native/chunks/runtime-3MCDLJAF.mjs +559 -0
  181. package/dist/react-native/chunks/snapshot-AUZMEV36.mjs +1205 -0
  182. package/dist/react-native/chunks/write-DDC2QBRJ.mjs +197 -0
  183. package/dist/react-native/partial-words.mjs +733 -0
  184. package/dist/react-native/pattern.mjs +2442 -0
  185. package/dist/react-native/synonyms.mjs +460 -0
  186. package/dist/react.d.ts +7 -7
  187. package/dist/react.mjs +2 -0
  188. package/dist/{rerank-ZZ5CHKLW.mjs → rerank-3W54N6P2.mjs} +4 -4
  189. package/dist/rerankers/http.mjs +2 -2
  190. package/dist/restore-queue-BQWWNNQI.mjs +41 -0
  191. package/dist/{runtime-RAOCKSYA.mjs → runtime-L2DZYY6N.mjs} +5 -5
  192. package/dist/server.d.ts +8 -8
  193. package/dist/server.mjs +32 -28
  194. package/dist/{snapshot-DB5ZVCDN.mjs → snapshot-EHXTOTW5.mjs} +39 -33
  195. package/dist/synonyms.mjs +3 -3
  196. package/dist/{tasks-ChWp0wrF.d.ts → tasks-C4ElXr4P.d.ts} +2 -2
  197. package/dist/thread-I7DVHHW7.mjs +31 -0
  198. package/dist/vector/search-worker.mjs +7 -5
  199. package/dist/workers/entry.mjs +9 -9
  200. package/dist/{write-KZVTLGCI.mjs → write-SDJXXQ2G.mjs} +29 -23
  201. package/package.json +88 -7
  202. package/dist/analysis-change-D5APH4Z3.mjs +0 -34
  203. package/dist/browser/import-FTMLTPGQ.mjs +0 -9
  204. package/dist/direct-executor-FDQYQEJQ.mjs +0 -22
  205. package/dist/import-6KXFY6XI.mjs +0 -35
  206. package/dist/thread-OV6T555H.mjs +0 -28
  207. /package/dist/{chunk-22YPZVMG.mjs → chunk-ZXNQEW43.mjs} +0 -0
@@ -0,0 +1,733 @@
1
+ import { spellingCountsOf, encodePartialSpellings, countSpelling, PARTIAL_WORD_RUN_CODE_POINTS, FROZEN_PARTIAL_REMOVED_ENTRY_BYTES, sameFields, countDocumentSpellings, GROWING_PARTIAL_ENTRY_BYTES, GROWING_PARTIAL_RUN_BYTES, GROWING_PARTIAL_RUN_MEMBER_BYTES, GROWING_PARTIAL_PENDING_ENTRY_BYTES, partitionDocumentFrequency, visitDocumentSpellings, visitDocumentSurfaceSpellings, codePointCountOf, GROWING_PARTIAL_PENDING_ENTRIES_PER_ENTRY } from './chunks/chunk-PU55IOG4.mjs';
2
+ import './chunks/chunk-TJMSKBEM.mjs';
3
+ import { fuzzyTermMatches } from './chunks/chunk-DKJTZ625.mjs';
4
+ import { encodeStringBlob, tokenize, resolveStopWords, transformToken } from './chunks/chunk-2J2727V4.mjs';
5
+ import './chunks/chunk-KWRW5U65.mjs';
6
+ import { compareCodePoints, codePointCount } from './chunks/chunk-PPEPTUVV.mjs';
7
+ import { PARTIAL_WORD_MIN_CODE_POINTS, PARTIAL_WORDS_ADDED_PER_QUERY, DEFAULT_FUZZY_PREFIX_LENGTH } from './chunks/chunk-AAAETEJK.mjs';
8
+ import './chunks/chunk-JV6VQY2S.mjs';
9
+ import './chunks/chunk-YH7W556M.mjs';
10
+
11
+ // src/core/partition/partial-words/text.ts
12
+ var encoder = new TextEncoder();
13
+ var LAST_BASIC_PLANE_CODE_POINT = 65535;
14
+ var BASIC_PLANE_SIZE = 65536;
15
+ var UTF8_CONTINUATION_MASK = 192;
16
+ var UTF8_CONTINUATION_BITS = 128;
17
+ function codePointsOf(text) {
18
+ const points = [];
19
+ let index = 0;
20
+ while (index < text.length) {
21
+ const point = text.codePointAt(index) ?? text.charCodeAt(index);
22
+ points.push(point);
23
+ index += point > LAST_BASIC_PLANE_CODE_POINT ? 2 : 1;
24
+ }
25
+ return points;
26
+ }
27
+ function runKeyAt(points, at) {
28
+ return String.fromCodePoint(points[at], points[at + 1], points[at + 2]);
29
+ }
30
+ function packedRunKeyAt(points, at) {
31
+ const first = points[at];
32
+ const second = points[at + 1];
33
+ const third = points[at + 2];
34
+ if ((first | second | third) > LAST_BASIC_PLANE_CODE_POINT) return String.fromCodePoint(first, second, third);
35
+ return first * BASIC_PLANE_SIZE * BASIC_PLANE_SIZE + second * BASIC_PLANE_SIZE + third;
36
+ }
37
+ function partialWordProbe(text) {
38
+ return { text, codePoints: codePointsOf(text), utf8: encoder.encode(text) };
39
+ }
40
+ function utf8Contains(haystack, start, end, needle) {
41
+ const last = end - needle.length;
42
+ for (let from = start; from <= last; from++) {
43
+ let at = 0;
44
+ while (at < needle.length && haystack[from + at] === needle[at]) at++;
45
+ if (at === needle.length) return true;
46
+ }
47
+ return false;
48
+ }
49
+ function utf8CodePointCount(bytes, start, end) {
50
+ let count = 0;
51
+ for (let at = start; at < end; at++) {
52
+ if ((bytes[at] & UTF8_CONTINUATION_MASK) !== UTF8_CONTINUATION_BITS) count++;
53
+ }
54
+ return count;
55
+ }
56
+
57
+ // src/core/partition/partial-words/expansion.ts
58
+ function excludedFromRequest(request, token) {
59
+ if (token === request.ownToken) return true;
60
+ return request.tolerance > 0 && fuzzyTermMatches(request.ownToken, token, request.tolerance, request.prefixLength);
61
+ }
62
+ function addedWordsFor(subs, readers, request) {
63
+ if (request.share <= 0) return [];
64
+ const probe = partialWordProbe(request.written);
65
+ const shortestSpelling = /* @__PURE__ */ new Map();
66
+ for (const reader of readers) {
67
+ reader.forEachContaining(probe, (token, spellingLength) => {
68
+ const known = shortestSpelling.get(token);
69
+ if (known === void 0 || spellingLength < known) shortestSpelling.set(token, spellingLength);
70
+ });
71
+ }
72
+ const ranked = [];
73
+ for (const [token, spellingLength] of shortestSpelling) {
74
+ if (excludedFromRequest(request, token)) continue;
75
+ const documents = partitionDocumentFrequency(subs, token);
76
+ if (documents > 0) ranked.push({ token, documents, spellingLength });
77
+ }
78
+ ranked.sort((a, b) => b.documents - a.documents || compareCodePoints(a.token, b.token));
79
+ if (ranked.length > request.share) ranked.length = request.share;
80
+ const writtenLength = probe.codePoints.length;
81
+ return ranked.map((word) => ({ token: word.token, factor: writtenLength / word.spellingLength }));
82
+ }
83
+ function expandPartialWords(subs, analysis, requests) {
84
+ const readers = [];
85
+ for (const sub of subs) {
86
+ const reader = sub.partialWords.readerFor(analysis);
87
+ if (reader !== null) readers.push(reader);
88
+ }
89
+ return requests.map((request) => readers.length === 0 ? [] : addedWordsFor(subs, readers, request));
90
+ }
91
+
92
+ // src/core/partition/partial-words/frozen-table.ts
93
+ var decoder = new TextDecoder();
94
+ function compareEntries(left, right) {
95
+ return compareCodePoints(left.spelling, right.spelling) || left.tokenIndex - right.tokenIndex;
96
+ }
97
+ function orderedEntriesOf(source, tokenTable) {
98
+ const entries = [];
99
+ for (let at = 0; at < source.tokens.length; at++) {
100
+ if (source.counts[at] <= 0) continue;
101
+ const tokenIndex = tokenTable.find(source.tokens[at]);
102
+ if (tokenIndex >= 0) entries.push({ spelling: source.spellings[at], tokenIndex, count: source.counts[at] });
103
+ }
104
+ entries.sort(compareEntries);
105
+ const distinct = [];
106
+ for (const entry of entries) {
107
+ const last = distinct[distinct.length - 1];
108
+ if (last !== void 0 && compareEntries(last, entry) === 0) last.count += entry.count;
109
+ else distinct.push(entry);
110
+ }
111
+ return distinct;
112
+ }
113
+ function buildPartialWordTable(source, tokenTable) {
114
+ const spellings = [];
115
+ const spellingTokens = [];
116
+ const spellingCounts = [];
117
+ const runLists = /* @__PURE__ */ new Map();
118
+ const addSpelling = (spelling, tokenIndex, count) => {
119
+ const points = codePointsOf(spelling);
120
+ if (points.length <= PARTIAL_WORD_RUN_CODE_POINTS) return;
121
+ const entry = spellings.length;
122
+ spellings.push(spelling);
123
+ spellingTokens.push(tokenIndex);
124
+ spellingCounts.push(count);
125
+ for (let at = 0; at + PARTIAL_WORD_RUN_CODE_POINTS <= points.length; at++) {
126
+ const key = runKeyAt(points, at);
127
+ const list = runLists.get(key);
128
+ if (list === void 0) runLists.set(key, [entry]);
129
+ else if (list[list.length - 1] !== entry) list.push(entry);
130
+ }
131
+ };
132
+ for (const entry of orderedEntriesOf(source, tokenTable)) addSpelling(entry.spelling, entry.tokenIndex, entry.count);
133
+ const runKeys = [...runLists.keys()].sort(compareCodePoints);
134
+ const runs = new Uint32Array(runKeys.length * PARTIAL_WORD_RUN_CODE_POINTS);
135
+ const runOffsets = new Uint32Array(runKeys.length + 1);
136
+ let memberCount = 0;
137
+ for (const key of runKeys) memberCount += runLists.get(key)?.length ?? 0;
138
+ const runEntries = new Uint32Array(memberCount);
139
+ let cursor = 0;
140
+ for (let run = 0; run < runKeys.length; run++) {
141
+ const points = codePointsOf(runKeys[run]);
142
+ runs.set(points, run * PARTIAL_WORD_RUN_CODE_POINTS);
143
+ for (const entry of runLists.get(runKeys[run]) ?? []) runEntries[cursor++] = entry;
144
+ runOffsets[run + 1] = cursor;
145
+ }
146
+ const spellingBlob = encodeStringBlob(spellings);
147
+ return {
148
+ fields: [...source.fields],
149
+ spellings: spellingBlob.blob,
150
+ spellingOffsets: spellingBlob.offsets,
151
+ spellingTokens: Uint32Array.from(spellingTokens),
152
+ spellingCounts: Uint32Array.from(spellingCounts),
153
+ runs,
154
+ runOffsets,
155
+ runEntries
156
+ };
157
+ }
158
+ function countTableSpellings(counts, table, tokenTable) {
159
+ const { spellings, spellingOffsets, spellingTokens, spellingCounts } = table;
160
+ for (let entry = 0; entry < spellingTokens.length; entry++) {
161
+ const spelling = decoder.decode(spellings.subarray(spellingOffsets[entry], spellingOffsets[entry + 1]));
162
+ countSpelling(counts, tokenTable.tokenAt(spellingTokens[entry]), spelling, spellingCounts[entry]);
163
+ }
164
+ }
165
+ function findRun(runs, first, second, third) {
166
+ let low = 0;
167
+ let high = runs.length / PARTIAL_WORD_RUN_CODE_POINTS;
168
+ while (low < high) {
169
+ const middle = low + high >>> 1;
170
+ const at = middle * PARTIAL_WORD_RUN_CODE_POINTS;
171
+ const difference = runs[at] - first || runs[at + 1] - second || runs[at + 2] - third;
172
+ if (difference === 0) return middle;
173
+ if (difference < 0) low = middle + 1;
174
+ else high = middle;
175
+ }
176
+ return -1;
177
+ }
178
+ function partialWordTableBytes(table) {
179
+ return table.spellings.byteLength + table.spellingOffsets.byteLength + table.spellingTokens.byteLength + table.spellingCounts.byteLength + table.runs.byteLength + table.runOffsets.byteLength + table.runEntries.byteLength;
180
+ }
181
+ function readPartialWordTable(table, tokenTable, removedCounts) {
182
+ const { spellings, spellingOffsets, spellingTokens, spellingCounts, runs, runOffsets, runEntries } = table;
183
+ function narrowestRun(points) {
184
+ let narrowest = -1;
185
+ let narrowestLength = Number.POSITIVE_INFINITY;
186
+ for (let at = 0; at + PARTIAL_WORD_RUN_CODE_POINTS <= points.length; at++) {
187
+ const run = findRun(runs, points[at], points[at + 1], points[at + 2]);
188
+ if (run < 0) return -1;
189
+ const length = runOffsets[run + 1] - runOffsets[run];
190
+ if (length < narrowestLength) {
191
+ narrowest = run;
192
+ narrowestLength = length;
193
+ }
194
+ }
195
+ return narrowest;
196
+ }
197
+ return {
198
+ forEachContaining(probe, visit) {
199
+ if (probe.codePoints.length < PARTIAL_WORD_RUN_CODE_POINTS) return;
200
+ const run = narrowestRun(probe.codePoints);
201
+ if (run < 0) return;
202
+ for (let member = runOffsets[run]; member < runOffsets[run + 1]; member++) {
203
+ const entry = runEntries[member];
204
+ const start = spellingOffsets[entry];
205
+ const end = spellingOffsets[entry + 1];
206
+ if (end - start <= probe.utf8.length) continue;
207
+ if ((removedCounts.get(entry) ?? 0) >= spellingCounts[entry]) continue;
208
+ if (!utf8Contains(spellings, start, end, probe.utf8)) continue;
209
+ const length = utf8CodePointCount(spellings, start, end);
210
+ if (length <= probe.codePoints.length) continue;
211
+ visit(tokenTable.tokenAt(spellingTokens[entry]), length);
212
+ }
213
+ },
214
+ entryOf(spelling) {
215
+ const probe = partialWordProbe(spelling);
216
+ if (probe.codePoints.length <= PARTIAL_WORD_RUN_CODE_POINTS) return -1;
217
+ const run = narrowestRun(probe.codePoints);
218
+ if (run < 0) return -1;
219
+ let exhausted = -1;
220
+ for (let member = runOffsets[run]; member < runOffsets[run + 1]; member++) {
221
+ const entry = runEntries[member];
222
+ const start = spellingOffsets[entry];
223
+ const end = spellingOffsets[entry + 1];
224
+ if (end - start !== probe.utf8.length || !utf8Contains(spellings, start, end, probe.utf8)) continue;
225
+ if ((removedCounts.get(entry) ?? 0) < spellingCounts[entry]) return entry;
226
+ if (exhausted < 0) exhausted = entry;
227
+ }
228
+ return exhausted;
229
+ },
230
+ bytes() {
231
+ return partialWordTableBytes(table);
232
+ }
233
+ };
234
+ }
235
+
236
+ // src/core/partition/partial-words/frozen-slot.ts
237
+ function tombstonedOrdinalsOf(documents) {
238
+ let marks = null;
239
+ for (let ordinal = 0; ordinal < documents.count; ordinal++) {
240
+ if (!documents.isTombstoned(ordinal)) continue;
241
+ marks ??= new Uint8Array(documents.count);
242
+ marks[ordinal] = 1;
243
+ }
244
+ return marks;
245
+ }
246
+ function addCounts(target, source) {
247
+ for (const [token, bySpelling] of source) {
248
+ for (const [spelling, count] of bySpelling) countSpelling(target, token, spelling, count);
249
+ }
250
+ }
251
+ function countRemovedSpellings(removed, document, analysis) {
252
+ const count = (spelling) => {
253
+ removed.set(spelling, (removed.get(spelling) ?? 0) + 1);
254
+ };
255
+ if (analysis.options?.customTokenizer !== void 0) {
256
+ visitDocumentSpellings(document, analysis, (_token, spelling) => count(spelling));
257
+ return;
258
+ }
259
+ visitDocumentSurfaceSpellings(document, analysis, count);
260
+ }
261
+ function unstemmedSpellingsOf(analysis) {
262
+ const { language } = analysis;
263
+ if (language.normalizer === void 0 || language.tokenizer?.normalizeDiacritics === true) return () => null;
264
+ const stopWords = resolveStopWords(language, analysis.options?.stopWordOverride);
265
+ return (spelling) => {
266
+ if (stopWords.has(spelling)) return null;
267
+ const normalized = transformToken(spelling, language, false, false);
268
+ return normalized === spelling ? null : normalized;
269
+ };
270
+ }
271
+ function subtractRemovedSpellings(counts, removed, analysis) {
272
+ const tokenOf = /* @__PURE__ */ new Map();
273
+ for (const [token, bySpelling] of counts) {
274
+ for (const spelling of bySpelling.keys()) tokenOf.set(spelling, token);
275
+ }
276
+ const unstemmedSpelling = unstemmedSpellingsOf(analysis);
277
+ for (const [spelling, count] of removed) {
278
+ const stored = tokenOf.has(spelling) ? spelling : unstemmedSpelling(spelling) ?? spelling;
279
+ const token = tokenOf.get(stored);
280
+ if (token !== void 0) countSpelling(counts, token, stored, -count);
281
+ }
282
+ }
283
+ function createFrozenPartialWordSlot(initial, tokenTable, documents) {
284
+ let table = initial;
285
+ let uncounted = null;
286
+ let removedCounts = /* @__PURE__ */ new Map();
287
+ let reader = initial === null ? null : readPartialWordTable(initial, tokenTable, removedCounts);
288
+ let pendingRemovals = [];
289
+ function isCounted(ordinal) {
290
+ return uncounted === null || uncounted[ordinal] === 0;
291
+ }
292
+ function subtractPendingRemovals(current, analysis) {
293
+ if (pendingRemovals.length === 0) return;
294
+ const removed = /* @__PURE__ */ new Map();
295
+ for (const ordinal of pendingRemovals) countRemovedSpellings(removed, documents.documentAt(ordinal), analysis);
296
+ pendingRemovals = [];
297
+ const unstemmedSpelling = unstemmedSpellingsOf(analysis);
298
+ for (const [spelling, count] of removed) {
299
+ let entry = current.entryOf(spelling);
300
+ if (entry < 0) {
301
+ const fallback = unstemmedSpelling(spelling);
302
+ if (fallback !== null) entry = current.entryOf(fallback);
303
+ }
304
+ if (entry >= 0) removedCounts.set(entry, (removedCounts.get(entry) ?? 0) + count);
305
+ }
306
+ }
307
+ function rebuild(analysis) {
308
+ uncounted = tombstonedOrdinalsOf(documents);
309
+ const counts = /* @__PURE__ */ new Map();
310
+ for (let ordinal = 0; ordinal < documents.count; ordinal++) {
311
+ if (isCounted(ordinal)) countDocumentSpellings(counts, documents.documentAt(ordinal), analysis, 1);
312
+ }
313
+ const rebuilt = buildPartialWordTable(encodePartialSpellings(analysis.fields, counts), tokenTable);
314
+ table = rebuilt;
315
+ removedCounts = /* @__PURE__ */ new Map();
316
+ pendingRemovals = [];
317
+ const rebuiltReader = readPartialWordTable(rebuilt, tokenTable, removedCounts);
318
+ reader = rebuiltReader;
319
+ return rebuiltReader;
320
+ }
321
+ function correctionsAgainstTable(mergedOrdinals) {
322
+ let corrections = 0;
323
+ for (let ordinal = 0; ordinal < mergedOrdinals.length; ordinal++) {
324
+ if (mergedOrdinals[ordinal] >= 0 !== isCounted(ordinal)) corrections += 1;
325
+ }
326
+ return corrections;
327
+ }
328
+ function keptCount(mergedOrdinals) {
329
+ let kept = 0;
330
+ for (let ordinal = 0; ordinal < mergedOrdinals.length; ordinal++) {
331
+ if (mergedOrdinals[ordinal] >= 0) kept += 1;
332
+ }
333
+ return kept;
334
+ }
335
+ return {
336
+ readerFor(analysis) {
337
+ if (analysis.fields.length === 0) return null;
338
+ if (table === null || reader === null || !sameFields(table.fields, analysis.fields)) return rebuild(analysis);
339
+ subtractPendingRemovals(reader, analysis);
340
+ return reader;
341
+ },
342
+ afterRemoval(ordinal) {
343
+ if (table !== null) pendingRemovals.push(ordinal);
344
+ },
345
+ tableOfEveryDocument(analysis) {
346
+ if (table === null || uncounted !== null || !sameFields(table.fields, analysis.fields)) return null;
347
+ return table;
348
+ },
349
+ countKeptSpellings(counts, analysis, mergedOrdinals) {
350
+ if (table === null || !sameFields(table.fields, analysis.fields) || correctionsAgainstTable(mergedOrdinals) > keptCount(mergedOrdinals)) {
351
+ for (let ordinal = 0; ordinal < mergedOrdinals.length; ordinal++) {
352
+ if (mergedOrdinals[ordinal] >= 0) countDocumentSpellings(counts, documents.documentAt(ordinal), analysis, 1);
353
+ }
354
+ return;
355
+ }
356
+ const corrected = /* @__PURE__ */ new Map();
357
+ countTableSpellings(corrected, table, tokenTable);
358
+ const removed = /* @__PURE__ */ new Map();
359
+ const returned = [];
360
+ for (let ordinal = 0; ordinal < mergedOrdinals.length; ordinal++) {
361
+ const kept = mergedOrdinals[ordinal] >= 0;
362
+ if (kept === isCounted(ordinal)) continue;
363
+ if (kept) returned.push(ordinal);
364
+ else countRemovedSpellings(removed, documents.documentAt(ordinal), analysis);
365
+ }
366
+ subtractRemovedSpellings(corrected, removed, analysis);
367
+ for (const ordinal of returned) countDocumentSpellings(corrected, documents.documentAt(ordinal), analysis, 1);
368
+ addCounts(counts, corrected);
369
+ },
370
+ spellings() {
371
+ return null;
372
+ },
373
+ bytes() {
374
+ if (table === null) return 0;
375
+ return partialWordTableBytes(table) + removedCounts.size * FROZEN_PARTIAL_REMOVED_ENTRY_BYTES;
376
+ }
377
+ };
378
+ }
379
+
380
+ // src/core/partition/partial-words/growing-slot.ts
381
+ function createGrowingPartialWordSlot(view) {
382
+ let fields = [];
383
+ let everyDocumentPending = false;
384
+ const pending = /* @__PURE__ */ new Set();
385
+ const entriesByToken = /* @__PURE__ */ new Map();
386
+ const entrySpellings = [];
387
+ const entryTokens = [];
388
+ const entryLengths = [];
389
+ const entryCounts = [];
390
+ const entryInRuns = [];
391
+ const freeEntries = [];
392
+ const entriesOutsideRuns = [];
393
+ const runs = /* @__PURE__ */ new Map();
394
+ let liveEntries = 0;
395
+ let runMembers = 0;
396
+ function resetSpellings() {
397
+ pending.clear();
398
+ entriesByToken.clear();
399
+ entrySpellings.length = 0;
400
+ entryTokens.length = 0;
401
+ entryLengths.length = 0;
402
+ entryCounts.length = 0;
403
+ entryInRuns.length = 0;
404
+ freeEntries.length = 0;
405
+ entriesOutsideRuns.length = 0;
406
+ runs.clear();
407
+ liveEntries = 0;
408
+ runMembers = 0;
409
+ }
410
+ function addEntry(byToken, token, spelling, count) {
411
+ const length = codePointCountOf(spelling);
412
+ if (length <= PARTIAL_WORD_RUN_CODE_POINTS) return;
413
+ const entry = freeEntries.pop() ?? entrySpellings.length;
414
+ entrySpellings[entry] = spelling;
415
+ entryTokens[entry] = token;
416
+ entryLengths[entry] = length;
417
+ entryCounts[entry] = count;
418
+ entryInRuns[entry] = false;
419
+ entriesOutsideRuns.push(entry);
420
+ if (entriesOutsideRuns.length > GROWING_PARTIAL_PENDING_ENTRIES_PER_ENTRY * entrySpellings.length) {
421
+ dropFreedAndRepeatedPendingEntries();
422
+ }
423
+ byToken.set(spelling, entry);
424
+ liveEntries++;
425
+ }
426
+ function dropFreedAndRepeatedPendingEntries() {
427
+ let kept = 0;
428
+ for (const entry of entriesOutsideRuns) {
429
+ if (entryLengths[entry] === 0 || entryInRuns[entry]) continue;
430
+ entryInRuns[entry] = true;
431
+ entriesOutsideRuns[kept++] = entry;
432
+ }
433
+ entriesOutsideRuns.length = kept;
434
+ for (let at = 0; at < kept; at++) entryInRuns[entriesOutsideRuns[at]] = false;
435
+ }
436
+ function addToRuns(entry) {
437
+ const points = codePointsOf(entrySpellings[entry]);
438
+ for (let at = 0; at + PARTIAL_WORD_RUN_CODE_POINTS <= points.length; at++) {
439
+ const key = packedRunKeyAt(points, at);
440
+ let members = runs.get(key);
441
+ if (members === void 0) {
442
+ members = /* @__PURE__ */ new Set();
443
+ runs.set(key, members);
444
+ }
445
+ const size = members.size;
446
+ members.add(entry);
447
+ if (members.size !== size) runMembers++;
448
+ }
449
+ entryInRuns[entry] = true;
450
+ }
451
+ function addEntriesToRuns() {
452
+ for (const entry of entriesOutsideRuns) {
453
+ if (entryLengths[entry] > 0 && !entryInRuns[entry]) addToRuns(entry);
454
+ }
455
+ entriesOutsideRuns.length = 0;
456
+ }
457
+ function removeFromRuns(entry) {
458
+ const points = codePointsOf(entrySpellings[entry]);
459
+ for (let at = 0; at + PARTIAL_WORD_RUN_CODE_POINTS <= points.length; at++) {
460
+ const key = packedRunKeyAt(points, at);
461
+ const members = runs.get(key);
462
+ if (members === void 0 || !members.delete(entry)) continue;
463
+ runMembers--;
464
+ if (members.size === 0) runs.delete(key);
465
+ }
466
+ entryInRuns[entry] = false;
467
+ }
468
+ function removeEntry(byToken, token, spelling, entry) {
469
+ if (entryInRuns[entry]) removeFromRuns(entry);
470
+ byToken.delete(spelling);
471
+ if (byToken.size === 0) entriesByToken.delete(token);
472
+ entrySpellings[entry] = "";
473
+ entryTokens[entry] = "";
474
+ entryLengths[entry] = 0;
475
+ entryCounts[entry] = 0;
476
+ freeEntries.push(entry);
477
+ liveEntries--;
478
+ }
479
+ function change(token, spelling, delta) {
480
+ let byToken = entriesByToken.get(token);
481
+ const entry = byToken?.get(spelling);
482
+ if (byToken !== void 0 && entry !== void 0) {
483
+ const after = entryCounts[entry] + delta;
484
+ if (after > 0) entryCounts[entry] = after;
485
+ else removeEntry(byToken, token, spelling, entry);
486
+ return;
487
+ }
488
+ if (delta <= 0) return;
489
+ if (byToken === void 0) {
490
+ byToken = /* @__PURE__ */ new Map();
491
+ entriesByToken.set(token, byToken);
492
+ }
493
+ addEntry(byToken, token, spelling, delta);
494
+ if (byToken.size === 0) entriesByToken.delete(token);
495
+ }
496
+ function encodedSpellings() {
497
+ const encoded = { fields: [...fields], tokens: [], spellings: [], counts: [] };
498
+ for (const [token, byToken] of entriesByToken) {
499
+ for (const [spelling, entry] of byToken) {
500
+ encoded.tokens.push(token);
501
+ encoded.spellings.push(spelling);
502
+ encoded.counts.push(entryCounts[entry]);
503
+ }
504
+ }
505
+ return encoded;
506
+ }
507
+ function applyCounts(source, direction) {
508
+ for (const [token, byToken] of source) {
509
+ for (const [spelling, count] of byToken) change(token, spelling, count * direction);
510
+ }
511
+ }
512
+ function adoptFields(next) {
513
+ if (sameFields(fields, next)) return;
514
+ fields = [...next];
515
+ resetSpellings();
516
+ everyDocumentPending = fields.length > 0;
517
+ }
518
+ function documentAt(internalId) {
519
+ const docId = view.docStore.getExternalId(internalId);
520
+ return docId === void 0 ? void 0 : view.docStore.get(docId)?.fields;
521
+ }
522
+ function resolvePending(analysis) {
523
+ if (everyDocumentPending) {
524
+ resetSpellings();
525
+ const derived2 = /* @__PURE__ */ new Map();
526
+ for (const [, stored] of view.docStore.all()) countDocumentSpellings(derived2, stored.fields, analysis, 1);
527
+ applyCounts(derived2, 1);
528
+ everyDocumentPending = false;
529
+ return;
530
+ }
531
+ if (pending.size === 0) return;
532
+ const derived = /* @__PURE__ */ new Map();
533
+ for (const internalId of pending) {
534
+ const document = documentAt(internalId);
535
+ if (document !== void 0) countDocumentSpellings(derived, document, analysis, 1);
536
+ }
537
+ pending.clear();
538
+ applyCounts(derived, 1);
539
+ }
540
+ const reader = {
541
+ forEachContaining(probe, visit) {
542
+ const points = probe.codePoints;
543
+ if (points.length < PARTIAL_WORD_RUN_CODE_POINTS) return;
544
+ let narrowest = null;
545
+ for (let at = 0; at + PARTIAL_WORD_RUN_CODE_POINTS <= points.length; at++) {
546
+ const members = runs.get(packedRunKeyAt(points, at));
547
+ if (members === void 0) return;
548
+ if (narrowest === null || members.size < narrowest.size) narrowest = members;
549
+ }
550
+ if (narrowest === null) return;
551
+ for (const entry of narrowest) {
552
+ const length = entryLengths[entry];
553
+ if (length <= points.length) continue;
554
+ if (!entrySpellings[entry].includes(probe.text)) continue;
555
+ visit(entryTokens[entry], length);
556
+ }
557
+ },
558
+ bytes() {
559
+ return slot.bytes();
560
+ }
561
+ };
562
+ const slot = {
563
+ readerFor(analysis) {
564
+ if (analysis.fields.length === 0) return null;
565
+ adoptFields(analysis.fields);
566
+ resolvePending(analysis);
567
+ addEntriesToRuns();
568
+ return reader;
569
+ },
570
+ spellings() {
571
+ if (fields.length === 0 || everyDocumentPending || pending.size > 0) return null;
572
+ return encodedSpellings();
573
+ },
574
+ afterDocument(documentFields, internalId, spellings, direction) {
575
+ if (documentFields.length === 0) return;
576
+ if (!sameFields(fields, documentFields)) {
577
+ const holdsOnlyThisDocument = direction === 1 && view.docStore.count() === 1;
578
+ adoptFields(documentFields);
579
+ if (holdsOnlyThisDocument) everyDocumentPending = false;
580
+ }
581
+ if (everyDocumentPending) return;
582
+ if (direction === -1 && pending.delete(internalId)) return;
583
+ if (spellings !== null) {
584
+ applyCounts(spellings, direction);
585
+ } else if (direction === 1) {
586
+ pending.add(internalId);
587
+ } else {
588
+ everyDocumentPending = true;
589
+ }
590
+ },
591
+ afterMerge(spellings, internalIds) {
592
+ if (internalIds.length === 0) return;
593
+ if (fields.length === 0 && spellings !== null && view.docStore.count() === internalIds.length) {
594
+ adoptFields(spellings.fields);
595
+ everyDocumentPending = false;
596
+ }
597
+ if (fields.length === 0 || everyDocumentPending) return;
598
+ if (spellings === null || !sameFields(fields, spellings.fields)) {
599
+ for (const internalId of internalIds) pending.add(internalId);
600
+ return;
601
+ }
602
+ for (let at = 0; at < spellings.tokens.length; at++) {
603
+ change(spellings.tokens[at], spellings.spellings[at], spellings.counts[at]);
604
+ }
605
+ },
606
+ forgetSpellings() {
607
+ resetSpellings();
608
+ everyDocumentPending = fields.length > 0;
609
+ },
610
+ clear() {
611
+ fields = [];
612
+ everyDocumentPending = false;
613
+ resetSpellings();
614
+ },
615
+ bytes() {
616
+ return liveEntries * GROWING_PARTIAL_ENTRY_BYTES + runs.size * GROWING_PARTIAL_RUN_BYTES + runMembers * GROWING_PARTIAL_RUN_MEMBER_BYTES + entriesOutsideRuns.length * GROWING_PARTIAL_PENDING_ENTRY_BYTES;
617
+ }
618
+ };
619
+ return slot;
620
+ }
621
+
622
+ // src/core/partition/partial-words/highlight.ts
623
+ function containsPartialWord(spelling, words) {
624
+ for (const word of words) {
625
+ if (spelling.length > word.length && spelling.includes(word)) return true;
626
+ }
627
+ return false;
628
+ }
629
+ function partialWordMatcher(text, language, partial) {
630
+ const indexed = tokenize(text, language, {
631
+ stem: true,
632
+ removeStopWords: true,
633
+ collectSurfaces: true,
634
+ customTokenizer: partial.customTokenizer,
635
+ stopWordOverride: partial.stopWordOverride
636
+ });
637
+ const positions = /* @__PURE__ */ new Set();
638
+ const spellings = /* @__PURE__ */ new Set();
639
+ for (let at = 0; at < indexed.tokens.length; at++) {
640
+ const spelling = indexed.surfaces?.[at] ?? indexed.tokens[at].token;
641
+ if (!containsPartialWord(spelling, partial.words)) continue;
642
+ positions.add(indexed.tokens[at].position);
643
+ spellings.add(spelling);
644
+ }
645
+ if (partial.customTokenizer !== void 0) return (_position, fieldToken) => spellings.has(fieldToken);
646
+ return (position) => positions.has(position);
647
+ }
648
+
649
+ // src/core/partition/partial-words/query.ts
650
+ function addPartialWords(group, added) {
651
+ const membersByToken = /* @__PURE__ */ new Map();
652
+ for (const member of group.members) membersByToken.set(member.token, member);
653
+ for (const word of added) {
654
+ const member = membersByToken.get(word.token);
655
+ if (member === void 0) {
656
+ group.members.push({ token: word.token, factor: 0, partialFactor: word.factor });
657
+ } else if (word.factor > member.partialFactor) {
658
+ member.partialFactor = word.factor;
659
+ }
660
+ }
661
+ }
662
+ function partialWordRequests(query) {
663
+ const eligible = [];
664
+ for (const queryToken of query.queryTokens) {
665
+ const word = query.written.get(queryToken.position);
666
+ if (word === void 0 || codePointCount(word) < PARTIAL_WORD_MIN_CODE_POINTS) continue;
667
+ eligible.push({ token: queryToken.token, written: word });
668
+ if (eligible.length === PARTIAL_WORDS_ADDED_PER_QUERY) break;
669
+ }
670
+ const count = eligible.length;
671
+ if (count === 0) return [];
672
+ const evenShare = Math.floor(PARTIAL_WORDS_ADDED_PER_QUERY / count);
673
+ const remainder = PARTIAL_WORDS_ADDED_PER_QUERY % count;
674
+ return eligible.map((entry, order) => ({
675
+ token: entry.token,
676
+ request: {
677
+ written: entry.written,
678
+ ownToken: entry.token,
679
+ share: evenShare + (order < remainder ? 1 : 0),
680
+ tolerance: entry.token === query.prefixToken ? 0 : query.tolerance,
681
+ prefixLength: query.prefixLength ?? DEFAULT_FUZZY_PREFIX_LENGTH
682
+ }
683
+ }));
684
+ }
685
+ function addPartialWordMembers(query, expand, groupOf) {
686
+ const requests = partialWordRequests(query);
687
+ const added = expand(
688
+ query.analysis,
689
+ requests.map((entry) => entry.request)
690
+ );
691
+ for (let at = 0; at < requests.length; at++) {
692
+ if (added[at].length === 0) continue;
693
+ const token = requests[at].token;
694
+ addPartialWords(groupOf(token, token !== query.prefixToken), added[at]);
695
+ }
696
+ }
697
+ function partialWordsToHighlight(queryTokens, writtenWords) {
698
+ const writtenAt = /* @__PURE__ */ new Map();
699
+ for (const word of writtenWords) {
700
+ if (!writtenAt.has(word.position)) writtenAt.set(word.position, word.token);
701
+ }
702
+ const seenTokens = /* @__PURE__ */ new Set();
703
+ const words = [];
704
+ for (const queryToken of queryTokens) {
705
+ if (seenTokens.has(queryToken.token)) continue;
706
+ seenTokens.add(queryToken.token);
707
+ const word = writtenAt.get(queryToken.position);
708
+ if (word === void 0 || codePointCount(word) < PARTIAL_WORD_MIN_CODE_POINTS) continue;
709
+ words.push(word);
710
+ if (words.length === PARTIAL_WORDS_ADDED_PER_QUERY) break;
711
+ }
712
+ return words;
713
+ }
714
+
715
+ // src/core/partition/partial-words/module.ts
716
+ var partialWordSearchModule = {
717
+ name: "partialWords",
718
+ createGrowingSlot: createGrowingPartialWordSlot,
719
+ createFrozenSlot: createFrozenPartialWordSlot,
720
+ buildTable: buildPartialWordTable,
721
+ expand: expandPartialWords,
722
+ countSpelling,
723
+ encodeSpellings: encodePartialSpellings,
724
+ spellingCountsOf,
725
+ highlightMatcher: partialWordMatcher,
726
+ addTermMembers: addPartialWordMembers,
727
+ highlightWords: partialWordsToHighlight
728
+ };
729
+
730
+ // src/partial-words/index.ts
731
+ var partialWordSearch = partialWordSearchModule;
732
+
733
+ export { partialWordSearch };