@delali/narsil 0.3.1-next.154 → 0.3.1-next.156

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 (329) hide show
  1. package/NOTICE +45 -0
  2. package/README.md +1 -0
  3. package/dist/adapters/filesystem.mjs +2 -2
  4. package/dist/adapters/gcs.mjs +2 -2
  5. package/dist/adapters/indexeddb.mjs +1 -1
  6. package/dist/adapters/s3.mjs +2 -2
  7. package/dist/{analysis-change-4GCRVRBW.mjs → analysis-change-5BQOQ4BF.mjs} +35 -28
  8. package/dist/{react-native/chunks/analysis-change-entry-TNLUC6IZ.mjs → analysis-change-entry-TXX6JSMX.mjs} +1 -1
  9. package/dist/archive-history-E4R73RWD.mjs +29 -0
  10. package/dist/browser/{analysis-change-IXWPXXJJ.mjs → analysis-change-435CUEPZ.mjs} +32 -12
  11. package/dist/{analysis-change-entry-KYGSXW4K.mjs → browser/analysis-change-entry-HZXKPPGV.mjs} +1 -1
  12. package/dist/browser/archive-history-4IP5XQZY.mjs +29 -0
  13. package/dist/browser/{chunk-4PD752F6.mjs → chunk-23XRXIBW.mjs} +1 -1
  14. package/dist/browser/{chunk-J433A7P3.mjs → chunk-2CFI5VVV.mjs} +5 -5
  15. package/dist/{react-native/chunks/chunk-3XKMRNRE.mjs → browser/chunk-2TI4SSUP.mjs} +27 -10
  16. package/dist/browser/chunk-3SSRJMFN.mjs +100 -0
  17. package/dist/browser/{chunk-2SHAKW2Z.mjs → chunk-3V7DNNZL.mjs} +515 -733
  18. package/dist/browser/{chunk-C4KS2QNF.mjs → chunk-4NGKC4H4.mjs} +9 -9
  19. package/dist/browser/{chunk-XRV72TJD.mjs → chunk-6LWDPLTB.mjs} +2 -2
  20. package/dist/browser/chunk-7IGKGWSQ.mjs +79 -0
  21. package/dist/browser/{chunk-VCOYGVP7.mjs → chunk-7U3WVJUP.mjs} +3 -3
  22. package/dist/browser/chunk-ATEBYXP6.mjs +10 -0
  23. package/dist/browser/chunk-BHFQATSC.mjs +432 -0
  24. package/dist/browser/chunk-CRE3G7F3.mjs +1007 -0
  25. package/dist/browser/{chunk-QXTPSX2H.mjs → chunk-EA63E3D2.mjs} +7 -7
  26. package/dist/{react-native/chunks/chunk-DCKMICOB.mjs → browser/chunk-EXQZGUQH.mjs} +1 -1
  27. package/dist/browser/{chunk-ML6HY7T7.mjs → chunk-G64Q6OJF.mjs} +1 -1
  28. package/dist/browser/chunk-GPPOG6PT.mjs +9 -0
  29. package/dist/browser/{chunk-EUNBNLKM.mjs → chunk-IZXVW2ZJ.mjs} +5 -5
  30. package/dist/browser/{chunk-G7LUMBSG.mjs → chunk-K4Q6KX3R.mjs} +30 -20
  31. package/dist/browser/{chunk-H6QFBMVE.mjs → chunk-KZWSX6BH.mjs} +3 -3
  32. package/dist/browser/chunk-M3MQE2X7.mjs +151 -0
  33. package/dist/browser/chunk-MGI4BCXC.mjs +63 -0
  34. package/dist/browser/chunk-MOG4OVDK.mjs +51 -0
  35. package/dist/browser/{chunk-W5X2UFWQ.mjs → chunk-NLWTBAGB.mjs} +12 -3
  36. package/dist/browser/{chunk-AYY6PIKL.mjs → chunk-NQAME3RK.mjs} +2 -2
  37. package/dist/browser/{chunk-7MEYN7V6.mjs → chunk-NXQG7DRA.mjs} +29 -14
  38. package/dist/browser/chunk-OEDCEZXJ.mjs +92 -0
  39. package/dist/{chunk-KUZKUONM.mjs → browser/chunk-SRMZXJSL.mjs} +1 -0
  40. package/dist/browser/chunk-SSTPBZZX.mjs +1106 -0
  41. package/dist/browser/{chunk-7TTWXUH6.mjs → chunk-STOWQFT3.mjs} +3 -2
  42. package/dist/browser/{chunk-26A5JFT2.mjs → chunk-TK63WFXK.mjs} +2 -1
  43. package/dist/browser/{chunk-SJB6VIZG.mjs → chunk-U3JOQGWX.mjs} +1 -1
  44. package/dist/browser/{chunk-AJ4HHOVT.mjs → chunk-U4YDIBUT.mjs} +4 -4
  45. package/dist/browser/{chunk-2FX6ROWR.mjs → chunk-VLJQW4J6.mjs} +2986 -2986
  46. package/dist/{react-native/chunks/chunk-3O57C2ZO.mjs → browser/chunk-WI4MR75E.mjs} +2 -2
  47. package/dist/browser/{chunk-3U3QR5YP.mjs → chunk-WN464PTL.mjs} +2 -2
  48. package/dist/browser/{chunk-U2E3HMYW.mjs → chunk-XAWNZ4G2.mjs} +11 -11
  49. package/dist/browser/{cold-module-VTUGDYNY.mjs → cold-module-2EHCIV4K.mjs} +20 -18
  50. package/dist/browser/durability-config-TIYKW6XX.mjs +89 -0
  51. package/dist/browser/{durability-wiring-GL4A7KDV.mjs → durability-wiring-A7BVG2DW.mjs} +50 -153
  52. package/dist/browser/engine-hooks-E4UD67JD.mjs +17 -0
  53. package/dist/browser/geo-index-HHWGMNIS.mjs +1386 -0
  54. package/dist/browser/import-DXYB6756.mjs +19 -0
  55. package/dist/browser/{methods-LMUTS7OI.mjs → methods-KTQCSIN4.mjs} +3 -3
  56. package/dist/browser/{module-M4JNBV6V.mjs → module-NIYMEA5R.mjs} +16 -14
  57. package/dist/browser/{module-EC3FYW7N.mjs → module-TCT66FWA.mjs} +10 -9
  58. package/dist/browser/operations-OJ3BXS55.mjs +5 -0
  59. package/dist/browser/{phrase-module-NPYUVX75.mjs → phrase-module-HAT3TLZN.mjs} +2 -2
  60. package/dist/browser/{pool-WCGDZHJP.mjs → pool-3JLET5RO.mjs} +1 -1
  61. package/dist/browser/restore-hooks-YPN4ZFCY.mjs +114 -0
  62. package/dist/browser/restore-queue-G3RQGL3Y.mjs +55 -0
  63. package/dist/browser/{retention-6QMRS5VK.mjs → retention-ZWVMNC3Q.mjs} +18 -15
  64. package/dist/browser/{runtime-3EW2AGB6.mjs → runtime-OTAGEFQW.mjs} +1 -1
  65. package/dist/browser/{snapshot-DN3CRVUQ.mjs → snapshot-VEQNIE6C.mjs} +71 -36
  66. package/dist/browser/start-BM442C6R.mjs +25 -0
  67. package/dist/browser/{write-WAWAFGKQ.mjs → write-2EVMZWDE.mjs} +16 -14
  68. package/dist/{capabilities-B3Brs1Rc.d.ts → capabilities-Da4ywVVl.d.ts} +35 -3
  69. package/dist/{chunk-K4B7OH65.mjs → chunk-25KDNIZZ.mjs} +2 -2
  70. package/dist/{chunk-O43Z4MS6.mjs → chunk-2NE7VCYE.mjs} +2 -2
  71. package/dist/chunk-2UV4QBHW.mjs +1092 -0
  72. package/dist/{chunk-3Y3J4V2R.mjs → chunk-3C7MTCCI.mjs} +1 -1
  73. package/dist/{chunk-TRISKD4Q.mjs → chunk-3HYC4JRF.mjs} +2 -2
  74. package/dist/{chunk-HVYICDY3.mjs → chunk-3OH67G7R.mjs} +1 -1
  75. package/dist/{chunk-PFKM7VNZ.mjs → chunk-46KY2PJD.mjs} +30 -11
  76. package/dist/{chunk-IJU7LL7D.mjs → chunk-4KKXNJM6.mjs} +5 -5
  77. package/dist/{chunk-IQ4R2I6N.mjs → chunk-5FLRXF73.mjs} +5 -1
  78. package/dist/{chunk-BPSKLCS7.mjs → chunk-5VV4R6P7.mjs} +3017 -3017
  79. package/dist/chunk-5YNRKI2C.mjs +81 -0
  80. package/dist/chunk-6HTGOXIK.mjs +875 -0
  81. package/dist/{chunk-7HCZWC7B.mjs → chunk-6I6AYAXS.mjs} +50 -8
  82. package/dist/{chunk-C6ASEFZI.mjs → chunk-6OEGXLBX.mjs} +1 -1
  83. package/dist/{chunk-DVWYODEB.mjs → chunk-6RC4K46J.mjs} +2 -2
  84. package/dist/chunk-7GFE3PEY.mjs +40 -0
  85. package/dist/{chunk-QKZHLADX.mjs → chunk-7LXHHCXZ.mjs} +28 -19
  86. package/dist/{chunk-JUKYYXSP.mjs → chunk-7V5IUP2T.mjs} +1 -31
  87. package/dist/{react-native/chunks/chunk-7GWPJDOA.mjs → chunk-A4L7YTKX.mjs} +53 -90
  88. package/dist/{chunk-Z3TNWCI5.mjs → chunk-BU4SAIC4.mjs} +3 -3
  89. package/dist/chunk-BWZ3P4MU.mjs +20 -0
  90. package/dist/{chunk-OKX2BBNW.mjs → chunk-CITFCZKF.mjs} +5 -4
  91. package/dist/{chunk-4HWZV5MK.mjs → chunk-CSLGFPFQ.mjs} +5 -5
  92. package/dist/chunk-DP5C7YFQ.mjs +543 -0
  93. package/dist/{chunk-RVKFI3A2.mjs → chunk-DWEPMFJE.mjs} +11 -8
  94. package/dist/{chunk-LSM2YTKM.mjs → chunk-EFBDHH5P.mjs} +87 -144
  95. package/dist/{chunk-NZMAXR2S.mjs → chunk-FAKFUDZZ.mjs} +121 -11
  96. package/dist/chunk-FB6463IN.mjs +1499 -0
  97. package/dist/{chunk-REL7LFLR.mjs → chunk-FCJ553HS.mjs} +3 -3
  98. package/dist/{chunk-MMEMEUOO.mjs → chunk-FJKKCV4D.mjs} +2 -2
  99. package/dist/{chunk-K7KLL263.mjs → chunk-FNGAM5B7.mjs} +14 -13
  100. package/dist/{chunk-DMQPFLGI.mjs → chunk-FRBFVQFN.mjs} +6 -5
  101. package/dist/{chunk-IBNLW3AV.mjs → chunk-FYOVBEMM.mjs} +20 -6
  102. package/dist/chunk-G6HRSGOU.mjs +74 -0
  103. package/dist/{chunk-USR7FQRZ.mjs → chunk-GH4WQ22V.mjs} +2 -2
  104. package/dist/chunk-GQPTDQCL.mjs +54 -0
  105. package/dist/{chunk-VREK3MYG.mjs → chunk-HFPMMRQT.mjs} +3 -3
  106. package/dist/{chunk-MLHNSAPK.mjs → chunk-HHBUCIUY.mjs} +3 -3
  107. package/dist/{chunk-YROWNOMH.mjs → chunk-HJJI72X7.mjs} +1 -1
  108. package/dist/{chunk-ECX4SGX6.mjs → chunk-I2KPOLOZ.mjs} +9 -9
  109. package/dist/{chunk-TV2L3BN7.mjs → chunk-I53G4JAU.mjs} +266 -265
  110. package/dist/{chunk-3A5KI24C.mjs → chunk-I54T6CQP.mjs} +1 -1
  111. package/dist/{chunk-NTZOXVUZ.mjs → chunk-I5B7RXU7.mjs} +93 -24
  112. package/dist/{chunk-YBJDOA2T.mjs → chunk-INJYO3BU.mjs} +1 -1
  113. package/dist/{react-native/chunks/chunk-KWRW5U65.mjs → chunk-J4IJTTEX.mjs} +1 -1
  114. package/dist/{chunk-X6NSJYQ3.mjs → chunk-JDJBQLRO.mjs} +13 -13
  115. package/dist/{chunk-MMBEANB2.mjs → chunk-JWRUUCWD.mjs} +3 -3
  116. package/dist/{chunk-AO2FAYIZ.mjs → chunk-K4ZIGL2O.mjs} +1 -1
  117. package/dist/{chunk-JFNKIBDT.mjs → chunk-K5QFDYST.mjs} +2 -2
  118. package/dist/{chunk-C73JLU4E.mjs → chunk-KF4EXSM4.mjs} +2 -2
  119. package/dist/{chunk-WCBA2LVZ.mjs → chunk-KHKIRS5D.mjs} +1 -1
  120. package/dist/{chunk-7QUGDVFC.mjs → chunk-KJ3RTZDJ.mjs} +1 -1
  121. package/dist/{chunk-HVKXNBFL.mjs → chunk-KKQC526K.mjs} +20 -12
  122. package/dist/chunk-KP7TYHWT.mjs +92 -0
  123. package/dist/{chunk-VMXSVVXG.mjs → chunk-L6V6BST3.mjs} +9 -22
  124. package/dist/{chunk-URPCYQVJ.mjs → chunk-LHKOSI2J.mjs} +1 -1
  125. package/dist/chunk-LNGE7SLY.mjs +151 -0
  126. package/dist/{react-native/chunks/chunk-CUNGPR5R.mjs → chunk-MP7ABPTD.mjs} +1 -0
  127. package/dist/{chunk-5KGYQT6W.mjs → chunk-MQOJIO5B.mjs} +26 -9
  128. package/dist/{chunk-Q3TCTQCC.mjs → chunk-NF4DT3IH.mjs} +1 -1
  129. package/dist/{chunk-3OFU3NJT.mjs → chunk-OIJ64LGT.mjs} +1 -1
  130. package/dist/chunk-ORN5BLL7.mjs +11 -0
  131. package/dist/{chunk-HWEDFLB7.mjs → chunk-P5ZI2P2W.mjs} +126 -1701
  132. package/dist/{chunk-466PYR4P.mjs → chunk-PWC4VB3Q.mjs} +2 -2
  133. package/dist/{chunk-B7S6YEBP.mjs → chunk-QJVOLKU6.mjs} +12 -3
  134. package/dist/{chunk-KCUIFVVW.mjs → chunk-QOW2JPUI.mjs} +9 -9
  135. package/dist/chunk-RDXO6JST.mjs +63 -0
  136. package/dist/chunk-RLOES5SX.mjs +31 -0
  137. package/dist/{chunk-YPUEV6ZC.mjs → chunk-RVGRFOGN.mjs} +1 -1
  138. package/dist/{chunk-JCLTESFN.mjs → chunk-RZWWB2XR.mjs} +1 -1
  139. package/dist/chunk-S5LN746F.mjs +10 -0
  140. package/dist/chunk-SA5LOGO3.mjs +470 -0
  141. package/dist/chunk-SQJWAIF4.mjs +12 -0
  142. package/dist/{chunk-YTJCGKM4.mjs → chunk-TBC3XUL2.mjs} +29 -6
  143. package/dist/chunk-TDIK6NTV.mjs +10 -0
  144. package/dist/chunk-TGS5UXBE.mjs +216 -0
  145. package/dist/{chunk-CP5RRPJR.mjs → chunk-TQXHPFWT.mjs} +1 -1
  146. package/dist/{chunk-7NTMUDC5.mjs → chunk-TZ3355VS.mjs} +5 -5
  147. package/dist/{chunk-Q7MS6P2J.mjs → chunk-TZTRKM33.mjs} +2 -2
  148. package/dist/{chunk-4UMZ7KQL.mjs → chunk-U55XJEIG.mjs} +2 -1
  149. package/dist/{chunk-S2N75OTN.mjs → chunk-UHICS3JI.mjs} +1 -1
  150. package/dist/{chunk-5FUOVJKG.mjs → chunk-VTTRFF2C.mjs} +32 -19
  151. package/dist/{chunk-62G63NMH.mjs → chunk-WX4LAO6M.mjs} +4 -4
  152. package/dist/{chunk-LTUGDMV4.mjs → chunk-WZ7YV54N.mjs} +1 -1
  153. package/dist/chunk-XAXKV65G.mjs +72 -0
  154. package/dist/chunk-XXHN7J46.mjs +101 -0
  155. package/dist/{chunk-PGVPE7GJ.mjs → chunk-YEKL4JBK.mjs} +1 -1
  156. package/dist/chunk-YTWZVGCB.mjs +382 -0
  157. package/dist/chunk-Z2KAFCRT.mjs +30 -0
  158. package/dist/{chunk-LKUE5GXS.mjs → chunk-ZKP7G7TV.mjs} +2 -2
  159. package/dist/{client-Df76GNKm.d.ts → client-DRv7UVeY.d.ts} +123 -11
  160. package/dist/client.d.ts +9 -8
  161. package/dist/client.mjs +65 -3
  162. package/dist/{cold-module-YLWMTTZG.mjs → cold-module-6MO2XJF2.mjs} +45 -39
  163. package/dist/{config-B8DP2VwR.d.ts → config-CoSig5Ox.d.ts} +22 -3
  164. package/dist/{config-05G_hy-1.d.ts → config-DMwffLKn.d.ts} +20 -5
  165. package/dist/direct-executor-FTMYY3TI.mjs +34 -0
  166. package/dist/distribution/coordinator/etcd.d.ts +2 -2
  167. package/dist/distribution/coordinator/etcd.mjs +3 -3
  168. package/dist/distribution/coordinator/in-memory.d.ts +2 -2
  169. package/dist/distribution/coordinator/in-memory.mjs +2 -2
  170. package/dist/distribution/transport/grpc.mjs +4 -4
  171. package/dist/distribution/transport/in-memory.mjs +2 -2
  172. package/dist/distribution/transport/tcp.mjs +3 -3
  173. package/dist/distribution.d.ts +8 -8
  174. package/dist/distribution.mjs +6799 -5939
  175. package/dist/durability-config-GE4U7MCZ.mjs +89 -0
  176. package/dist/{durability-wiring-RHLXDIVF.mjs → durability-wiring-VIF5MOSY.mjs} +82 -179
  177. package/dist/embeddings/openai.mjs +2 -2
  178. package/dist/{sync-uXR7MmM7.d.ts → engine-CFxPYqEk.d.ts} +702 -2
  179. package/dist/engine-hooks-EGUGNZYE.mjs +54 -0
  180. package/dist/geo-index-MRH5JMIR.mjs +1387 -0
  181. package/dist/import-XKDPJQDP.mjs +56 -0
  182. package/dist/{index-nRqDM6uS.d.ts → index-C4AmUnl1.d.ts} +1 -1
  183. package/dist/index.browser.mjs +9 -7
  184. package/dist/index.d.ts +134 -9
  185. package/dist/index.mjs +33 -26
  186. package/dist/index.react-native.mjs +20 -17
  187. package/dist/invalidation/filesystem.mjs +2 -2
  188. package/dist/{long-query-thread-EMYTGSJP.mjs → long-query-thread-YA4IAYSY.mjs} +34 -28
  189. package/dist/{methods-ABM5ELBR.mjs → methods-7IOINERF.mjs} +3 -3
  190. package/dist/{module-MG7JMV2U.mjs → module-FQ4JWNQJ.mjs} +41 -34
  191. package/dist/{module-3OMJZUFT.mjs → module-N55W4Q5C.mjs} +14 -14
  192. package/dist/operations-G5EP6JPX.mjs +5 -0
  193. package/dist/{paged-partition-archive-UOLHOEZJ.mjs → paged-partition-archive-PXW5XAYU.mjs} +48 -38
  194. package/dist/partial-words.mjs +11 -9
  195. package/dist/pattern.mjs +6 -5
  196. package/dist/persistence/durability/checkpoint-worker.d.ts +8 -1
  197. package/dist/persistence/durability/checkpoint-worker.mjs +44 -35
  198. package/dist/{phrase-module-O3MDRQXP.mjs → phrase-module-XW5MKWP5.mjs} +4 -3
  199. package/dist/{pool-CQXYPFLG.mjs → pool-Y4A46T36.mjs} +1 -1
  200. package/dist/query-suggestions/merge-worker.d.ts +55 -0
  201. package/dist/query-suggestions/merge-worker.mjs +88 -0
  202. package/dist/query-suggestions-CBYkrQ5T.d.ts +311 -0
  203. package/dist/query-suggestions.browser.mjs +247 -0
  204. package/dist/query-suggestions.d.ts +20 -0
  205. package/dist/query-suggestions.mjs +69 -0
  206. package/dist/react-native/chunks/{analysis-change-EAYO3Y6Q.mjs → analysis-change-LT5QBQ3H.mjs} +43 -22
  207. package/dist/{browser/analysis-change-entry-FCSHFQSS.mjs → react-native/chunks/analysis-change-entry-SCVWK6OU.mjs} +1 -1
  208. package/dist/react-native/chunks/archive-history-MJKUQLSU.mjs +29 -0
  209. package/dist/{chunk-ZIFJXCKA.mjs → react-native/chunks/chunk-2PRHILX3.mjs} +54 -20
  210. package/dist/react-native/chunks/{chunk-VQSKZ3EZ.mjs → chunk-3JWDECAZ.mjs} +8 -8
  211. package/dist/{chunk-R6A773WK.mjs → react-native/chunks/chunk-3WI35N75.mjs} +1 -1
  212. package/dist/react-native/chunks/{chunk-75VWIY35.mjs → chunk-4DII3ZSM.mjs} +1 -1
  213. package/dist/react-native/chunks/{chunk-NKIZX26F.mjs → chunk-4J74WHQM.mjs} +2 -2
  214. package/dist/react-native/chunks/{chunk-UWDNZDWK.mjs → chunk-4JYO3JD2.mjs} +6 -6
  215. package/dist/react-native/chunks/chunk-5CQX3XXV.mjs +17 -0
  216. package/dist/react-native/chunks/chunk-6VBXNFLE.mjs +9 -0
  217. package/dist/react-native/chunks/{chunk-SJWDBRNP.mjs → chunk-6WA3C3DV.mjs} +1 -1
  218. package/dist/react-native/chunks/{chunk-OQQVRWZ2.mjs → chunk-C5G6TJ7A.mjs} +1 -1
  219. package/dist/react-native/chunks/{chunk-RVAEBN74.mjs → chunk-CKNRFDTZ.mjs} +1 -1
  220. package/dist/react-native/chunks/chunk-DIYDOIM4.mjs +10 -0
  221. package/dist/react-native/chunks/{chunk-O32RB3BL.mjs → chunk-DNXOMPAQ.mjs} +4 -4
  222. package/dist/react-native/chunks/{chunk-YBEW6YTR.mjs → chunk-DVDX4SDR.mjs} +2 -2
  223. package/dist/react-native/chunks/chunk-DXRSEWA2.mjs +12 -0
  224. package/dist/{browser/chunk-MYITLCHT.mjs → react-native/chunks/chunk-DZ7H7D2C.mjs} +1 -0
  225. package/dist/react-native/chunks/{chunk-PPEPTUVV.mjs → chunk-EJ33LCHV.mjs} +29 -6
  226. package/dist/react-native/chunks/{chunk-RYMDHGL4.mjs → chunk-ENLMYKSX.mjs} +3045 -3075
  227. package/dist/react-native/chunks/chunk-FHPW7P2O.mjs +40 -0
  228. package/dist/react-native/chunks/{chunk-JV6VQY2S.mjs → chunk-FTZHMRD2.mjs} +2 -1
  229. package/dist/react-native/chunks/{chunk-YHKZSLOC.mjs → chunk-G43IPIDG.mjs} +5 -5
  230. package/dist/react-native/chunks/{chunk-AUT7PMA4.mjs → chunk-GXX3DQXP.mjs} +8 -22
  231. package/dist/react-native/chunks/chunk-H3MDVPBO.mjs +151 -0
  232. package/dist/react-native/chunks/{chunk-DH3TVWWK.mjs → chunk-IYNT75CE.mjs} +12 -3
  233. package/dist/react-native/chunks/chunk-KV46CT4D.mjs +1007 -0
  234. package/dist/{browser/chunk-ZPTA75ZC.mjs → react-native/chunks/chunk-LZSLNSUN.mjs} +1 -1
  235. package/dist/react-native/chunks/{chunk-63YSZOXB.mjs → chunk-MIP4SOR6.mjs} +1480 -826
  236. package/dist/react-native/chunks/{chunk-ZBSWRSBG.mjs → chunk-MJDQU5MW.mjs} +1 -1
  237. package/dist/react-native/chunks/{chunk-GFYFQLJD.mjs → chunk-MUWD2H2S.mjs} +2 -2
  238. package/dist/react-native/chunks/{chunk-IOY2SM2P.mjs → chunk-MVXELMJX.mjs} +1 -1
  239. package/dist/{browser/chunk-TTD27VXX.mjs → react-native/chunks/chunk-NB3LP33V.mjs} +27 -10
  240. package/dist/react-native/chunks/{chunk-I5PGWQJF.mjs → chunk-PDRWWPKV.mjs} +33 -24
  241. package/dist/react-native/chunks/chunk-PJHAB5ZY.mjs +79 -0
  242. package/dist/react-native/chunks/{chunk-2CGSQM4O.mjs → chunk-POPDAGH6.mjs} +13 -13
  243. package/dist/react-native/chunks/{chunk-NP7DD4G5.mjs → chunk-QUKQNI3H.mjs} +5 -5
  244. package/dist/react-native/chunks/{chunk-EH5CFV6Z.mjs → chunk-RDWG33MM.mjs} +2 -2
  245. package/dist/react-native/chunks/{chunk-JX2RIAXH.mjs → chunk-SK2PWYDH.mjs} +5 -5
  246. package/dist/react-native/chunks/{chunk-ZYDKJXQJ.mjs → chunk-SUPXRTMD.mjs} +1 -1
  247. package/dist/react-native/chunks/chunk-TP6KCKER.mjs +63 -0
  248. package/dist/react-native/chunks/{chunk-JPAJWO6D.mjs → chunk-U4KSKA4Z.mjs} +1 -1
  249. package/dist/react-native/chunks/chunk-UQ4OAXKU.mjs +1106 -0
  250. package/dist/react-native/chunks/{chunk-VVFYOADG.mjs → chunk-VWUDIOT6.mjs} +6 -6
  251. package/dist/{browser/chunk-SIR3LMTV.mjs → react-native/chunks/chunk-WBYQRHDY.mjs} +2 -2
  252. package/dist/react-native/chunks/{chunk-C2H2QQFW.mjs → chunk-YH7QY657.mjs} +3 -3
  253. package/dist/react-native/chunks/{chunk-NCJS3WIY.mjs → chunk-YZW4CHM6.mjs} +51 -12
  254. package/dist/react-native/chunks/chunk-ZLWVW734.mjs +100 -0
  255. package/dist/react-native/chunks/chunk-ZXZFN7FI.mjs +432 -0
  256. package/dist/react-native/chunks/chunk-ZZT7CEN7.mjs +92 -0
  257. package/dist/react-native/chunks/{cold-module-TJL6AFAD.mjs → cold-module-KVZYUGRY.mjs} +31 -28
  258. package/dist/react-native/chunks/durability-config-QXVZEO7T.mjs +89 -0
  259. package/dist/react-native/chunks/{durability-wiring-RRDYJLLM.mjs → durability-wiring-34OYO32E.mjs} +60 -162
  260. package/dist/react-native/chunks/engine-hooks-M7JV46NH.mjs +30 -0
  261. package/dist/react-native/chunks/geo-index-PX3BIHAH.mjs +1387 -0
  262. package/dist/react-native/chunks/gzip.react-native-HLEPDKZ3.mjs +3 -0
  263. package/dist/react-native/chunks/import-H6AQREWI.mjs +32 -0
  264. package/dist/react-native/chunks/{methods-X6F36SJE.mjs → methods-6W5U4C3H.mjs} +3 -3
  265. package/dist/react-native/chunks/module-LBZPGOWH.mjs +36 -0
  266. package/dist/react-native/chunks/{module-S4DKSWMF.mjs → module-TTEVPRCW.mjs} +14 -13
  267. package/dist/react-native/chunks/operations-GNRMD6EX.mjs +5 -0
  268. package/dist/react-native/chunks/{phrase-module-JZ37TB7N.mjs → phrase-module-QK22HSQ2.mjs} +2 -2
  269. package/dist/react-native/chunks/{pool-RTGXJXPU.mjs → pool-JR3NJCAF.mjs} +1 -1
  270. package/dist/react-native/chunks/restore-hooks-IBGIY3DR.mjs +127 -0
  271. package/dist/react-native/chunks/restore-queue-ZZX54AH7.mjs +55 -0
  272. package/dist/react-native/chunks/{retention-PPCTP2VY.mjs → retention-EW4TTDFB.mjs} +29 -25
  273. package/dist/react-native/chunks/{runtime-KUATOLYB.mjs → runtime-R5E3TB3J.mjs} +1 -1
  274. package/dist/react-native/chunks/{snapshot-ZBIEOZTZ.mjs → snapshot-REYVIN3X.mjs} +80 -44
  275. package/dist/react-native/chunks/start-BQK6KN3R.mjs +38 -0
  276. package/dist/react-native/chunks/{write-2W4FTX7J.mjs → write-FQAYCZF5.mjs} +27 -24
  277. package/dist/react-native/partial-words.mjs +11 -9
  278. package/dist/react-native/pattern.mjs +4 -4
  279. package/dist/react-native/query-suggestions.mjs +260 -0
  280. package/dist/react-native/sync.mjs +78 -15
  281. package/dist/react-native/synonyms.mjs +95 -27
  282. package/dist/react.d.ts +11 -11
  283. package/dist/react.mjs +1 -0
  284. package/dist/{rerank-IZOB6NII.mjs → rerank-MQ37IYRV.mjs} +4 -4
  285. package/dist/rerankers/http.mjs +2 -2
  286. package/dist/restore-hooks-CDERDEF4.mjs +153 -0
  287. package/dist/restore-queue-7NNSTROA.mjs +55 -0
  288. package/dist/retention-QSVBBNRM.mjs +66 -0
  289. package/dist/{runtime-UZOC3NPY.mjs → runtime-COIUORCN.mjs} +5 -5
  290. package/dist/{schema-DDauvDOv.d.ts → schema-Jwt928nJ.d.ts} +1 -1
  291. package/dist/server.d.ts +108 -12
  292. package/dist/server.mjs +303 -50
  293. package/dist/{snapshot-NFX2EYN2.mjs → snapshot-RH4NSKIZ.mjs} +98 -61
  294. package/dist/start-MCKCOGIW.mjs +66 -0
  295. package/dist/sync/filesystem.d.ts +4 -4
  296. package/dist/sync/filesystem.mjs +6 -6
  297. package/dist/sync/indexeddb.d.ts +4 -4
  298. package/dist/sync/indexeddb.mjs +2 -2
  299. package/dist/sync.browser.mjs +74 -11
  300. package/dist/sync.d.ts +5 -5
  301. package/dist/sync.mjs +78 -16
  302. package/dist/synonyms.mjs +9 -8
  303. package/dist/{tasks-BShx8pdK.d.ts → tasks-qrJojgST.d.ts} +13 -5
  304. package/dist/thread-O4SBJJJS.mjs +50 -0
  305. package/dist/{types-SnO7_tAI.d.ts → types-BZCGjfLn.d.ts} +2 -3
  306. package/dist/vector/search-worker.d.ts +1 -1
  307. package/dist/vector/search-worker.mjs +8 -8
  308. package/dist/workers/entry.mjs +19 -8
  309. package/dist/{write-FGB62BHQ.mjs → write-3FK7NG3Y.mjs} +40 -33
  310. package/openapi.json +798 -7
  311. package/package.json +32 -8
  312. package/dist/browser/import-YI5GNB4H.mjs +0 -17
  313. package/dist/browser/operations-WVYLF72Q.mjs +0 -5
  314. package/dist/browser/restore-queue-TYIGDL5L.mjs +0 -41
  315. package/dist/chunk-37IVJLP6.mjs +0 -44
  316. package/dist/chunk-DJHHF2L5.mjs +0 -17
  317. package/dist/direct-executor-FI5GJHWX.mjs +0 -29
  318. package/dist/engine-DYu-e0oR.d.ts +0 -674
  319. package/dist/import-SRBNC6TE.mjs +0 -49
  320. package/dist/operations-PGOAY2KS.mjs +0 -5
  321. package/dist/react-native/chunks/chunk-TJMSKBEM.mjs +0 -25
  322. package/dist/react-native/chunks/gzip.react-native-DNB5YNFA.mjs +0 -3
  323. package/dist/react-native/chunks/import-JYBMEJPQ.mjs +0 -29
  324. package/dist/react-native/chunks/module-QT5HZAY4.mjs +0 -33
  325. package/dist/react-native/chunks/operations-RYKTSZQA.mjs +0 -5
  326. package/dist/react-native/chunks/restore-queue-ZBVIKJWI.mjs +0 -41
  327. package/dist/restore-queue-COI2GSSK.mjs +0 -41
  328. package/dist/retention-55WA7GPU.mjs +0 -58
  329. package/dist/thread-P2G2FWM2.mjs +0 -44
@@ -1,26 +1,28 @@
1
- import { DEFAULT_MAX_RERANK_WINDOW, DEFAULT_RERANK_TIMEOUT_MS } from './chunk-IO2SMUQD.mjs';
2
- import { createDocIdMap, detectRuntime, countWrite, HEAP_RESUME_FRACTION_BELOW_V8_INEFFECTIVE_MARK_COMPACT_LINE, HEAP_BLOCK_FRACTION_BELOW_V8_INEFFECTIVE_MARK_COMPACT_LINE, yieldBackgroundTurn, backgroundTurnIsSpent, reservedHeapBytes, reserveHeapBytes, turnIsSpent, yieldTurn, MIN_OVERSAMPLE, noteThreadSlotGone, threadSlotOfWorker, collectYoungGenerationBeforeRefusal, collectGarbageBeforeRefusal, collectAndReturnPages, admittedHeapBytes, turnsAreBudgeted, indexChangeOutsideExternalWaits, changeIndexOutsideExternalWaits } from './chunk-NCJS3WIY.mjs';
3
- import { MAX_INDEX_CONFIGURATION_BYTES, ABSOLUTE_WINDOWS_PATH_PATTERN, MODULE_URL_SCHEME_PATTERN, MAX_SWEEP_INTERVAL_MS, MIN_SWEEP_INTERVAL_MS, STATISTICS_BROADCAST_INTERVAL_MS, BATCH_CHUNK_SIZE, MAX_INDEX_NAME_LENGTH, INDEX_NAME_PATTERN, HEAP_PRESSURE_WARNING_FRACTION, MAX_SUGGEST_LIMIT, FOREIGN_STATS_TTL_MS, DEFAULT_SUGGEST_LIMIT, DEFAULT_LIMIT, DEFAULT_OFFSET, MIN_DOCUMENTS_FOR_SEGMENTS, HEAP_PRESSURE_REARM_FRACTION, MAX_DOC_ID_LENGTH } from './chunk-AM7RSBPF.mjs';
4
1
  import { createRequestId } from './chunk-NNE4VDMM.mjs';
5
- import { splitWorkerBudget, resolveWorkerCount, DEFAULT_REQUEST_TIMEOUT_MS, resolveRequestThreadCount, MAX_RENUMBERED_SEARCH_ATTEMPTS } from './chunk-LU3Y3P63.mjs';
6
- import { PATTERN_EXPRESSION_OPERATORS, PATTERN_TEST_OPERATORS, PATTERN_ELEMENT_OPERATORS, requireTextRangeField, isFiniteNumber, invalid, requireFieldKind, kindOfValue, requireListLength, isObjectRecord, GEO_UNIT_METRES, DEFAULT_PATTERN_WORK_CAP, MAX_FILTER_DEPTH, MATCHER_STATE_BUDGET_BYTES, MAX_FILTER_TESTS, FILTER_OPERAND_COPY_DEPTH, TYPO_CLAIM_SLOTS_PER_WORD, PATTERN_WORK_FLUSH_UNITS } from './chunk-EH5CFV6Z.mjs';
7
- import { isLatitude, MAX_LATITUDE_DEGREES, isLongitude, MAX_LONGITUDE_DEGREES, MIN_POLYGON_POINTS, expandTermPrefix, getNestedValue, tokenizeOptions, raiseEarlierReleaseGraphSetting, messagePackUpperBoundBytes, suggestDisplayTerms, validateDocument, validateDocumentStrict, textFieldsChanged, sameFields, getFlatSchema, getOrCreateFieldNameIndex, partitionDocumentFrequency, visitDocumentSurfaceSpellings, visitDocumentSpellings, validateVectorStorage, validateTextStorage, validateVectorPromotion, ANTIMERIDIAN_SPAN_DEGREES, FULL_TURN_DEGREES, LOCATION_CODE_BITS_PER_AXIS, MAX_COVERING_CELLS, VINCENTY_CONVERGENCE_THRESHOLD, EARTH_RADIUS_METERS, RADIUS_BOX_MARGIN_RATIO, RADIUS_BOX_MARGIN_RADIANS, DEG_TO_RAD, validateRequiredFields, requireDocumentWithinSizeLimit, VINCENTY_MAX_ITERATIONS } from './chunk-AUT7PMA4.mjs';
2
+ import { DEFAULT_MAX_RERANK_WINDOW, DEFAULT_RERANK_TIMEOUT_MS } from './chunk-IO2SMUQD.mjs';
3
+ import { createDocIdMap, turnsAreBudgeted, turnIsSpent, yieldTurn, detectRuntime, indexChangeOutsideExternalWaits, changeIndexOutsideExternalWaits, noteFallback, countWrite, nativeSearchCoreIsEnabled, loadNativeCore, HEAP_RESUME_FRACTION_BELOW_V8_INEFFECTIVE_MARK_COMPACT_LINE, HEAP_BLOCK_FRACTION_BELOW_V8_INEFFECTIVE_MARK_COMPACT_LINE, yieldBackgroundTurn, backgroundTurnIsSpent, reservedHeapBytes, reserveHeapBytes, MIN_OVERSAMPLE, noteThreadSlotGone, threadSlotOfWorker, collectYoungGenerationBeforeRefusal, collectGarbageBeforeRefusal, collectAndReturnPages, admittedHeapBytes, NATIVE_OK } from './chunk-YZW4CHM6.mjs';
4
+ import { splitWorkerBudget, resolveWorkerCount, resolveRequestThreadCount, DEFAULT_REQUEST_TIMEOUT_MS, MAX_RENUMBERED_SEARCH_ATTEMPTS } from './chunk-LU3Y3P63.mjs';
5
+ import { MAX_INDEX_CONFIGURATION_BYTES, MAX_INDEX_NAME_LENGTH, INDEX_NAME_PATTERN, BATCH_CHUNK_SIZE, MAX_DOC_ID_LENGTH, ABSOLUTE_WINDOWS_PATH_PATTERN, MODULE_URL_SCHEME_PATTERN, MAX_SWEEP_INTERVAL_MS, MIN_SWEEP_INTERVAL_MS, STATISTICS_BROADCAST_INTERVAL_MS, HEAP_PRESSURE_WARNING_FRACTION, MAX_SUGGEST_LIMIT, FOREIGN_STATS_TTL_MS, DEFAULT_SUGGEST_LIMIT, DEFAULT_LIMIT, DEFAULT_OFFSET, MIN_DOCUMENTS_FOR_SEGMENTS, HEAP_PRESSURE_REARM_FRACTION } from './chunk-AM7RSBPF.mjs';
6
+ import { reactNativeHost } from './chunk-MVXELMJX.mjs';
7
+ import { PATTERN_EXPRESSION_OPERATORS, PATTERN_TEST_OPERATORS, PATTERN_ELEMENT_OPERATORS, requireTextRangeField, isFiniteNumber, invalid, requireFieldKind, kindOfValue, requireListLength, isObjectRecord, GEO_UNIT_METRES, DEFAULT_PATTERN_WORK_CAP, MAX_FILTER_DEPTH, MATCHER_STATE_BUDGET_BYTES, MAX_FILTER_TESTS, FILTER_OPERAND_COPY_DEPTH, TYPO_CLAIM_SLOTS_PER_WORD, PATTERN_WORK_FLUSH_UNITS } from './chunk-RDWG33MM.mjs';
8
+ import { isLatitude, isLongitude, expandTermPrefix, getNestedValue, tokenizeOptions, raiseEarlierReleaseGraphSetting, messagePackUpperBoundBytes, validateVectorPromotion, validateVectorStorage, validateTextStorage, suggestDisplayTerms, validateDocument, validateDocumentStrict, textFieldsChanged, sameFields, getFlatSchema, getOrCreateFieldNameIndex, partitionDocumentFrequency, visitDocumentSurfaceSpellings, visitDocumentSpellings, validateRequiredFields, requireDocumentWithinSizeLimit } from './chunk-GXX3DQXP.mjs';
8
9
  import { fuzzyPrefixOf, boundedLevenshtein, fuzzyTermMatches } from './chunk-UNUFZ2QY.mjs';
9
- import { withOpenIndex, oneAtATime, emitSyncChange } from './chunk-JDOEEMEF.mjs';
10
- import { encodeStringBlob, encodeLookupKey, visitTokens, codePointOrder, tokenize } from './chunk-7GWPJDOA.mjs';
11
- import { requireWithinFileLimit, HEADER_SIZE, payloadByteLength, checksumOfChunks, packEnvelopeWithEngineVersion, INDEX_CONFIGURATION_ENVELOPE_VERSION, readHeapStatistics, readOldGenerationStatistics } from './chunk-C2H2QQFW.mjs';
10
+ import { emitSyncChange, withOpenIndex, oneAtATime } from './chunk-JDOEEMEF.mjs';
11
+ import { encodeStringBlob, encodeLookupKey, visitTokens, codePointOrder, tokenize, installNativeAnalysis, NATIVE_ANALYSIS_FIRST_TOKEN_RECORDS, NATIVE_ANALYSIS_HELD_TERMS } from './chunk-2PRHILX3.mjs';
12
+ import { requireWithinFileLimit, HEADER_SIZE, payloadByteLength, checksumOfChunks, packEnvelopeWithEngineVersion, INDEX_CONFIGURATION_ENVELOPE_VERSION, readHeapStatistics, readOldGenerationStatistics } from './chunk-YH7QY657.mjs';
12
13
  import { fnv1a, FNV_OFFSET_BASIS, fnv1aContinue, fnv1aContinueTaggedNumbers } from './chunk-CHPTFFJM.mjs';
13
- import { flattenSchema, partialFieldsOf, schemaFieldsOf, encodeDocument, validateSchema, extractVectorFieldsFromSchema, requireCreatableSchema } from './chunk-O32RB3BL.mjs';
14
- import { MAX_FILE_BYTES, MAX_DOCUMENT_ENCODING_DEPTH } from './chunk-TJMSKBEM.mjs';
15
- import { parsedTypeOf, isSingleStringFieldType, isWordIndexedBase, MIN_PATTERN_VALUE_LIMIT, MAX_PATTERN_VALUE_LIMIT, PROTOTYPE_POLLUTION_KEYS, isPlainObject, MAX_NESTING_DEPTH, isStringValuedBase, withSortableOption, isGeopointOrVectorType, isWordIndexedFieldType, isListBase, VECTOR_PATTERN } from './chunk-OQQVRWZ2.mjs';
16
- import { resolveIndexAnalysis, getLanguage } from './chunk-ZBSWRSBG.mjs';
17
- import { singleFoldTable, appendFoldedCodePoint, toReducedSortValue, compareComparableValues, defaultSortMode, readSortField, truncateSortString, toComparableSortValue, SORT_VALUE_MAX_CODE_POINTS, compareComparableKeys, sortModeOf, isSortMode, SORT_MODES, compareSortValues } from './chunk-KWRW5U65.mjs';
18
- import { compareCodePoints, exceedsCodePoints, holdsUnpairedSurrogate, codePointCount } from './chunk-PPEPTUVV.mjs';
14
+ import { flattenSchema, partialFieldsOf, schemaFieldsOf, validateSchema, requireCreatableSchema, encodeDocument, extractVectorFieldsFromSchema } from './chunk-DNXOMPAQ.mjs';
15
+ import { MAX_DOCUMENT_ENCODING_DEPTH } from './chunk-6VBXNFLE.mjs';
16
+ import { parsedTypeOf, isSingleStringFieldType, isWordIndexedBase, MIN_PATTERN_VALUE_LIMIT, MAX_PATTERN_VALUE_LIMIT, PROTOTYPE_POLLUTION_KEYS, isPlainObject, isWordIndexedFieldType, isStringValuedBase, MAX_NESTING_DEPTH, withSortableOption, isGeopointOrVectorType, isListBase, VECTOR_PATTERN } from './chunk-C5G6TJ7A.mjs';
17
+ import { resolveIndexAnalysis, getLanguage } from './chunk-MJDQU5MW.mjs';
18
+ import { singleFoldTable, appendFoldedCodePoint, toReducedSortValue, compareComparableValues, defaultSortMode, readSortField, truncateSortString, toComparableSortValue, SORT_VALUE_MAX_CODE_POINTS, compareComparableKeys, sortModeOf, isSortMode, SORT_MODES, compareSortValues } from './chunk-3WI35N75.mjs';
19
+ import { compareCodePoints, holdsUnpairedSurrogate, exceedsCodePoints, codePointCount } from './chunk-EJ33LCHV.mjs';
20
+ import { highWord, SMALLEST_NORMAL_HIGH_WORD, MAGNITUDE_MASK, lowWord, INFINITE_HIGH_WORD, withHighWord } from './chunk-FHPW7P2O.mjs';
21
+ import { MAX_LATITUDE_DEGREES, MAX_LONGITUDE_DEGREES, MIN_POLYGON_POINTS } from './chunk-DXRSEWA2.mjs';
19
22
  import { bitsetHas, createBitSet, GrowableUint32, bitsetIsEmpty, bitsetSet, bitsetOrInto, bitsetAndNotInto, bitsetAndInto, bitsetFromSet } from './chunk-LVIKKAA6.mjs';
20
- import { DEFAULT_FUZZY_PREFIX_LENGTH, MAX_CURSOR_LENGTH, MAX_CURSOR_ANCHOR_CODE_POINTS, MAX_SORT_FIELDS, MAX_SORT_FIELD_NAME_LENGTH, BM25_DISPLAYED_NAME_LENGTH, RESULT_WINDOW, DEFAULT_LINEAR_ALPHA, MIN_LINEAR_ALPHA, MAX_LINEAR_ALPHA, DEFAULT_RANK_CONSTANT, MIN_RANK_CONSTANT, DEFAULT_PAGE_SIZE, DEFAULT_MAX_PER_GROUP, PREFIX_MAX_EXPANSIONS, MAX_TOLERANCE, MAX_PREFIX_LENGTH } from './chunk-AAAETEJK.mjs';
21
- import { TARGET_BLOCK_ENTRIES, SEGMENT_TOKEN_TABLE_START, SEGMENT_POSTING_LOG_START, SEGMENT_POSITION_POOL_START, SEGMENT_FIELD_SCRATCH_START, SCORE_BUFFER_INITIAL_TOUCHED_CAPACITY, PRUNING_REJECTION_SLACK, FROZEN_REMOVAL_INDEX_MAX_PROCESS_FRACTION, SORT_COLUMN_MINIMUM_REBUILD_THRESHOLD, SORT_COLUMN_REBUILD_FRACTION_SHIFT } from './chunk-JV6VQY2S.mjs';
22
- import { reactNativeHost } from './chunk-IOY2SM2P.mjs';
23
- import { ErrorCodes, NarsilError } from './chunk-CUNGPR5R.mjs';
23
+ import { BM25_DISPLAYED_NAME_LENGTH, DEFAULT_FUZZY_PREFIX_LENGTH, MAX_CURSOR_LENGTH, MAX_CURSOR_ANCHOR_CODE_POINTS, MAX_SORT_FIELDS, MAX_SORT_FIELD_NAME_LENGTH, RESULT_WINDOW, DEFAULT_LINEAR_ALPHA, MIN_LINEAR_ALPHA, MAX_LINEAR_ALPHA, DEFAULT_RANK_CONSTANT, MIN_RANK_CONSTANT, DEFAULT_PAGE_SIZE, DEFAULT_MAX_PER_GROUP, PREFIX_MAX_EXPANSIONS, MAX_TOLERANCE, MAX_PREFIX_LENGTH } from './chunk-AAAETEJK.mjs';
24
+ import { TARGET_BLOCK_ENTRIES, SEGMENT_TOKEN_TABLE_START, SEGMENT_POSTING_LOG_START, SEGMENT_POSITION_POOL_START, SEGMENT_FIELD_SCRATCH_START, SCORE_BUFFER_INITIAL_TOUCHED_CAPACITY, PRUNING_REJECTION_SLACK, FIELD_RUN_ENTRIES_START, FROZEN_REMOVAL_INDEX_MAX_PROCESS_FRACTION, SORT_COLUMN_MINIMUM_REBUILD_THRESHOLD, SORT_COLUMN_REBUILD_FRACTION_SHIFT } from './chunk-FTZHMRD2.mjs';
25
+ import { ErrorCodes, NarsilError } from './chunk-DZ7H7D2C.mjs';
24
26
  import { Decoder, decode, encode } from '@msgpack/msgpack';
25
27
 
26
28
  // src/core/partition/partial-words/platform.browser.ts
@@ -455,7 +457,7 @@ function createMemoryMonitor(options) {
455
457
  collectionCount++;
456
458
  return options.read() ?? figures;
457
459
  }
458
- function record(figures) {
460
+ function record2(figures) {
459
461
  const wasFull = latest?.full ?? false;
460
462
  let full = nextFullState(wasFull, figures, options.fractions);
461
463
  let settled2 = figures;
@@ -473,7 +475,7 @@ function createMemoryMonitor(options) {
473
475
  lastSampleAt = Date.now();
474
476
  const figures = options.read();
475
477
  if (figures !== null) {
476
- record(figures);
478
+ record2(figures);
477
479
  }
478
480
  }
479
481
  function latestFigures() {
@@ -487,7 +489,7 @@ function createMemoryMonitor(options) {
487
489
  lastSampleAt = Date.now();
488
490
  const figures = options.read();
489
491
  if (figures === null) return latestFigures();
490
- record(figuresWithoutGarbageBeforeRefusal(figures));
492
+ record2(figuresWithoutGarbageBeforeRefusal(figures));
491
493
  return latestFigures();
492
494
  },
493
495
  refusedAfterCollection(figures) {
@@ -942,7 +944,8 @@ var NARSIL_CONFIG_KEYS = {
942
944
  lifecycle: true,
943
945
  patternWorkCap: true,
944
946
  events: true,
945
- memory: true
947
+ memory: true,
948
+ querySuggestions: true
946
949
  };
947
950
  var EVENT_NAMES = {
948
951
  write: true,
@@ -956,7 +959,9 @@ var EVENT_NAMES = {
956
959
  layoutUpgrade: true,
957
960
  checkpointHeld: true,
958
961
  durabilityError: true,
959
- invalidationError: true
962
+ invalidationError: true,
963
+ querySuggestionsBuild: true,
964
+ querySuggestionsWarning: true
960
965
  };
961
966
  var DURABILITY_CONFIG_KEYS = {
962
967
  tier: true,
@@ -1313,6 +1318,11 @@ function validateRequiredFieldsInSchema(required, schema) {
1313
1318
  }
1314
1319
  }
1315
1320
 
1321
+ // src/core/document-copy.browser.ts
1322
+ function copyStoredValue(value) {
1323
+ return structuredClone(value);
1324
+ }
1325
+
1316
1326
  // src/core/projection.ts
1317
1327
  function requireFieldPathList(paths, option) {
1318
1328
  if (paths === void 0) return;
@@ -1363,9 +1373,9 @@ function readProjectedPath(source, path) {
1363
1373
  for (const segment of path) {
1364
1374
  if (typeof current !== "object" || current === null || Array.isArray(current))
1365
1375
  return { found: false, value: void 0 };
1366
- const record = current;
1367
- if (!Object.hasOwn(record, segment)) return { found: false, value: void 0 };
1368
- current = record[segment];
1376
+ const record2 = current;
1377
+ if (!Object.hasOwn(record2, segment)) return { found: false, value: void 0 };
1378
+ current = record2[segment];
1369
1379
  }
1370
1380
  return { found: true, value: current };
1371
1381
  }
@@ -1386,8 +1396,8 @@ function writePath(target, path, value) {
1386
1396
  }
1387
1397
  function cloneExcept(value, path, exclude) {
1388
1398
  const reachesDeeper = exclude.some((excluded) => excluded.length > path.length && covers(path, excluded));
1389
- if (!reachesDeeper) return structuredClone(value);
1390
- if (typeof value !== "object" || value === null || Array.isArray(value)) return structuredClone(value);
1399
+ if (!reachesDeeper) return copyStoredValue(value);
1400
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return copyStoredValue(value);
1391
1401
  const source = value;
1392
1402
  const kept = {};
1393
1403
  for (const key of Object.keys(source)) {
@@ -1426,7 +1436,7 @@ function projectionKeepsField(projection, fieldPath) {
1426
1436
  return !projection.exclude.some((excluded) => covers(excluded, path));
1427
1437
  }
1428
1438
  function cloneProjected(document, projection) {
1429
- if (projection === void 0 || projection.kind === "full") return structuredClone(document);
1439
+ if (projection === void 0 || projection.kind === "full") return copyStoredValue(document);
1430
1440
  if (projection.kind === "none") return {};
1431
1441
  if (projection.include === null) return cloneExcept(document, [], projection.exclude);
1432
1442
  return projectIncludedPaths(projection.include, projection.exclude, (path) => readProjectedPath(document, path));
@@ -1574,9 +1584,9 @@ function createDocumentStore() {
1574
1584
  for (const fieldName of Object.keys(fieldLengths)) {
1575
1585
  let column = lengthColumns.get(fieldName);
1576
1586
  if (column === void 0 || column.length <= internalId) {
1577
- const grown = new Uint32Array(Math.max(internalId + 1, (column?.length ?? 0) * 2, 64));
1578
- if (column !== void 0) grown.set(column);
1579
- column = grown;
1587
+ const grown2 = new Uint32Array(Math.max(internalId + 1, (column?.length ?? 0) * 2, 64));
1588
+ if (column !== void 0) grown2.set(column);
1589
+ column = grown2;
1580
1590
  lengthColumns.set(fieldName, column);
1581
1591
  }
1582
1592
  column[internalId] = fieldLengths[fieldName];
@@ -2007,9 +2017,9 @@ var PositionPool = class {
2007
2017
  reserve(needed) {
2008
2018
  if (needed <= this.values.length) return;
2009
2019
  const capacity = grownCapacity(this.values.length, needed);
2010
- const grown = new Uint32Array(capacity);
2011
- grown.set(this.values.subarray(0, this.end));
2012
- this.values = grown;
2020
+ const grown2 = new Uint32Array(capacity);
2021
+ grown2.set(this.values.subarray(0, this.end));
2022
+ this.values = grown2;
2013
2023
  }
2014
2024
  };
2015
2025
 
@@ -2051,9 +2061,9 @@ var PostingPool2 = class extends PostingPool {
2051
2061
  if (this.copy !== null || this.replaced) return;
2052
2062
  const capacity = this.docIds.length;
2053
2063
  if (this.end < capacity * POOL_GROWTH_START_FRACTION) return;
2054
- const grown = grownCapacity(capacity, this.end + 1);
2055
- if (grown <= capacity) return;
2056
- const copy = new PostingCopy(this, grown);
2064
+ const grown2 = grownCapacity(capacity, this.end + 1);
2065
+ if (grown2 <= capacity) return;
2066
+ const copy = new PostingCopy(this, grown2);
2057
2067
  this.copy = copy;
2058
2068
  void copyBetweenTurns(copy);
2059
2069
  }
@@ -2095,9 +2105,9 @@ var PositionPool2 = class extends PositionPool {
2095
2105
  if (this.copy !== null || this.replaced) return;
2096
2106
  const capacity = this.values.length;
2097
2107
  if (this.end < capacity * POOL_GROWTH_START_FRACTION) return;
2098
- const grown = grownCapacity(capacity, this.end + 1);
2099
- if (grown <= capacity) return;
2100
- const copy = new PositionCopy(this, grown);
2108
+ const grown2 = grownCapacity(capacity, this.end + 1);
2109
+ if (grown2 <= capacity) return;
2110
+ const copy = new PositionCopy(this, grown2);
2101
2111
  this.copy = copy;
2102
2112
  void copyBetweenTurns(copy);
2103
2113
  }
@@ -2469,7 +2479,7 @@ var LivePostings = class {
2469
2479
  terms = new TermColumns(TERM_TABLE_START_CAPACITY);
2470
2480
  pool = new PostingPool2(POSTING_POOL_START_ENTRIES);
2471
2481
  positions = new PositionPool2(POSITION_POOL_START_VALUES);
2472
- retired = new Uint8Array(RETIRED_DOCUMENTS_START_CAPACITY);
2482
+ retired = new Uint32Array(RETIRED_DOCUMENTS_START_CAPACITY >>> 5);
2473
2483
  batchMode = false;
2474
2484
  dirty = /* @__PURE__ */ new Set();
2475
2485
  cachedViews = /* @__PURE__ */ new Map();
@@ -2556,7 +2566,7 @@ var LivePostings = class {
2556
2566
  this.repackIfSparse();
2557
2567
  }
2558
2568
  isRetired(internalId) {
2559
- return internalId < this.retired.length && this.retired[internalId] === 1;
2569
+ return bitsetHas(this.retired, internalId);
2560
2570
  }
2561
2571
  beginBatch() {
2562
2572
  this.batchMode = true;
@@ -2580,7 +2590,7 @@ var LivePostings = class {
2580
2590
  this.pool = new PostingPool2(POSTING_POOL_START_ENTRIES);
2581
2591
  this.pool.epoch = epoch;
2582
2592
  this.positions = new PositionPool2(POSITION_POOL_START_VALUES);
2583
- this.retired = new Uint8Array(RETIRED_DOCUMENTS_START_CAPACITY);
2593
+ this.retired = new Uint32Array(RETIRED_DOCUMENTS_START_CAPACITY >>> 5);
2584
2594
  this.dirty.clear();
2585
2595
  this.cachedViews.clear();
2586
2596
  this.compactedSlack = 0;
@@ -2589,12 +2599,13 @@ var LivePostings = class {
2589
2599
  return this.terms.byteLength() + this.pool.byteLength() + this.positions.values.byteLength + this.retired.byteLength;
2590
2600
  }
2591
2601
  retire(internalId) {
2592
- if (internalId >= this.retired.length) {
2593
- const grown = new Uint8Array(Math.max(internalId + 1, this.retired.length * 2));
2594
- grown.set(this.retired);
2595
- this.retired = grown;
2602
+ const word = internalId >>> 5;
2603
+ if (word >= this.retired.length) {
2604
+ const grown2 = new Uint32Array(Math.max(word + 1, this.retired.length * 2));
2605
+ grown2.set(this.retired);
2606
+ this.retired = grown2;
2596
2607
  }
2597
- this.retired[internalId] = 1;
2608
+ bitsetSet(this.retired, internalId);
2598
2609
  }
2599
2610
  purgeRetired() {
2600
2611
  const terms = this.terms;
@@ -2606,7 +2617,7 @@ var LivePostings = class {
2606
2617
  compact(ordinal) {
2607
2618
  if (this.terms.deadDocuments[ordinal] === 0) return;
2608
2619
  const retired = this.retired;
2609
- this.filterEntries(ordinal, (id) => id < retired.length && retired[id] === 1);
2620
+ this.filterEntries(ordinal, (id) => bitsetHas(retired, id));
2610
2621
  this.terms.deadDocuments[ordinal] = 0;
2611
2622
  }
2612
2623
  filterEntries(ordinal, drop) {
@@ -2816,6 +2827,7 @@ function createInvertedIndex(fieldNameTable) {
2816
2827
  return entries;
2817
2828
  }
2818
2829
  return {
2830
+ livePostings: postings,
2819
2831
  insert(token, internalId, termFrequency, fieldNameIndex2, positions) {
2820
2832
  postings.insert(token, internalId, termFrequency, fieldNameIndex2, positions);
2821
2833
  },
@@ -3321,420 +3333,54 @@ function patternIndexOf(indexes, fieldPath) {
3321
3333
  return index;
3322
3334
  }
3323
3335
 
3324
- // src/geo/cells.ts
3325
- var AXIS_CELLS = 2 ** LOCATION_CODE_BITS_PER_AXIS;
3326
- function axisCell(value, lowest, span) {
3327
- const cell = Math.floor((value - lowest) / span * AXIS_CELLS);
3328
- if (!(cell > 0)) return 0;
3329
- return cell >= AXIS_CELLS ? AXIS_CELLS - 1 : cell;
3330
- }
3331
- function latitudeCell(lat) {
3332
- return axisCell(lat, -MAX_LATITUDE_DEGREES, 2 * MAX_LATITUDE_DEGREES);
3333
- }
3334
- function longitudeCell(lon) {
3335
- return axisCell(lon, -MAX_LONGITUDE_DEGREES, FULL_TURN_DEGREES);
3336
- }
3337
- function interleave(row, column, bits) {
3338
- let code = 0;
3339
- for (let bit = bits - 1; bit >= 0; bit--) code = code * 4 + (row >>> bit & 1) * 2 + (column >>> bit & 1);
3340
- return code;
3341
- }
3342
- function locationCode(lat, lon) {
3343
- return interleave(latitudeCell(lat), longitudeCell(lon), LOCATION_CODE_BITS_PER_AXIS);
3344
- }
3345
- function appendBoxRanges(box, out) {
3346
- const south = latitudeCell(box.south);
3347
- const north = latitudeCell(box.north);
3348
- const west = longitudeCell(box.west);
3349
- const east = longitudeCell(box.east);
3350
- let level = LOCATION_CODE_BITS_PER_AXIS;
3351
- while (level > 0) {
3352
- const shift2 = LOCATION_CODE_BITS_PER_AXIS - level;
3353
- const rows = (north >>> shift2) - (south >>> shift2) + 1;
3354
- const columns = (east >>> shift2) - (west >>> shift2) + 1;
3355
- if (rows * columns <= MAX_COVERING_CELLS) break;
3356
- level--;
3357
- }
3358
- const shift = LOCATION_CODE_BITS_PER_AXIS - level;
3359
- const codesPerCell = 4 ** shift;
3360
- for (let row = south >>> shift; row <= north >>> shift; row++) {
3361
- for (let column = west >>> shift; column <= east >>> shift; column++) {
3362
- const from = interleave(row, column, level) * codesPerCell;
3363
- out.push({ from, to: from + codesPerCell });
3364
- }
3365
- }
3366
- }
3367
- function coveringRanges(boxes) {
3368
- const ranges = [];
3369
- for (const box of boxes) appendBoxRanges(box, ranges);
3370
- ranges.sort((left, right) => left.from - right.from);
3371
- const merged = [];
3372
- for (const range of ranges) {
3373
- const last = merged[merged.length - 1];
3374
- if (last !== void 0 && range.from <= last.to) {
3375
- if (range.to > last.to) last.to = range.to;
3376
- } else {
3377
- merged.push({ from: range.from, to: range.to });
3378
- }
3336
+ // src/schema/declared-types.ts
3337
+ function mayDeclare(schema, typeName, depth) {
3338
+ if (!isPlainObject(schema) || depth > MAX_NESTING_DEPTH + 1) return false;
3339
+ for (const type of Object.values(schema)) {
3340
+ if (typeof type === "string" ? type.includes(typeName) : mayDeclare(type, typeName, depth + 1)) return true;
3379
3341
  }
3380
- return merged;
3342
+ return false;
3381
3343
  }
3382
- function longitudeBoxes(south, north, west, east) {
3383
- if (east - west >= FULL_TURN_DEGREES) {
3384
- return [{ south, north, west: -MAX_LONGITUDE_DEGREES, east: MAX_LONGITUDE_DEGREES }];
3385
- }
3386
- if (west < -MAX_LONGITUDE_DEGREES) {
3387
- return [
3388
- { south, north, west: west + FULL_TURN_DEGREES, east: MAX_LONGITUDE_DEGREES },
3389
- { south, north, west: -MAX_LONGITUDE_DEGREES, east }
3390
- ];
3391
- }
3392
- if (east > MAX_LONGITUDE_DEGREES) {
3393
- return [
3394
- { south, north, west, east: MAX_LONGITUDE_DEGREES },
3395
- { south, north, west: -MAX_LONGITUDE_DEGREES, east: east - FULL_TURN_DEGREES }
3396
- ];
3397
- }
3398
- return [{ south, north, west, east }];
3399
- }
3400
- function radiusBoxes(lat, lon, distanceMeters) {
3401
- const angle = distanceMeters / EARTH_RADIUS_METERS * RADIUS_BOX_MARGIN_RATIO + RADIUS_BOX_MARGIN_RADIANS;
3402
- const angleDegrees = angle / DEG_TO_RAD;
3403
- const south = lat - angleDegrees;
3404
- const north = lat + angleDegrees;
3405
- if (angle >= Math.PI || south <= -MAX_LATITUDE_DEGREES || north >= MAX_LATITUDE_DEGREES) {
3406
- return [
3407
- {
3408
- south: Math.max(south, -MAX_LATITUDE_DEGREES),
3409
- north: Math.min(north, MAX_LATITUDE_DEGREES),
3410
- west: -MAX_LONGITUDE_DEGREES,
3411
- east: MAX_LONGITUDE_DEGREES
3412
- }
3413
- ];
3414
- }
3415
- const spread = Math.asin(Math.sin(angle) / Math.cos(lat * DEG_TO_RAD)) / DEG_TO_RAD;
3416
- return longitudeBoxes(south, north, lon - spread, lon + spread);
3417
- }
3418
-
3419
- // src/geo/haversine.ts
3420
- function haversineDistance(lat1, lon1, lat2, lon2) {
3421
- const phi1 = lat1 * DEG_TO_RAD;
3422
- const phi2 = lat2 * DEG_TO_RAD;
3423
- const deltaPhi = (lat2 - lat1) * DEG_TO_RAD;
3424
- const deltaLambda = (lon2 - lon1) * DEG_TO_RAD;
3425
- const halfDeltaPhi = Math.sin(deltaPhi / 2);
3426
- const halfDeltaLambda = Math.sin(deltaLambda / 2);
3427
- const a = halfDeltaPhi * halfDeltaPhi + Math.cos(phi1) * Math.cos(phi2) * halfDeltaLambda * halfDeltaLambda;
3428
- const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
3429
- return EARTH_RADIUS_METERS * c;
3430
- }
3431
-
3432
- // src/geo/edge-tree.ts
3433
- function buildLongitudeEdgeTree(lons) {
3434
- const n = lons.length;
3435
- const edges = [];
3436
- for (let i = 0; i < n; i++) {
3437
- if (lons[i] !== lons[i === 0 ? n - 1 : i - 1]) edges.push(i);
3438
- }
3439
- const lowOf = (i) => Math.min(lons[i], lons[i === 0 ? n - 1 : i - 1]);
3440
- edges.sort((left, right) => lowOf(left) - lowOf(right));
3441
- const count = edges.length;
3442
- const tree = {
3443
- from: new Int32Array(count),
3444
- to: new Int32Array(count),
3445
- low: new Float64Array(count),
3446
- high: new Float64Array(count),
3447
- subtreeHigh: new Float64Array(count)
3448
- };
3449
- edges.forEach((i, at) => {
3450
- const j = i === 0 ? n - 1 : i - 1;
3451
- tree.from[at] = i;
3452
- tree.to[at] = j;
3453
- tree.low[at] = Math.min(lons[i], lons[j]);
3454
- tree.high[at] = Math.max(lons[i], lons[j]);
3455
- });
3456
- const fillSubtreeHigh = (start, end) => {
3457
- if (start >= end) return Number.NEGATIVE_INFINITY;
3458
- const mid = start + end >>> 1;
3459
- const highest = Math.max(tree.high[mid], fillSubtreeHigh(start, mid), fillSubtreeHigh(mid + 1, end));
3460
- tree.subtreeHigh[mid] = highest;
3461
- return highest;
3462
- };
3463
- fillSubtreeHigh(0, count);
3464
- return tree;
3465
- }
3466
- function forEachEdgeSpanning(tree, lon, visit) {
3467
- const walk = (start, end) => {
3468
- if (start >= end) return;
3469
- const mid = start + end >>> 1;
3470
- if (tree.subtreeHigh[mid] <= lon) return;
3471
- walk(start, mid);
3472
- if (tree.low[mid] > lon) return;
3473
- if (lon < tree.high[mid]) visit(tree.from[mid], tree.to[mid]);
3474
- walk(mid + 1, end);
3475
- };
3476
- walk(0, tree.from.length);
3344
+ function schemaMayDeclare(schema, typeName) {
3345
+ return mayDeclare(schema, typeName, 1);
3477
3346
  }
3478
3347
 
3479
- // src/geo/polygon.ts
3480
- function requirePolygonRing(points) {
3481
- if (!Array.isArray(points) || points.length < MIN_POLYGON_POINTS) {
3482
- throw new NarsilError(
3483
- ErrorCodes.SEARCH_INVALID_FILTER,
3484
- `A polygon encloses an area only with at least ${MIN_POLYGON_POINTS} points`,
3485
- { points: Array.isArray(points) ? points.length : typeof points, minimum: MIN_POLYGON_POINTS }
3486
- );
3487
- }
3488
- points.forEach((point, position) => {
3489
- const { lat, lon } = point ?? {};
3490
- if (typeof lat !== "number" || !Number.isFinite(lat) || typeof lon !== "number" || !Number.isFinite(lon)) {
3491
- throw new NarsilError(
3492
- ErrorCodes.SEARCH_INVALID_FILTER,
3493
- `A polygon point carries a finite "lat" and "lon", and the point at position ${position} does not`,
3494
- { position }
3348
+ // src/workers/code-loader.ts
3349
+ function codeLoader(importCode, typeName) {
3350
+ let loaded2 = null;
3351
+ let loading2 = null;
3352
+ function load() {
3353
+ if (loaded2 !== null) return Promise.resolve(loaded2);
3354
+ if (loading2 === null) {
3355
+ loading2 = importCode().then(
3356
+ (code) => {
3357
+ loaded2 = code;
3358
+ return code;
3359
+ },
3360
+ (err) => {
3361
+ loading2 = null;
3362
+ throw err;
3363
+ }
3495
3364
  );
3496
3365
  }
3497
- if (isLatitude(lat) && isLongitude(lon)) return;
3498
- throw new NarsilError(
3499
- ErrorCodes.SEARCH_INVALID_FILTER,
3500
- `A polygon point must hold a "lat" from -${MAX_LATITUDE_DEGREES} to ${MAX_LATITUDE_DEGREES} and a "lon" from -${MAX_LONGITUDE_DEGREES} to ${MAX_LONGITUDE_DEGREES}, while the point at position ${position} holds ${lat}, ${lon}`,
3501
- { position, lat, lon }
3502
- );
3503
- });
3504
- }
3505
- function signedArea(polygon) {
3506
- let area = 0;
3507
- for (let i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {
3508
- area += polygon[j].lon * polygon[i].lat - polygon[i].lon * polygon[j].lat;
3509
- }
3510
- return area;
3511
- }
3512
- function crossesAntimeridian(polygon) {
3513
- let west = Number.POSITIVE_INFINITY;
3514
- let east = Number.NEGATIVE_INFINITY;
3515
- for (const point of polygon) {
3516
- if (point.lon < west) west = point.lon;
3517
- if (point.lon > east) east = point.lon;
3518
- }
3519
- return east - west >= ANTIMERIDIAN_SPAN_DEGREES && signedArea(polygon) < 0;
3520
- }
3521
- function eastward(lon) {
3522
- return lon < 0 ? lon + FULL_TURN_DEGREES : lon;
3523
- }
3524
- function polygonContainment(polygon) {
3525
- const n = polygon.length;
3526
- if (n < MIN_POLYGON_POINTS) return () => false;
3527
- const unwrap = crossesAntimeridian(polygon);
3528
- const lats = new Float64Array(n);
3529
- const lons = new Float64Array(n);
3530
- for (let i = 0; i < n; i++) {
3531
- lats[i] = polygon[i].lat;
3532
- lons[i] = unwrap ? eastward(polygon[i].lon) : polygon[i].lon;
3533
- }
3534
- const edges = buildLongitudeEdgeTree(lons);
3535
- return (lat, rawLon) => {
3536
- const lon = unwrap ? eastward(rawLon) : rawLon;
3537
- let inside = false;
3538
- forEachEdgeSpanning(edges, lon, (i, j) => {
3539
- const intersectLat = lats[i] + (lats[j] - lats[i]) / (lons[j] - lons[i]) * (lon - lons[i]);
3540
- if (lat < intersectLat) inside = !inside;
3541
- });
3542
- return inside;
3543
- };
3544
- }
3545
- function polygonBoxes(polygon) {
3546
- if (polygon.length < MIN_POLYGON_POINTS) return [];
3547
- const unwrap = crossesAntimeridian(polygon);
3548
- let south = Number.POSITIVE_INFINITY;
3549
- let north = Number.NEGATIVE_INFINITY;
3550
- let west = Number.POSITIVE_INFINITY;
3551
- let east = Number.NEGATIVE_INFINITY;
3552
- for (const point of polygon) {
3553
- const lon = unwrap ? eastward(point.lon) : point.lon;
3554
- south = Math.min(south, point.lat);
3555
- north = Math.max(north, point.lat);
3556
- west = Math.min(west, lon);
3557
- east = Math.max(east, lon);
3558
- }
3559
- if (west >= MAX_LONGITUDE_DEGREES)
3560
- return longitudeBoxes(south, north, west - FULL_TURN_DEGREES, east - FULL_TURN_DEGREES);
3561
- return longitudeBoxes(south, north, west, east);
3562
- }
3563
-
3564
- // src/geo/vincenty.ts
3565
- var WGS84_A = 6378137;
3566
- var WGS84_F = 1 / 298.257223563;
3567
- var WGS84_B = WGS84_A * (1 - WGS84_F);
3568
- function vincentyDistance(lat1, lon1, lat2, lon2) {
3569
- const phi1 = lat1 * DEG_TO_RAD;
3570
- const phi2 = lat2 * DEG_TO_RAD;
3571
- const L = (lon2 - lon1) * DEG_TO_RAD;
3572
- const U1 = Math.atan((1 - WGS84_F) * Math.tan(phi1));
3573
- const U2 = Math.atan((1 - WGS84_F) * Math.tan(phi2));
3574
- const sinU1 = Math.sin(U1);
3575
- const cosU1 = Math.cos(U1);
3576
- const sinU2 = Math.sin(U2);
3577
- const cosU2 = Math.cos(U2);
3578
- let lambda = L;
3579
- let prevLambda;
3580
- let sinSigma = 0;
3581
- let cosSigma = 0;
3582
- let sigma = 0;
3583
- let sinAlpha = 0;
3584
- let cos2Alpha = 0;
3585
- let cos2SigmaM = 0;
3586
- let iterations = VINCENTY_MAX_ITERATIONS;
3587
- do {
3588
- const sinLambda = Math.sin(lambda);
3589
- const cosLambda = Math.cos(lambda);
3590
- const term1 = cosU2 * sinLambda;
3591
- const term2 = cosU1 * sinU2 - sinU1 * cosU2 * cosLambda;
3592
- sinSigma = Math.sqrt(term1 * term1 + term2 * term2);
3593
- if (sinSigma === 0) return 0;
3594
- cosSigma = sinU1 * sinU2 + cosU1 * cosU2 * cosLambda;
3595
- sigma = Math.atan2(sinSigma, cosSigma);
3596
- sinAlpha = cosU1 * cosU2 * sinLambda / sinSigma;
3597
- cos2Alpha = 1 - sinAlpha * sinAlpha;
3598
- cos2SigmaM = cos2Alpha === 0 ? 0 : cosSigma - 2 * sinU1 * sinU2 / cos2Alpha;
3599
- const C = WGS84_F / 16 * cos2Alpha * (4 + WGS84_F * (4 - 3 * cos2Alpha));
3600
- prevLambda = lambda;
3601
- lambda = L + (1 - C) * WGS84_F * sinAlpha * (sigma + C * sinSigma * (cos2SigmaM + C * cosSigma * (-1 + 2 * cos2SigmaM * cos2SigmaM)));
3602
- } while (Math.abs(lambda - prevLambda) > VINCENTY_CONVERGENCE_THRESHOLD && --iterations > 0);
3603
- if (iterations === 0) {
3604
- return haversineDistance(lat1, lon1, lat2, lon2);
3605
- }
3606
- const uSq = cos2Alpha * (WGS84_A * WGS84_A - WGS84_B * WGS84_B) / (WGS84_B * WGS84_B);
3607
- const A = 1 + uSq / 16384 * (4096 + uSq * (-768 + uSq * (320 - 175 * uSq)));
3608
- const B = uSq / 1024 * (256 + uSq * (-128 + uSq * (74 - 47 * uSq)));
3609
- const deltaSigma = B * sinSigma * (cos2SigmaM + B / 4 * (cosSigma * (-1 + 2 * cos2SigmaM * cos2SigmaM) - B / 6 * cos2SigmaM * (-3 + 4 * sinSigma * sinSigma) * (-3 + 4 * cos2SigmaM * cos2SigmaM)));
3610
- return WGS84_B * A * (sigma - deltaSigma);
3611
- }
3612
-
3613
- // src/geo/geo-index.ts
3614
- var REMOVED_DOC_ID = -1;
3615
- function firstAtOrAfter(entries, code) {
3616
- let lo = 0;
3617
- let hi = entries.length;
3618
- while (lo < hi) {
3619
- const mid = lo + hi >>> 1;
3620
- if (entries[mid].code < code) lo = mid + 1;
3621
- else hi = mid;
3622
- }
3623
- return lo;
3624
- }
3625
- function dropRemoved(entries) {
3626
- let write = 0;
3627
- for (let read = 0; read < entries.length; read++) {
3628
- if (entries[read].docId !== REMOVED_DOC_ID) entries[write++] = entries[read];
3366
+ return loading2;
3629
3367
  }
3630
- entries.length = write;
3631
- }
3632
- function mergeSortedPending(entries, pending) {
3633
- pending.sort((left2, right2) => left2.code - right2.code || left2.docId - right2.docId);
3634
- const mainLength = entries.length;
3635
- for (const entry of pending) entries.push(entry);
3636
- let left = mainLength - 1;
3637
- let right = pending.length - 1;
3638
- let write = entries.length - 1;
3639
- while (right >= 0) {
3640
- const later = left >= 0 ? entries[left] : void 0;
3641
- const next = pending[right];
3642
- if (later !== void 0 && (later.code > next.code || later.code === next.code && later.docId > next.docId)) {
3643
- entries[write--] = later;
3644
- left--;
3645
- } else {
3646
- entries[write--] = next;
3647
- right--;
3648
- }
3649
- }
3650
- }
3651
- function createGeoIndex() {
3652
- let entries = [];
3653
- let pending = [];
3654
- const byDocument = /* @__PURE__ */ new Map();
3655
- let removedCount = 0;
3656
- function ensureSorted() {
3657
- if (removedCount > 0) {
3658
- dropRemoved(entries);
3659
- dropRemoved(pending);
3660
- removedCount = 0;
3661
- }
3662
- if (pending.length === 0) return;
3663
- if (entries.length === 0) {
3664
- pending.sort((left, right) => left.code - right.code || left.docId - right.docId);
3665
- entries = pending;
3666
- } else {
3667
- mergeSortedPending(entries, pending);
3668
- }
3669
- pending = [];
3670
- }
3671
- function removeEntry(entry) {
3672
- byDocument.delete(entry.docId);
3673
- entry.docId = REMOVED_DOC_ID;
3674
- removedCount++;
3675
- const held = entries.length + pending.length;
3676
- if (removedCount >= Math.max(PENDING_REMOVAL_MERGE_FLOOR, held / PENDING_REMOVAL_MERGE_DIVISOR)) ensureSorted();
3677
- }
3678
- function matching(boxes, passes, inside) {
3679
- ensureSorted();
3680
- const within = /* @__PURE__ */ new Set();
3681
- for (const range of coveringRanges(boxes)) {
3682
- for (let at = firstAtOrAfter(entries, range.from); at < entries.length && entries[at].code < range.to; at++) {
3683
- if (passes(entries[at])) within.add(entries[at].docId);
3684
- }
3685
- }
3686
- if (inside) return within;
3687
- const outside = /* @__PURE__ */ new Set();
3688
- for (const entry of entries) {
3689
- if (!within.has(entry.docId)) outside.add(entry.docId);
3690
- }
3691
- return outside;
3692
- }
3693
- const index = {
3694
- insert(internalId, lat, lon) {
3695
- const existing = byDocument.get(internalId);
3696
- if (existing !== void 0) removeEntry(existing);
3697
- const entry = { lat, lon, docId: internalId, code: locationCode(lat, lon) };
3698
- pending.push(entry);
3699
- byDocument.set(internalId, entry);
3700
- },
3701
- remove(internalId) {
3702
- const existing = byDocument.get(internalId);
3703
- if (existing !== void 0) removeEntry(existing);
3704
- },
3705
- radiusQuery(lat, lon, distanceMeters, inside, highPrecision) {
3706
- const distanceFn = highPrecision ? vincentyDistance : haversineDistance;
3707
- return matching(
3708
- radiusBoxes(lat, lon, distanceMeters),
3709
- (entry) => distanceFn(lat, lon, entry.lat, entry.lon) <= distanceMeters,
3710
- inside
3711
- );
3712
- },
3713
- polygonQuery(points, inside) {
3714
- const contains = polygonContainment(points);
3715
- return matching(polygonBoxes(points), (entry) => contains(entry.lat, entry.lon), inside);
3716
- },
3717
- documentsBitset(capacity) {
3718
- const bits = createBitSet(capacity);
3719
- for (const docId of byDocument.keys()) bitsetSet(bits, docId);
3720
- return bits;
3721
- },
3722
- clear() {
3723
- entries = [];
3724
- pending = [];
3725
- byDocument.clear();
3726
- removedCount = 0;
3727
- },
3728
- serialize() {
3729
- ensureSorted();
3730
- return entries.map((entry) => ({ lat: entry.lat, lon: entry.lon, docId: entry.docId }));
3368
+ return {
3369
+ loaded: () => loaded2,
3370
+ require() {
3371
+ if (loaded2 === null) throw new Error(`The engine reached ${typeName} code before it loaded that code`);
3372
+ return loaded2;
3731
3373
  },
3732
- deserialize(data) {
3733
- index.clear();
3734
- for (const entry of data) index.insert(entry.docId, entry.lat, entry.lon);
3735
- }
3374
+ load,
3375
+ loadFor: (schema) => loaded2 !== null || !schemaMayDeclare(schema, typeName) ? null : load()
3736
3376
  };
3737
- return index;
3377
+ }
3378
+
3379
+ // src/geo/geo-code.ts
3380
+ var geoCode = codeLoader(() => import('./geo-index-PX3BIHAH.mjs'), "geopoint");
3381
+ var loadGeoCodeFor = geoCode.loadFor;
3382
+ function createLoadedGeoIndex() {
3383
+ return geoCode.require().createGeoIndex(PENDING_REMOVAL_MERGE_FLOOR, PENDING_REMOVAL_MERGE_DIVISOR);
3738
3384
  }
3739
3385
 
3740
3386
  // src/core/field-index/boolean.ts
@@ -3818,7 +3464,7 @@ function reversedUnits(value) {
3818
3464
  for (let at = value.length - 1; at >= 0; at--) reversed += value[at];
3819
3465
  return reversed;
3820
3466
  }
3821
- function firstAtOrAfter2(sorted, key) {
3467
+ function firstAtOrAfter(sorted, key) {
3822
3468
  let lo = 0;
3823
3469
  let hi = sorted.length;
3824
3470
  while (lo < hi) {
@@ -3828,10 +3474,10 @@ function firstAtOrAfter2(sorted, key) {
3828
3474
  }
3829
3475
  return lo;
3830
3476
  }
3831
- function settledColumn(column, holds) {
3477
+ function settledColumn(column, holds2) {
3832
3478
  const { keys, values } = column;
3833
3479
  const order = [];
3834
- for (let at = 0; at < keys.length; at++) if (holds(values[at])) order.push(at);
3480
+ for (let at = 0; at < keys.length; at++) if (holds2(values[at])) order.push(at);
3835
3481
  order.sort((left, right) => compareUnits(keys[left], keys[right]) || compareUnits(values[left], values[right]));
3836
3482
  const settled2 = { keys: [], values: [] };
3837
3483
  for (const at of order) {
@@ -3843,8 +3489,8 @@ function settledColumn(column, holds) {
3843
3489
  return settled2;
3844
3490
  }
3845
3491
  var ValueAffixes = class {
3846
- constructor(holds, values) {
3847
- this.holds = holds;
3492
+ constructor(holds2, values) {
3493
+ this.holds = holds2;
3848
3494
  for (const value of values) this.add(value);
3849
3495
  }
3850
3496
  forward = { keys: [], values: [] };
@@ -3876,7 +3522,7 @@ var ValueAffixes = class {
3876
3522
  }
3877
3523
  matching(column, start) {
3878
3524
  const found = [];
3879
- for (let at = firstAtOrAfter2(column.keys, start); at < column.keys.length; at++) {
3525
+ for (let at = firstAtOrAfter(column.keys, start); at < column.keys.length; at++) {
3880
3526
  if (!column.keys[at].startsWith(start)) break;
3881
3527
  found.push(column.values[at]);
3882
3528
  }
@@ -4114,7 +3760,7 @@ function removeFromPending(pending, marked, byDocument) {
4114
3760
  }
4115
3761
  pending.length = write;
4116
3762
  }
4117
- function mergeSortedPending2(entries, pending) {
3763
+ function mergeSortedPending(entries, pending) {
4118
3764
  pending.sort((a, b) => a.value - b.value);
4119
3765
  const mainLength = entries.length;
4120
3766
  for (const entry of pending) entries.push(entry);
@@ -4150,7 +3796,7 @@ function createNumericIndex() {
4150
3796
  pending.sort((a, b) => a.value - b.value);
4151
3797
  entries = pending;
4152
3798
  } else {
4153
- mergeSortedPending2(entries, pending);
3799
+ mergeSortedPending(entries, pending);
4154
3800
  }
4155
3801
  pending = [];
4156
3802
  }
@@ -4338,7 +3984,7 @@ function ensureFieldIndex(state, fieldPath, base) {
4338
3984
  } else if ((base === "enum" || base === "enum[]") && !state.enumIndexes.has(fieldPath)) {
4339
3985
  state.enumIndexes.set(fieldPath, createEnumIndex());
4340
3986
  } else if (base === "geopoint" && !state.geoIndexes.has(fieldPath)) {
4341
- state.geoIndexes.set(fieldPath, createGeoIndex());
3987
+ state.geoIndexes.set(fieldPath, createLoadedGeoIndex());
4342
3988
  }
4343
3989
  }
4344
3990
  function getOrCreateNumericIndex(state, fieldPath) {
@@ -4921,6 +4567,33 @@ var FIELD_FILTER_OPERATORS = [
4921
4567
  "polygon"
4922
4568
  ];
4923
4569
 
4570
+ // src/geo/polygon-ring.ts
4571
+ function requirePolygonRing(points) {
4572
+ if (!Array.isArray(points) || points.length < MIN_POLYGON_POINTS) {
4573
+ throw new NarsilError(
4574
+ ErrorCodes.SEARCH_INVALID_FILTER,
4575
+ `A polygon encloses an area only with at least ${MIN_POLYGON_POINTS} points`,
4576
+ { points: Array.isArray(points) ? points.length : typeof points, minimum: MIN_POLYGON_POINTS }
4577
+ );
4578
+ }
4579
+ points.forEach((point, position) => {
4580
+ const { lat, lon } = point ?? {};
4581
+ if (typeof lat !== "number" || !Number.isFinite(lat) || typeof lon !== "number" || !Number.isFinite(lon)) {
4582
+ throw new NarsilError(
4583
+ ErrorCodes.SEARCH_INVALID_FILTER,
4584
+ `A polygon point carries a finite "lat" and "lon", and the point at position ${position} does not`,
4585
+ { position }
4586
+ );
4587
+ }
4588
+ if (isLatitude(lat) && isLongitude(lon)) return;
4589
+ throw new NarsilError(
4590
+ ErrorCodes.SEARCH_INVALID_FILTER,
4591
+ `A polygon point must hold a "lat" from -${MAX_LATITUDE_DEGREES} to ${MAX_LATITUDE_DEGREES} and a "lon" from -${MAX_LONGITUDE_DEGREES} to ${MAX_LONGITUDE_DEGREES}, while the point at position ${position} holds ${lat}, ${lon}`,
4592
+ { position, lat, lon }
4593
+ );
4594
+ });
4595
+ }
4596
+
4924
4597
  // src/filters/operands/geo.ts
4925
4598
  function requireFlag(fieldPath, operator, flag, value) {
4926
4599
  if (value === void 0 || typeof value === "boolean") return;
@@ -5284,11 +4957,11 @@ function noteUnknownExpressionKey(expression, walk) {
5284
4957
  return;
5285
4958
  }
5286
4959
  }
5287
- function setOwn(record, key, value) {
4960
+ function setOwn(record2, key, value) {
5288
4961
  if (key === PROTOTYPE_KEY) {
5289
- Object.defineProperty(record, key, { value, enumerable: true, writable: true, configurable: true });
4962
+ Object.defineProperty(record2, key, { value, enumerable: true, writable: true, configurable: true });
5290
4963
  } else {
5291
- record[key] = value;
4964
+ record2[key] = value;
5292
4965
  }
5293
4966
  }
5294
4967
  function ownedOperandOf(value, fieldPath, operator, depth) {
@@ -5299,9 +4972,9 @@ function ownedOperandOf(value, fieldPath, operator, depth) {
5299
4972
  for (let at = 0; at < value.length; at++) owned2.push(ownedOperandOf(value[at], fieldPath, operator, depth + 1));
5300
4973
  return owned2;
5301
4974
  }
5302
- const record = value;
4975
+ const record2 = value;
5303
4976
  const owned = {};
5304
- for (const key of Object.keys(record)) setOwn(owned, key, ownedOperandOf(record[key], fieldPath, operator, depth + 1));
4977
+ for (const key of Object.keys(record2)) setOwn(owned, key, ownedOperandOf(record2[key], fieldPath, operator, depth + 1));
5305
4978
  return owned;
5306
4979
  }
5307
4980
  function ownedFieldFilterOf(fieldPath, filter) {
@@ -5529,20 +5202,20 @@ function createValueStore(initialKind) {
5529
5202
  function setNumber(internalId, value) {
5530
5203
  if (numbers === null) return;
5531
5204
  if (internalId >= numbers.length) {
5532
- const grown = new Float64Array(grow2(numbers.length, internalId));
5533
- grown.fill(Number.NaN, numbers.length);
5534
- grown.set(numbers);
5535
- numbers = grown;
5205
+ const grown2 = new Float64Array(grow2(numbers.length, internalId));
5206
+ grown2.fill(Number.NaN, numbers.length);
5207
+ grown2.set(numbers);
5208
+ numbers = grown2;
5536
5209
  }
5537
5210
  numbers[internalId] = value;
5538
5211
  }
5539
5212
  function setBoolean(internalId, value) {
5540
5213
  if (booleans === null) return;
5541
5214
  if (internalId >= booleans.length) {
5542
- const grown = new Uint8Array(grow2(booleans.length, internalId));
5543
- grown.fill(BOOLEAN_MISSING, booleans.length);
5544
- grown.set(booleans);
5545
- booleans = grown;
5215
+ const grown2 = new Uint8Array(grow2(booleans.length, internalId));
5216
+ grown2.fill(BOOLEAN_MISSING, booleans.length);
5217
+ grown2.set(booleans);
5218
+ booleans = grown2;
5546
5219
  }
5547
5220
  booleans[internalId] = value;
5548
5221
  }
@@ -5637,7 +5310,7 @@ function liveInternalIds(docStore) {
5637
5310
  return ids;
5638
5311
  }
5639
5312
  function createSortColumnSet(docStore) {
5640
- const columns = /* @__PURE__ */ new Map();
5313
+ const columns2 = /* @__PURE__ */ new Map();
5641
5314
  function rebuildThreshold() {
5642
5315
  const count = docStore.count();
5643
5316
  const fraction = count >> SORT_COLUMN_REBUILD_FRACTION_SHIFT;
@@ -5662,7 +5335,7 @@ function createSortColumnSet(docStore) {
5662
5335
  dirty: /* @__PURE__ */ new Set(),
5663
5336
  dirtyStream: null
5664
5337
  };
5665
- columns.set(key, entry);
5338
+ columns2.set(key, entry);
5666
5339
  return entry;
5667
5340
  }
5668
5341
  function buildDirtyStream(entry) {
@@ -5716,11 +5389,11 @@ function createSortColumnSet(docStore) {
5716
5389
  }
5717
5390
  return {
5718
5391
  holds(field, fieldType, mode) {
5719
- return columns.has(columnKeyOf(field, fieldType, mode));
5392
+ return columns2.has(columnKeyOf(field, fieldType, mode));
5720
5393
  },
5721
5394
  column(field, fieldType, mode) {
5722
5395
  const key = columnKeyOf(field, fieldType, mode);
5723
- let entry = columns.get(key);
5396
+ let entry = columns2.get(key);
5724
5397
  if (entry === void 0) {
5725
5398
  entry = backfill(key, field, fieldType, mode);
5726
5399
  } else if (entry.dirty.size > rebuildThreshold()) {
@@ -5729,14 +5402,14 @@ function createSortColumnSet(docStore) {
5729
5402
  return viewOf(entry);
5730
5403
  },
5731
5404
  record(internalId, document) {
5732
- for (const entry of columns.values()) {
5405
+ for (const entry of columns2.values()) {
5733
5406
  entry.store.set(internalId, toReducedSortValue(readSortField(document, entry.field), entry.mode));
5734
5407
  entry.dirty.add(internalId);
5735
5408
  entry.dirtyStream = null;
5736
5409
  }
5737
5410
  },
5738
5411
  forget(internalId) {
5739
- for (const entry of columns.values()) {
5412
+ for (const entry of columns2.values()) {
5740
5413
  entry.store.clear(internalId);
5741
5414
  entry.dirty.delete(internalId);
5742
5415
  entry.dirtyStream = null;
@@ -5744,16 +5417,16 @@ function createSortColumnSet(docStore) {
5744
5417
  },
5745
5418
  refresh() {
5746
5419
  const threshold = rebuildThreshold();
5747
- for (const entry of columns.values()) {
5420
+ for (const entry of columns2.values()) {
5748
5421
  if (entry.dirty.size > threshold) rebuild(entry);
5749
5422
  }
5750
5423
  },
5751
5424
  fieldCount() {
5752
- return columns.size;
5425
+ return columns2.size;
5753
5426
  },
5754
5427
  estimateBytes() {
5755
5428
  let bytes = 0;
5756
- for (const entry of columns.values()) {
5429
+ for (const entry of columns2.values()) {
5757
5430
  bytes += entry.store.estimateBytes() + estimateOrderBytes(entry.order);
5758
5431
  }
5759
5432
  return bytes;
@@ -5822,26 +5495,26 @@ function compareColumnValue(column, aId, bId, direction) {
5822
5495
  if (!rankIsBetweenValues(aRank)) return 0;
5823
5496
  return compareComparableValues(column.valueOf(aId), column.valueOf(bId), direction);
5824
5497
  }
5825
- function compareCandidates(columns, directions, a, b) {
5826
- for (let i = 0; i < columns.length; i++) {
5827
- const comparison = compareColumnValue(columns[i], a.internalId, b.internalId, directions[i]);
5498
+ function compareCandidates(columns2, directions, a, b) {
5499
+ for (let i = 0; i < columns2.length; i++) {
5500
+ const comparison = compareColumnValue(columns2[i], a.internalId, b.internalId, directions[i]);
5828
5501
  if (comparison !== 0) return comparison;
5829
5502
  }
5830
5503
  return compareCodePoints(a.externalId, b.externalId);
5831
5504
  }
5832
- function compareWithAnchor(columns, directions, candidate, anchorKey, anchorId) {
5833
- for (let i = 0; i < columns.length; i++) {
5505
+ function compareWithAnchor(columns2, directions, candidate, anchorKey, anchorId) {
5506
+ for (let i = 0; i < columns2.length; i++) {
5834
5507
  const comparison = compareComparableValues(candidate.key[i], anchorKey[i] ?? null, directions[i]);
5835
5508
  if (comparison !== 0) return comparison;
5836
5509
  }
5837
5510
  return compareCodePoints(candidate.externalId, anchorId);
5838
5511
  }
5839
- function insertOrdered(page, entry, columns, directions) {
5512
+ function insertOrdered(page, entry, columns2, directions) {
5840
5513
  let low = 0;
5841
5514
  let high = page.length;
5842
5515
  while (low < high) {
5843
5516
  const mid = low + high >>> 1;
5844
- if (compareCandidates(columns, directions, page[mid], entry) <= 0) low = mid + 1;
5517
+ if (compareCandidates(columns2, directions, page[mid], entry) <= 0) low = mid + 1;
5845
5518
  else high = mid;
5846
5519
  }
5847
5520
  page.splice(low, 0, entry);
@@ -5931,11 +5604,11 @@ function selectSortedPage(state, request) {
5931
5604
  if (limit <= 0 || fields.length === 0) return [];
5932
5605
  const set = state.sortColumns;
5933
5606
  if (set === null) return [];
5934
- const columns = fields.map(
5607
+ const columns2 = fields.map(
5935
5608
  (field, index) => set.column(field, fieldTypes[index], modes[index] ?? defaultSortMode(directions[index] ?? "asc"))
5936
5609
  );
5937
5610
  const resolver = state.docStore.resolver();
5938
- const leading = columns[0];
5611
+ const leading = columns2[0];
5939
5612
  const leadingDirection = directions[0];
5940
5613
  const anchorRank = anchorKey === null || anchorId === null ? null : rankOfValue(leading.order, anchorKey[0] ?? null);
5941
5614
  const next = createStream(leading, leadingDirection, anchorRank);
@@ -5950,17 +5623,17 @@ function selectSortedPage(state, request) {
5950
5623
  if (page.length === limit && rankOrdersAfter(leadingRank, page[limit - 1].leadingRank, leadingDirection)) {
5951
5624
  break;
5952
5625
  }
5953
- const key = new Array(columns.length);
5954
- for (let i = 0; i < columns.length; i++) key[i] = columns[i].valueOf(internalId);
5626
+ const key = new Array(columns2.length);
5627
+ for (let i = 0; i < columns2.length; i++) key[i] = columns2[i].valueOf(internalId);
5955
5628
  const candidate = { internalId, externalId, leadingRank, key };
5956
5629
  if (anchorKey !== null && anchorId !== null) {
5957
- if (compareWithAnchor(columns, directions, candidate, anchorKey, anchorId) <= 0) continue;
5630
+ if (compareWithAnchor(columns2, directions, candidate, anchorKey, anchorId) <= 0) continue;
5958
5631
  }
5959
5632
  if (page.length === limit) {
5960
- if (compareCandidates(columns, directions, candidate, page[limit - 1]) >= 0) continue;
5633
+ if (compareCandidates(columns2, directions, candidate, page[limit - 1]) >= 0) continue;
5961
5634
  page.pop();
5962
5635
  }
5963
- insertOrdered(page, candidate, columns, directions);
5636
+ insertOrdered(page, candidate, columns2, directions);
5964
5637
  }
5965
5638
  return page.map((entry) => ({ id: entry.externalId, key: entry.key }));
5966
5639
  }
@@ -6043,17 +5716,21 @@ function presentBitsetOf(state, fieldPath, type, capacity) {
6043
5716
  if (base === "number") present = state.numericIndexes.get(fieldPath)?.getAllDocIdsBitset(capacity);
6044
5717
  else if (base === "boolean") present = state.booleanIndexes.get(fieldPath)?.getAllDocIdsBitset(capacity);
6045
5718
  else if (base === "enum") present = state.enumIndexes.get(fieldPath)?.getAllDocIdsBitset(capacity);
6046
- else if (base === "geopoint") present = state.geoIndexes.get(fieldPath)?.documentsBitset(capacity);
5719
+ else if (base === "geopoint") present = geoDocumentsBitset(state, fieldPath, capacity);
6047
5720
  else if (base !== void 0 && keepsValueSize(base)) {
6048
5721
  present = state.sizeIndexes.get(fieldPath)?.getAllDocIdsBitset(capacity);
6049
5722
  }
6050
5723
  return present ?? createBitSet(capacity);
6051
5724
  }
6052
- function liveDocumentsBitset(state, capacity) {
5725
+ function bitsetOfDocuments(internalIds, capacity) {
6053
5726
  const bits = createBitSet(capacity);
6054
- for (const internalId of state.docStore.allInternalIds()) bitsetSet(bits, internalId);
5727
+ for (const internalId of internalIds) bitsetSet(bits, internalId);
6055
5728
  return bits;
6056
5729
  }
5730
+ function geoDocumentsBitset(state, fieldPath, capacity) {
5731
+ const geoIndex = state.geoIndexes.get(fieldPath);
5732
+ return geoIndex === void 0 ? void 0 : bitsetOfDocuments(geoIndex.documentIds(), capacity);
5733
+ }
6057
5734
  function buildFilterContext(state, schema, meter) {
6058
5735
  const flat = getFlatSchema(state, schema);
6059
5736
  const capacity = state.docStore.internalIdCapacity();
@@ -6105,7 +5782,7 @@ function buildFilterContext(state, schema, meter) {
6105
5782
  },
6106
5783
  capacity,
6107
5784
  get allDocIdsBitset() {
6108
- cachedAllDocIdsBitset ??= liveDocumentsBitset(state, capacity);
5785
+ cachedAllDocIdsBitset ??= bitsetOfDocuments(state.docStore.allInternalIds(), capacity);
6109
5786
  return cachedAllDocIdsBitset;
6110
5787
  }
6111
5788
  };
@@ -6179,7 +5856,7 @@ function requireLoadedPhraseCode() {
6179
5856
  }
6180
5857
  function loadPhraseCode() {
6181
5858
  if (loading === null) {
6182
- loading = import('./phrase-module-JZ37TB7N.mjs').then(
5859
+ loading = import('./phrase-module-QK22HSQ2.mjs').then(
6183
5860
  (code) => {
6184
5861
  loaded = code;
6185
5862
  return code;
@@ -6213,10 +5890,82 @@ function analyseQueryPhrases(term, language, analysis) {
6213
5890
  );
6214
5891
  }
6215
5892
 
5893
+ // src/math/log.ts
5894
+ var EXPONENT_BIAS = 1023;
5895
+ var EXPONENT_SHIFT = 20;
5896
+ var SUBNORMAL_SCALE_EXPONENT = 54;
5897
+ var ROUNDING_OFFSET = 614244;
5898
+ var HALVING_BIT = 1048576;
5899
+ var ONE_HIGH_WORD = 1072693248;
5900
+ var SIGNIFICAND_MASK = 1048575;
5901
+ var NEAR_ONE_LIMIT = 3;
5902
+ var LOWER_SPLIT = 398458;
5903
+ var UPPER_SPLIT = 440401;
5904
+ var LN2_HI = 0.6931471803691238;
5905
+ var LN2_LO = 19082149292705877e-26;
5906
+ var TWO54 = 18014398509481984;
5907
+ var TWO = 2;
5908
+ var THIRD = 0.3333333333333333;
5909
+ var HALF = 0.5;
5910
+ var LG1 = 0.6666666666666735;
5911
+ var LG2 = 0.3999999999940942;
5912
+ var LG3 = 0.2857142874366239;
5913
+ var LG4 = 0.22222198432149784;
5914
+ var LG5 = 0.1818357216161805;
5915
+ var LG6 = 0.15313837699209373;
5916
+ var LG7 = 0.14798198605116586;
5917
+ function nearOne(fraction, scale) {
5918
+ if (fraction === 0) {
5919
+ if (scale === 0) return 0;
5920
+ return scale * LN2_HI + scale * LN2_LO;
5921
+ }
5922
+ const cubic = fraction * fraction * (HALF - THIRD * fraction);
5923
+ if (scale === 0) return fraction - cubic;
5924
+ return scale * LN2_HI - (cubic - scale * LN2_LO - fraction);
5925
+ }
5926
+ function series(fraction, scale, significand) {
5927
+ const ratio = fraction / (TWO + fraction);
5928
+ const square = ratio * ratio;
5929
+ const below = significand - LOWER_SPLIT;
5930
+ const fourth = square * square;
5931
+ const above = UPPER_SPLIT - significand;
5932
+ const even = fourth * (LG2 + fourth * (LG4 + fourth * LG6));
5933
+ const odd = square * (LG1 + fourth * (LG3 + fourth * (LG5 + fourth * LG7)));
5934
+ const poly = odd + even;
5935
+ if ((below | above) > 0) {
5936
+ const halfSquare = HALF * fraction * fraction;
5937
+ if (scale === 0) return fraction - (halfSquare - ratio * (halfSquare + poly));
5938
+ return scale * LN2_HI - (halfSquare - (ratio * (halfSquare + poly) + scale * LN2_LO) - fraction);
5939
+ }
5940
+ if (scale === 0) return fraction - ratio * (fraction - poly);
5941
+ return scale * LN2_HI - (ratio * (fraction - poly) - scale * LN2_LO - fraction);
5942
+ }
5943
+ function log(value) {
5944
+ let high = highWord(value);
5945
+ let scale = 0;
5946
+ let scaled = value;
5947
+ if (high < SMALLEST_NORMAL_HIGH_WORD) {
5948
+ if ((high & MAGNITUDE_MASK | lowWord(value)) === 0) return Number.NEGATIVE_INFINITY;
5949
+ if (high < 0) return Number.NaN;
5950
+ scale -= SUBNORMAL_SCALE_EXPONENT;
5951
+ scaled *= TWO54;
5952
+ high = highWord(scaled);
5953
+ }
5954
+ if (high >= INFINITE_HIGH_WORD) return scaled + scaled;
5955
+ scale += (high >> EXPONENT_SHIFT) - EXPONENT_BIAS;
5956
+ const significand = high & SIGNIFICAND_MASK;
5957
+ const halving = significand + ROUNDING_OFFSET & HALVING_BIT;
5958
+ scaled = withHighWord(scaled, significand | halving ^ ONE_HIGH_WORD);
5959
+ scale += halving >> EXPONENT_SHIFT;
5960
+ const fraction = scaled - 1;
5961
+ if ((SIGNIFICAND_MASK & 2 + significand) < NEAR_ONE_LIMIT) return nearOne(fraction, scale);
5962
+ return series(fraction, scale, significand);
5963
+ }
5964
+
6216
5965
  // src/core/scorer.ts
6217
5966
  function computeIDF(docFrequency, totalDocs) {
6218
5967
  if (totalDocs === 0) return 0;
6219
- return Math.log((totalDocs - docFrequency + 0.5) / (docFrequency + 0.5) + 1);
5968
+ return log((totalDocs - docFrequency + 0.5) / (docFrequency + 0.5) + 1);
6220
5969
  }
6221
5970
  function pairKeepsBoundSound(k1, b) {
6222
5971
  return k1 >= 0 && k1 <= MAX_BM25_K1 && b >= 0 && b <= MAX_BM25_B;
@@ -6280,6 +6029,43 @@ function computeBM25WithIDF(termFrequency, idf, fieldLength, avgFieldLength, k1,
6280
6029
  return idf * (numerator / denominator);
6281
6030
  }
6282
6031
 
6032
+ // src/core/partition/field-order.ts
6033
+ var fieldRun = { entries: new Uint32Array(FIELD_RUN_ENTRIES_START), length: 0 };
6034
+ var ranksByFieldNames = /* @__PURE__ */ new WeakMap();
6035
+ var ONLY_FIELD_RANKS = new Uint32Array(1);
6036
+ function fieldNameRanks(fieldNames) {
6037
+ if (fieldNames.length < 2) return ONLY_FIELD_RANKS;
6038
+ const held = ranksByFieldNames.get(fieldNames);
6039
+ if (held !== void 0 && held.length === fieldNames.length) return held;
6040
+ const order = Array.from(fieldNames.keys()).sort(
6041
+ (left, right) => compareCodePoints(fieldNames[left], fieldNames[right])
6042
+ );
6043
+ const ranks = new Uint32Array(order.length);
6044
+ for (let rank = 0; rank < order.length; rank++) ranks[order[rank]] = rank;
6045
+ ranksByFieldNames.set(fieldNames, ranks);
6046
+ return ranks;
6047
+ }
6048
+ function orderRunByFieldName(docIds, fieldIndices, ranks, start, count) {
6049
+ let entries = fieldRun.entries;
6050
+ let end = start;
6051
+ for (; end < count && docIds[end] === docIds[start]; end++) {
6052
+ let slot = end - start;
6053
+ if (slot === entries.length) {
6054
+ const grown2 = new Uint32Array(slot * 2);
6055
+ grown2.set(entries);
6056
+ entries = fieldRun.entries = grown2;
6057
+ }
6058
+ const rank = ranks[fieldIndices[end]];
6059
+ while (slot > 0 && ranks[fieldIndices[entries[slot - 1]]] > rank) {
6060
+ entries[slot] = entries[slot - 1];
6061
+ slot--;
6062
+ }
6063
+ entries[slot] = end;
6064
+ }
6065
+ fieldRun.length = end - start;
6066
+ return entries;
6067
+ }
6068
+
6283
6069
  // src/core/partition/field-scoring.ts
6284
6070
  var NO_FIELD_VALUES = new Float64Array(0);
6285
6071
  function differentPairsOf(searchable, k1s, bs) {
@@ -6307,7 +6093,8 @@ function loadFieldScoring(state, fields, boost, averageFieldLengths, bm25) {
6307
6093
  lengthColumns: new Array(fieldCount).fill(null),
6308
6094
  k1s: perField === void 0 ? NO_FIELD_VALUES : new Float64Array(fieldCount),
6309
6095
  bs: perField === void 0 ? NO_FIELD_VALUES : new Float64Array(fieldCount),
6310
- boundPairs: [k1, b]
6096
+ boundPairs: [k1, b],
6097
+ nameRanks: fieldNameRanks(fieldNames)
6311
6098
  };
6312
6099
  for (let fieldIndex = 0; fieldIndex < fieldCount; fieldIndex++) {
6313
6100
  const fieldName = fieldNames[fieldIndex];
@@ -6324,8 +6111,8 @@ function loadFieldScoring(state, fields, boost, averageFieldLengths, bm25) {
6324
6111
  if (perField !== void 0) scoring.boundPairs = differentPairsOf(scoring.searchable, scoring.k1s, scoring.bs);
6325
6112
  return scoring;
6326
6113
  }
6327
- function fieldLengthOf(columns, fieldIndex, internalId, averageLength) {
6328
- const column = fieldIndex < columns.length ? columns[fieldIndex] : null;
6114
+ function fieldLengthOf(columns2, fieldIndex, internalId, averageLength) {
6115
+ const column = fieldIndex < columns2.length ? columns2[fieldIndex] : null;
6329
6116
  if (column === null || internalId >= column.length) return averageLength;
6330
6117
  const stored = column[internalId];
6331
6118
  return stored > 0 ? stored : averageLength;
@@ -6410,20 +6197,26 @@ function termGroupOf(groups, token) {
6410
6197
  function typoMatchesFor(index, token, group, exact, tolerance, prefixLength) {
6411
6198
  if (group !== void 0) {
6412
6199
  if (!group.typoMatches || exact || tolerance === 0) return [];
6413
- return index.fuzzyLookup(token, tolerance, prefixLength).filter((match) => match.token !== token && group.synonyms?.has(match.token) !== true);
6200
+ return index.fuzzyLookup(token, tolerance, prefixLength).filter((match) => match.token !== token && group.synonyms?.has(match.token) !== true).sort(byToken);
6201
+ }
6202
+ if (!exact) {
6203
+ const matches = index.fuzzyLookup(token, tolerance, prefixLength);
6204
+ return matches.length > 1 ? matches.sort(byToken) : matches;
6414
6205
  }
6415
- if (!exact) return index.fuzzyLookup(token, tolerance, prefixLength);
6416
6206
  const postingList = index.lookup(token);
6417
6207
  return postingList ? [{ token, postingList }] : [];
6418
6208
  }
6209
+ function byToken(left, right) {
6210
+ return compareCodePoints(left.token, right.token);
6211
+ }
6419
6212
  function resolveGroupMatches(context, group) {
6420
- const frequencyOf = (token) => context.globalFrequency(token) ?? context.index.documentFrequency(token);
6213
+ const frequencyOf2 = (token) => context.globalFrequency(token) ?? context.index.documentFrequency(token);
6421
6214
  const lookup = (token) => context.index.lookup(token);
6422
6215
  const synonyms = group.synonyms;
6423
- let groupDocumentFrequency = synonyms?.documentFrequency(frequencyOf) ?? 0;
6216
+ let groupDocumentFrequency = synonyms?.documentFrequency(frequencyOf2) ?? 0;
6424
6217
  const found = [];
6425
6218
  for (const member of group.members) {
6426
- const documents = frequencyOf(member.token);
6219
+ const documents = frequencyOf2(member.token);
6427
6220
  if (documents > groupDocumentFrequency) groupDocumentFrequency = documents;
6428
6221
  const postingList = synonyms !== void 0 && member.token === group.token ? synonyms.postings(lookup, member.token) : lookup(member.token);
6429
6222
  if (postingList === void 0) continue;
@@ -6448,10 +6241,20 @@ function computeGroupContributions(context, matches, collect) {
6448
6241
  const { docIds, termFrequencies, fieldNameIndices, deletedDocs, hasDeleted, count } = postingColumns(
6449
6242
  match.postingList
6450
6243
  );
6451
- for (let pi = 0; pi < count; pi++) {
6452
- const internalId = docIds[pi];
6244
+ let runStart = 0;
6245
+ let runEnd = 0;
6246
+ for (let at = 0; at < count; at++) {
6247
+ const internalId = docIds[at];
6453
6248
  if (hasDeleted && deletedDocs.has(internalId)) continue;
6454
6249
  if (filterBitset && !bitsetHas(filterBitset, internalId)) continue;
6250
+ let pi = at;
6251
+ if (at < runEnd) {
6252
+ pi = fieldRun.entries[at - runStart];
6253
+ } else if (at + 2 < count && docIds[at + 2] === internalId) {
6254
+ pi = orderRunByFieldName(docIds, fieldNameIndices, fields.nameRanks, at, count)[0];
6255
+ runStart = at;
6256
+ runEnd = at + fieldRun.length;
6257
+ }
6455
6258
  const fieldIndex = fieldNameIndices[pi];
6456
6259
  if (fields.searchable[fieldIndex] === 0) continue;
6457
6260
  const factor = partialMarks[fieldIndex] === 1 ? match.partialFactor : match.factor;
@@ -6729,7 +6532,7 @@ function mergeFieldIndexes(target, source, idMapping) {
6729
6532
  for (const [fieldPath, index] of source.geoIndexes) {
6730
6533
  let targetIndex = target.geoIndexes.get(fieldPath);
6731
6534
  if (targetIndex === void 0) {
6732
- targetIndex = createGeoIndex();
6535
+ targetIndex = createLoadedGeoIndex();
6733
6536
  target.geoIndexes.set(fieldPath, targetIndex);
6734
6537
  }
6735
6538
  for (const entry of index.serialize()) {
@@ -6760,8 +6563,8 @@ function mergeSegmentState(target, source) {
6760
6563
  // src/core/partition/block-bounds.ts
6761
6564
  var ABSENT_FIELD_LENGTH_BOUND = 0;
6762
6565
  var boundsByList = /* @__PURE__ */ new WeakMap();
6763
- function fieldLengthBound(columns, fieldIndex, internalId) {
6764
- const column = fieldIndex < columns.length ? columns[fieldIndex] : null;
6566
+ function fieldLengthBound(columns2, fieldIndex, internalId) {
6567
+ const column = fieldIndex < columns2.length ? columns2[fieldIndex] : null;
6765
6568
  if (column === null || internalId >= column.length) return ABSENT_FIELD_LENGTH_BOUND;
6766
6569
  const stored = column[internalId];
6767
6570
  return stored > 0 ? stored : ABSENT_FIELD_LENGTH_BOUND;
@@ -6769,7 +6572,7 @@ function fieldLengthBound(columns, fieldIndex, internalId) {
6769
6572
  function entriesCovered(bounds) {
6770
6573
  return bounds.blockCount === 0 ? 0 : bounds.entryEnd[bounds.blockCount - 1];
6771
6574
  }
6772
- function scanPostingBlocks(list, columns, previous, keepBlocks) {
6575
+ function scanPostingBlocks(list, columns2, previous, keepBlocks) {
6773
6576
  const { docIds, termFrequencies, fieldNameIndices, length } = list;
6774
6577
  const startEntry = previous !== null && keepBlocks > 0 ? previous.entryEnd[keepBlocks - 1] : 0;
6775
6578
  const capacity = keepBlocks + Math.ceil((length - startEntry) / TARGET_BLOCK_ENTRIES) + 1;
@@ -6803,7 +6606,7 @@ function scanPostingBlocks(list, columns, previous, keepBlocks) {
6803
6606
  const position = entry + run;
6804
6607
  const termFrequency = termFrequencies[position];
6805
6608
  if (termFrequency > blockMaxTf) blockMaxTf = termFrequency;
6806
- const fieldLength = fieldLengthBound(columns, fieldNameIndices[position], docId);
6609
+ const fieldLength = fieldLengthBound(columns2, fieldNameIndices[position], docId);
6807
6610
  if (fieldLength < blockMinLen) blockMinLen = fieldLength;
6808
6611
  }
6809
6612
  run++;
@@ -6837,19 +6640,19 @@ function scanPostingBlocks(list, columns, previous, keepBlocks) {
6837
6640
  documentCount
6838
6641
  };
6839
6642
  }
6840
- function blockBoundsFor(list, columns) {
6643
+ function blockBoundsFor(list, columns2) {
6841
6644
  const existing = boundsByList.get(list);
6842
6645
  if (existing !== void 0 && existing.structureRevision === list.structureRevision) {
6843
6646
  const covered = entriesCovered(existing);
6844
6647
  if (covered === list.length) return existing;
6845
6648
  if (list.ordered && covered < list.length) {
6846
- const extended = scanPostingBlocks(list, columns, existing, Math.max(0, existing.blockCount - 1));
6649
+ const extended = scanPostingBlocks(list, columns2, existing, Math.max(0, existing.blockCount - 1));
6847
6650
  boundsByList.set(list, extended);
6848
6651
  return extended;
6849
6652
  }
6850
6653
  }
6851
6654
  const stored = list.storedBlockBounds?.() ?? null;
6852
- const built = stored === null ? scanPostingBlocks(list, columns, null, 0) : { ...stored, structureRevision: list.structureRevision };
6655
+ const built = stored === null ? scanPostingBlocks(list, columns2, null, 0) : { ...stored, structureRevision: list.structureRevision };
6853
6656
  boundsByList.set(list, built);
6854
6657
  return built;
6855
6658
  }
@@ -6910,9 +6713,9 @@ function beginScoring(buffer, capacity) {
6910
6713
  }
6911
6714
  function appendTouched(buffer, internalId) {
6912
6715
  if (buffer.touchedCount === buffer.touched.length) {
6913
- const grown = new Int32Array(buffer.touched.length * 2);
6914
- grown.set(buffer.touched);
6915
- buffer.touched = grown;
6716
+ const grown2 = new Int32Array(buffer.touched.length * 2);
6717
+ grown2.set(buffer.touched);
6718
+ buffer.touched = grown2;
6916
6719
  }
6917
6720
  buffer.touched[buffer.touchedCount] = internalId;
6918
6721
  buffer.touchedCount++;
@@ -7002,13 +6805,13 @@ function topKFromBuffer(buffer, k, resolver, components) {
7002
6805
  const result = new Array(heap.length);
7003
6806
  for (let index = 0; index < heap.length; index++) {
7004
6807
  const entry = heap[index];
7005
- const record = components?.get(entry.internalId);
6808
+ const record2 = components?.get(entry.internalId);
7006
6809
  result[index] = {
7007
6810
  docId: entry.externalId,
7008
6811
  score: entry.score,
7009
- termFrequencies: record?.termFrequencies ?? EMPTY_COMPONENTS,
7010
- fieldLengths: record?.fieldLengths ?? EMPTY_COMPONENTS,
7011
- idf: record?.idf ?? EMPTY_COMPONENTS
6812
+ termFrequencies: record2?.termFrequencies ?? EMPTY_COMPONENTS,
6813
+ fieldLengths: record2?.fieldLengths ?? EMPTY_COMPONENTS,
6814
+ idf: record2?.idf ?? EMPTY_COMPONENTS
7012
6815
  };
7013
6816
  }
7014
6817
  return result;
@@ -7078,20 +6881,20 @@ function fieldPairUpperBound(scan, list, maxBoost, maxAverageLength) {
7078
6881
  return best;
7079
6882
  }
7080
6883
  function samePairEntryScore(scan, entry, internalId) {
7081
- const { fields, columns } = scan;
7082
- const fieldIndex = columns.fieldNameIndices[entry];
6884
+ const { fields, columns: columns2 } = scan;
6885
+ const fieldIndex = columns2.fieldNameIndices[entry];
7083
6886
  const averageLength = fields.averageLengths[fieldIndex];
7084
6887
  const fieldLength = fieldLengthOf(fields.lengthColumns, fieldIndex, internalId, averageLength);
7085
- const bm25 = scan.scoresAreZero ? 0 : computeBM25WithIDF(columns.termFrequencies[entry], scan.idf, fieldLength, averageLength, scan.k1, scan.b);
6888
+ const bm25 = scan.scoresAreZero ? 0 : computeBM25WithIDF(columns2.termFrequencies[entry], scan.idf, fieldLength, averageLength, scan.k1, scan.b);
7086
6889
  return bm25 * fields.boosts[fieldIndex];
7087
6890
  }
7088
6891
  function fieldPairEntryScore(scan, entry, internalId) {
7089
- const { fields, columns } = scan;
7090
- const fieldIndex = columns.fieldNameIndices[entry];
6892
+ const { fields, columns: columns2 } = scan;
6893
+ const fieldIndex = columns2.fieldNameIndices[entry];
7091
6894
  const averageLength = fields.averageLengths[fieldIndex];
7092
6895
  const fieldLength = fieldLengthOf(fields.lengthColumns, fieldIndex, internalId, averageLength);
7093
6896
  const bm25 = scan.scoresAreZero ? 0 : computeBM25WithIDF(
7094
- columns.termFrequencies[entry],
6897
+ columns2.termFrequencies[entry],
7095
6898
  scan.idf,
7096
6899
  fieldLength,
7097
6900
  averageLength,
@@ -7156,15 +6959,30 @@ function firstEntryOf(docIds, count, internalId) {
7156
6959
  }
7157
6960
  return low;
7158
6961
  }
6962
+ function fieldOrderedRunScore(scan, start, internalId, total, entryScore) {
6963
+ const { docIds, fieldNameIndices, count } = scan.columns;
6964
+ const ordered = orderRunByFieldName(docIds, fieldNameIndices, scan.fields.nameRanks, start, count);
6965
+ let score = total;
6966
+ for (let at = 0; at < fieldRun.length; at++) {
6967
+ const row = ordered[at];
6968
+ if (scan.fields.searchable[fieldNameIndices[row]] !== 1) continue;
6969
+ score += entryScore(scan, row, internalId);
6970
+ }
6971
+ return score;
6972
+ }
7159
6973
  function samePairQueryOrderScore(scans, internalId) {
7160
6974
  let score = 0;
7161
6975
  for (const scan of scans) {
7162
6976
  const { docIds, deletedDocs, hasDeleted, count } = scan.columns;
7163
6977
  if (hasDeleted && deletedDocs.has(internalId)) continue;
7164
- for (let entry = firstEntryOf(docIds, count, internalId); entry < count && docIds[entry] === internalId; entry++) {
7165
- if (scan.fields.searchable[scan.columns.fieldNameIndices[entry]] !== 1) continue;
7166
- score += samePairEntryScore(scan, entry, internalId);
6978
+ const start = firstEntryOf(docIds, count, internalId);
6979
+ if (start + 1 < count && docIds[start + 1] === internalId) {
6980
+ score = fieldOrderedRunScore(scan, start, internalId, score, samePairEntryScore);
6981
+ continue;
7167
6982
  }
6983
+ if (start === count || docIds[start] !== internalId) continue;
6984
+ if (scan.fields.searchable[scan.columns.fieldNameIndices[start]] !== 1) continue;
6985
+ score += samePairEntryScore(scan, start, internalId);
7168
6986
  }
7169
6987
  return score;
7170
6988
  }
@@ -7173,10 +6991,14 @@ function fieldPairQueryOrderScore(scans, internalId) {
7173
6991
  for (const scan of scans) {
7174
6992
  const { docIds, deletedDocs, hasDeleted, count } = scan.columns;
7175
6993
  if (hasDeleted && deletedDocs.has(internalId)) continue;
7176
- for (let entry = firstEntryOf(docIds, count, internalId); entry < count && docIds[entry] === internalId; entry++) {
7177
- if (scan.fields.searchable[scan.columns.fieldNameIndices[entry]] !== 1) continue;
7178
- score += fieldPairEntryScore(scan, entry, internalId);
6994
+ const start = firstEntryOf(docIds, count, internalId);
6995
+ if (start + 1 < count && docIds[start + 1] === internalId) {
6996
+ score = fieldOrderedRunScore(scan, start, internalId, score, fieldPairEntryScore);
6997
+ continue;
7179
6998
  }
6999
+ if (start === count || docIds[start] !== internalId) continue;
7000
+ if (scan.fields.searchable[scan.columns.fieldNameIndices[start]] !== 1) continue;
7001
+ score += fieldPairEntryScore(scan, start, internalId);
7180
7002
  }
7181
7003
  return score;
7182
7004
  }
@@ -7314,7 +7136,8 @@ function singleTermTopK(request) {
7314
7136
  lengthColumns: fieldLengthColumns,
7315
7137
  k1s,
7316
7138
  bs,
7317
- boundPairs
7139
+ boundPairs,
7140
+ nameRanks
7318
7141
  } = request.fields;
7319
7142
  const onePair = boundPairs.length === 2;
7320
7143
  const onlyK1 = boundPairs[0];
@@ -7354,12 +7177,14 @@ function singleTermTopK(request) {
7354
7177
  }
7355
7178
  let score = 0;
7356
7179
  let scored2 = false;
7357
- while (entry < end && docIds[entry] === internalId) {
7358
- const fieldIndex = fieldNameIndices[entry];
7180
+ const ordered = entry + 2 < end && docIds[entry + 2] === internalId ? orderRunByFieldName(docIds, fieldNameIndices, nameRanks, entry, end) : null;
7181
+ for (let at = 0; entry < end && docIds[entry] === internalId; at++, entry++) {
7182
+ const row = ordered === null ? entry : ordered[at];
7183
+ const fieldIndex = fieldNameIndices[row];
7359
7184
  if (fieldSearchable[fieldIndex] === 1) {
7360
7185
  const fieldLength = fieldLengthOf(fieldLengthColumns, fieldIndex, internalId, fieldAvgLengths[fieldIndex]);
7361
7186
  score += (scoresAreZero ? 0 : computeBM25WithIDF(
7362
- termFrequencies[entry],
7187
+ termFrequencies[row],
7363
7188
  idf,
7364
7189
  fieldLength,
7365
7190
  fieldAvgLengths[fieldIndex],
@@ -7368,7 +7193,6 @@ function singleTermTopK(request) {
7368
7193
  )) * fieldBoosts[fieldIndex];
7369
7194
  scored2 = true;
7370
7195
  }
7371
- entry++;
7372
7196
  }
7373
7197
  if (!scored2) continue;
7374
7198
  totalMatched++;
@@ -7408,6 +7232,10 @@ function singleTermTopK(request) {
7408
7232
  }
7409
7233
 
7410
7234
  // src/core/partition/search.ts
7235
+ var nativeKeywordSearch = null;
7236
+ function installNativeKeywordSearch(search) {
7237
+ nativeKeywordSearch = search;
7238
+ }
7411
7239
  function globalDocFreqFor(docFreqs, term, fallback) {
7412
7240
  return Object.hasOwn(docFreqs, term) ? docFreqs[term] : fallback;
7413
7241
  }
@@ -7434,15 +7262,11 @@ function searchFulltext(state, params) {
7434
7262
  const totalDocs = globalStats?.totalDocuments ?? state.stats.totalDocuments;
7435
7263
  const avgFieldLengths = globalStats?.averageFieldLengths ?? state.stats.averageFieldLengths;
7436
7264
  const scoresAreZero = totalDocs === 0;
7437
- if (state.scoreBuffer === null) state.scoreBuffer = createScoreBuffer(state.docStore.internalIdCapacity());
7438
- const scoreBuffer = state.scoreBuffer;
7439
- beginScoring(scoreBuffer, state.docStore.internalIdCapacity());
7440
- const components = collectComponents ? /* @__PURE__ */ new Map() : null;
7441
7265
  const useIntersection = termMatch === "all" && queryTokens.length > 1;
7442
7266
  const fieldNames = state.fieldNameTable.names;
7443
7267
  const resolver = state.docStore.resolver();
7444
7268
  const fieldScoring = loadFieldScoring(state, fields, boost, avgFieldLengths, bm25Params);
7445
- const { searchable, boosts, averageLengths, lengthColumns, k1s, bs, boundPairs } = fieldScoring;
7269
+ const { searchable, boosts, averageLengths, lengthColumns, k1s, bs, boundPairs, nameRanks } = fieldScoring;
7446
7270
  const onePair = boundPairs.length === 2;
7447
7271
  const onlyK1 = boundPairs[0];
7448
7272
  const onlyB = boundPairs[1];
@@ -7458,7 +7282,13 @@ function searchFulltext(state, params) {
7458
7282
  if (phraseMatches !== null && bitsetIsEmpty(phraseMatches.matched)) {
7459
7283
  return { scored: [], totalMatched: 0 };
7460
7284
  }
7285
+ const inTheCore = nativeKeywordSearch?.(state, params, phraseMatches);
7286
+ if (inTheCore) return inTheCore;
7461
7287
  const filterBitset = phraseMatches?.matched ?? params.filterBitset;
7288
+ if (state.scoreBuffer === null) state.scoreBuffer = createScoreBuffer(state.docStore.internalIdCapacity());
7289
+ const scoreBuffer = state.scoreBuffer;
7290
+ beginScoring(scoreBuffer, state.docStore.internalIdCapacity());
7291
+ const components = collectComponents ? /* @__PURE__ */ new Map() : null;
7462
7292
  function documentFrequency(token, list) {
7463
7293
  return globalStats ? globalDocFreqFor(globalStats.docFrequencies, token, list.docIdSet.size) : list.docIdSet.size;
7464
7294
  }
@@ -7467,25 +7297,35 @@ function searchFulltext(state, params) {
7467
7297
  for (let entry = 0; entry < rows.phrase.tokens.length; entry++) {
7468
7298
  idf += computeIDF(documentFrequency(rows.phrase.tokens[entry], rows.lists[entry]), totalDocs);
7469
7299
  }
7470
- for (let row = 0; row < rows.docIds.length; row++) {
7471
- const internalId = rows.docIds.values[row];
7472
- if (!bitsetHas(matched, internalId)) continue;
7473
- const fieldIndex = rows.fieldIndices.values[row];
7474
- const frequency = rows.frequencies.values[row];
7475
- const avgLen = averageLengths[fieldIndex];
7476
- const fieldLength = fieldLengthOf(lengthColumns, fieldIndex, internalId, avgLen);
7477
- const score = scoresAreZero ? 0 : computeBM25WithIDF(
7478
- frequency,
7479
- idf,
7480
- fieldLength,
7481
- avgLen,
7482
- onePair ? onlyK1 : k1s[fieldIndex],
7483
- onePair ? onlyB : bs[fieldIndex]
7300
+ for (let start = 0; start < rows.docIds.length; start += fieldRun.length) {
7301
+ const entries = orderRunByFieldName(
7302
+ rows.docIds.values,
7303
+ rows.fieldIndices.values,
7304
+ nameRanks,
7305
+ start,
7306
+ rows.docIds.length
7484
7307
  );
7485
- addScore(scoreBuffer, internalId, score * boosts[fieldIndex]);
7486
- if (components !== null) {
7487
- recordComponents(components, internalId, fieldNames[fieldIndex], rows.phrase.key, frequency, fieldLength, idf);
7488
- }
7308
+ for (let at = 0; at < fieldRun.length; at++) scorePhraseRow(rows, matched, entries[at], idf);
7309
+ }
7310
+ }
7311
+ function scorePhraseRow(rows, matched, row, idf) {
7312
+ const internalId = rows.docIds.values[row];
7313
+ if (!bitsetHas(matched, internalId)) return;
7314
+ const fieldIndex = rows.fieldIndices.values[row];
7315
+ const frequency = rows.frequencies.values[row];
7316
+ const avgLen = averageLengths[fieldIndex];
7317
+ const fieldLength = fieldLengthOf(lengthColumns, fieldIndex, internalId, avgLen);
7318
+ const score = scoresAreZero ? 0 : computeBM25WithIDF(
7319
+ frequency,
7320
+ idf,
7321
+ fieldLength,
7322
+ avgLen,
7323
+ onePair ? onlyK1 : k1s[fieldIndex],
7324
+ onePair ? onlyB : bs[fieldIndex]
7325
+ );
7326
+ addScore(scoreBuffer, internalId, score * boosts[fieldIndex]);
7327
+ if (components !== null) {
7328
+ recordComponents(components, internalId, fieldNames[fieldIndex], rows.phrase.key, frequency, fieldLength, idf);
7489
7329
  }
7490
7330
  }
7491
7331
  const groupContext = {
@@ -7508,13 +7348,23 @@ function searchFulltext(state, params) {
7508
7348
  const docFreq = documentFrequency(token, postingList);
7509
7349
  return { token, docFreq, idf: computeIDF(docFreq, totalDocs), postingList };
7510
7350
  }
7511
- function scorePostings(match, onlyScored) {
7351
+ function scorePostings(match, only) {
7512
7352
  const { docIds, termFrequencies, fieldNameIndices, deletedDocs, hasDeleted, count } = postingColumns(
7513
7353
  match.postingList
7514
7354
  );
7515
- if (!onlyScored && !hasDeleted && filterBitset === void 0 && components === null) {
7516
- for (let pi = 0; pi < count; pi++) {
7517
- const internalId = docIds[pi];
7355
+ let runStart = 0;
7356
+ let runEnd = 0;
7357
+ if (only === null && !hasDeleted && filterBitset === void 0 && components === null) {
7358
+ for (let at = 0; at < count; at++) {
7359
+ const internalId = docIds[at];
7360
+ let pi = at;
7361
+ if (at < runEnd) {
7362
+ pi = fieldRun.entries[at - runStart];
7363
+ } else if (at + 1 < count && docIds[at + 1] === internalId) {
7364
+ pi = orderRunByFieldName(docIds, fieldNameIndices, nameRanks, at, count)[0];
7365
+ runStart = at;
7366
+ runEnd = at + fieldRun.length;
7367
+ }
7518
7368
  const fieldIndex = fieldNameIndices[pi];
7519
7369
  if (searchable[fieldIndex] === 0) continue;
7520
7370
  const avgLen = averageLengths[fieldIndex];
@@ -7531,11 +7381,19 @@ function searchFulltext(state, params) {
7531
7381
  }
7532
7382
  return;
7533
7383
  }
7534
- for (let pi = 0; pi < count; pi++) {
7535
- const internalId = docIds[pi];
7384
+ for (let at = 0; at < count; at++) {
7385
+ const internalId = docIds[at];
7536
7386
  if (hasDeleted && deletedDocs.has(internalId)) continue;
7537
7387
  if (filterBitset && !bitsetHas(filterBitset, internalId)) continue;
7538
- if (onlyScored && !hasScore(scoreBuffer, internalId)) continue;
7388
+ if (only !== null && !bitsetHas(only, internalId)) continue;
7389
+ let pi = at;
7390
+ if (at < runEnd) {
7391
+ pi = fieldRun.entries[at - runStart];
7392
+ } else if (at + 1 < count && docIds[at + 1] === internalId) {
7393
+ pi = orderRunByFieldName(docIds, fieldNameIndices, nameRanks, at, count)[0];
7394
+ runStart = at;
7395
+ runEnd = at + fieldRun.length;
7396
+ }
7539
7397
  const fieldIndex = fieldNameIndices[pi];
7540
7398
  if (searchable[fieldIndex] === 0) continue;
7541
7399
  const termFrequency = termFrequencies[pi];
@@ -7563,10 +7421,10 @@ function searchFulltext(state, params) {
7563
7421
  }
7564
7422
  }
7565
7423
  }
7566
- function scoreGroup(group, onlyScored) {
7424
+ function scoreGroup(group, only) {
7567
7425
  if (group === null) return;
7568
7426
  for (const [internalId, contribution] of computeGroupContributions(groupContext, group, collectComponents)) {
7569
- if (onlyScored && !hasScore(scoreBuffer, internalId)) continue;
7427
+ if (only !== null && !bitsetHas(only, internalId)) continue;
7570
7428
  mergeGroupContribution(internalId, contribution);
7571
7429
  }
7572
7430
  }
@@ -7607,19 +7465,27 @@ function searchFulltext(state, params) {
7607
7465
  }
7608
7466
  resolved.push({ token: qt.token, matches, totalPostings, group: groupMatches });
7609
7467
  }
7610
- resolved.sort((a, b) => a.totalPostings - b.totalPostings);
7611
- for (let tokenIndex = 0; tokenIndex < resolved.length; tokenIndex++) {
7612
- const onlyScored = tokenIndex > 0;
7613
- for (const match of resolved[tokenIndex].matches) scorePostings(match, onlyScored);
7614
- scoreGroup(resolved[tokenIndex].group, onlyScored);
7468
+ let anchor = resolved[0];
7469
+ for (const term of resolved) if (term.totalPostings < anchor.totalPostings) anchor = term;
7470
+ for (const match of anchor.matches) scorePostings(match, null);
7471
+ scoreGroup(anchor.group, null);
7472
+ const anchorDocuments = createBitSet(state.docStore.internalIdCapacity());
7473
+ for (let index = 0; index < scoreBuffer.touchedCount; index++) {
7474
+ bitsetSet(anchorDocuments, scoreBuffer.touched[index]);
7475
+ }
7476
+ beginScoring(scoreBuffer, state.docStore.internalIdCapacity());
7477
+ components?.clear();
7478
+ for (const term of resolved) {
7479
+ for (const match of term.matches) scorePostings(match, anchorDocuments);
7480
+ scoreGroup(term.group, anchorDocuments);
7615
7481
  }
7616
7482
  } else {
7617
7483
  for (const qt of queryTokens) {
7618
7484
  const group = termGroupOf(termGroups, qt.token);
7619
7485
  for (const m of typoMatchesFor(state.invertedIdx, qt.token, group, exact, tolerance, prefixLength)) {
7620
- scorePostings(resolveMatch(m.token, m.postingList), false);
7486
+ scorePostings(resolveMatch(m.token, m.postingList), null);
7621
7487
  }
7622
- if (group !== void 0) scoreGroup(resolveGroupMatches(groupContext, group), false);
7488
+ if (group !== void 0) scoreGroup(resolveGroupMatches(groupContext, group), null);
7623
7489
  }
7624
7490
  }
7625
7491
  if (phraseMatches !== null) {
@@ -7745,7 +7611,7 @@ function lookupReadOnce(state, token) {
7745
7611
  }
7746
7612
  function encodeFieldLengths(state, remap, documentCount) {
7747
7613
  const names = [];
7748
- const columns = [];
7614
+ const columns2 = [];
7749
7615
  const totals = {};
7750
7616
  for (const fieldName of Object.keys(state.stats.totalFieldLengths)) {
7751
7617
  const column = state.docStore.fieldLengthColumn(fieldName);
@@ -7759,10 +7625,10 @@ function encodeFieldLengths(state, remap, documentCount) {
7759
7625
  total += column[internalId];
7760
7626
  }
7761
7627
  names.push(fieldName);
7762
- columns.push(packed);
7628
+ columns2.push(packed);
7763
7629
  totals[fieldName] = total;
7764
7630
  }
7765
- return { names, columns, totals };
7631
+ return { names, columns: columns2, totals };
7766
7632
  }
7767
7633
  function encodeSegmentState(state) {
7768
7634
  const { remap, docIds } = buildOrdinalRemap(state);
@@ -7905,7 +7771,7 @@ function mergePayloadFieldIndexes(target, payload, ordinalBase) {
7905
7771
  for (const entry of payload.geo) {
7906
7772
  let index = target.geoIndexes.get(entry.fieldPath);
7907
7773
  if (index === void 0) {
7908
- index = createGeoIndex();
7774
+ index = createLoadedGeoIndex();
7909
7775
  target.geoIndexes.set(entry.fieldPath, index);
7910
7776
  }
7911
7777
  for (let i = 0; i < entry.docIds.length; i++) {
@@ -8139,7 +8005,7 @@ function deserializePartition(state, data, clearFn, schema) {
8139
8005
  state.enumIndexes.set(path, idx);
8140
8006
  }
8141
8007
  for (const [path, entries] of Object.entries(data.fieldIndexes.geopoint)) {
8142
- const geoIdx = createGeoIndex();
8008
+ const geoIdx = createLoadedGeoIndex();
8143
8009
  const converted = entries.map((e) => ({
8144
8010
  lat: e.lat,
8145
8011
  lon: e.lon,
@@ -9471,22 +9337,22 @@ function createWriteLogRecorder() {
9471
9337
  const current = [null, null];
9472
9338
  return {
9473
9339
  open(owner) {
9474
- const log = { docIds: /* @__PURE__ */ new Set(), replaced: false };
9475
- current[owner] = log;
9340
+ const log2 = { docIds: /* @__PURE__ */ new Set(), replaced: false };
9341
+ current[owner] = log2;
9476
9342
  return {
9477
9343
  get partitionsReplaced() {
9478
- return log.replaced;
9344
+ return log2.replaced;
9479
9345
  },
9480
9346
  get pendingDocuments() {
9481
- return log.docIds.size;
9347
+ return log2.docIds.size;
9482
9348
  },
9483
9349
  takeWrittenDocIds() {
9484
- const taken = log.docIds;
9485
- log.docIds = /* @__PURE__ */ new Set();
9350
+ const taken = log2.docIds;
9351
+ log2.docIds = /* @__PURE__ */ new Set();
9486
9352
  return taken;
9487
9353
  },
9488
9354
  close() {
9489
- if (current[owner] === log) current[owner] = null;
9355
+ if (current[owner] === log2) current[owner] = null;
9490
9356
  }
9491
9357
  };
9492
9358
  },
@@ -9495,17 +9361,17 @@ function createWriteLogRecorder() {
9495
9361
  current[1]?.docIds.add(docId);
9496
9362
  },
9497
9363
  segmentWritten(segment) {
9498
- for (const log of current) {
9499
- if (log === null) continue;
9364
+ for (const log2 of current) {
9365
+ if (log2 === null) continue;
9500
9366
  for (const internalId of segment.docStore.allInternalIds()) {
9501
9367
  const docId = segment.docStore.getExternalId(internalId);
9502
- if (docId !== void 0) log.docIds.add(docId);
9368
+ if (docId !== void 0) log2.docIds.add(docId);
9503
9369
  }
9504
9370
  }
9505
9371
  },
9506
9372
  partitionsReplaced() {
9507
- for (const log of current) {
9508
- if (log !== null) log.replaced = true;
9373
+ for (const log2 of current) {
9374
+ if (log2 !== null) log2.replaced = true;
9509
9375
  }
9510
9376
  }
9511
9377
  };
@@ -10942,6 +10808,22 @@ async function runQueryAction(entry, action) {
10942
10808
  return { count: result.totalMatched };
10943
10809
  }
10944
10810
 
10811
+ // src/workers/vector-code.ts
10812
+ var vectorCode = codeLoader(() => import('./module-TTEVPRCW.mjs'), "vector");
10813
+ var loadedVectorCode = vectorCode.loaded;
10814
+ var requireLoadedVectorCode = vectorCode.require;
10815
+ var loadVectorCode = vectorCode.load;
10816
+ var loadVectorCodeFor = vectorCode.loadFor;
10817
+
10818
+ // src/workers/schema-code.ts
10819
+ function loadSchemaCodeFor(schema) {
10820
+ const vectorCode2 = loadVectorCodeFor(schema);
10821
+ const geoCode2 = loadGeoCodeFor(schema);
10822
+ if (vectorCode2 === null) return geoCode2;
10823
+ if (geoCode2 === null) return vectorCode2;
10824
+ return Promise.all([vectorCode2, geoCode2]);
10825
+ }
10826
+
10945
10827
  // src/core/partition/frozen/doc-table.ts
10946
10828
  function createFrozenDocTable(idTable, lengthColumns, documents, tombstones) {
10947
10829
  const capacity = idTable.count;
@@ -11777,17 +11659,17 @@ function createFrozenInvertedReader(table, views, counts) {
11777
11659
  // src/core/partition/frozen/live-counts.ts
11778
11660
  var UINT32_BYTES = 4;
11779
11661
  var FLOAT64_BYTES = 8;
11780
- function removalIndexBytes(columns, terms) {
11781
- const documentWords = 2 * (columns.documentCount + 1);
11782
- return (columns.postingDocIds.length + documentWords + 2 * terms) * UINT32_BYTES + terms * FLOAT64_BYTES;
11662
+ function removalIndexBytes(columns2, terms) {
11663
+ const documentWords = 2 * (columns2.documentCount + 1);
11664
+ return (columns2.postingDocIds.length + documentWords + 2 * terms) * UINT32_BYTES + terms * FLOAT64_BYTES;
11783
11665
  }
11784
11666
  function processHasRoomFor(bytes) {
11785
11667
  const memory = readResidentMemory();
11786
11668
  if (memory === null) return true;
11787
11669
  return memory.residentBytes + bytes <= FROZEN_REMOVAL_INDEX_MAX_PROCESS_FRACTION * memory.limitBytes;
11788
11670
  }
11789
- function buildRemovalIndex(columns, table) {
11790
- const { documentCount, postingDocIds } = columns;
11671
+ function buildRemovalIndex(columns2, table) {
11672
+ const { documentCount, postingDocIds } = columns2;
11791
11673
  const starts = new Uint32Array(documentCount + 1);
11792
11674
  for (let row = 0; row < postingDocIds.length; row++) starts[postingDocIds[row] + 1]++;
11793
11675
  for (let ordinal = 0; ordinal < documentCount; ordinal++) starts[ordinal + 1] += starts[ordinal];
@@ -11806,10 +11688,10 @@ function buildRemovalIndex(columns, table) {
11806
11688
  occurrences: new Float64Array(table.size)
11807
11689
  };
11808
11690
  }
11809
- function tryBuildRemovalIndex(columns, table) {
11810
- if (!processHasRoomFor(removalIndexBytes(columns, table.size))) return null;
11691
+ function tryBuildRemovalIndex(columns2, table) {
11692
+ if (!processHasRoomFor(removalIndexBytes(columns2, table.size))) return null;
11811
11693
  try {
11812
- return buildRemovalIndex(columns, table);
11694
+ return buildRemovalIndex(columns2, table);
11813
11695
  } catch (error) {
11814
11696
  if (error instanceof RangeError) return null;
11815
11697
  throw error;
@@ -11825,8 +11707,8 @@ function slotOfRow(postingOffsets, slots, row) {
11825
11707
  }
11826
11708
  return low;
11827
11709
  }
11828
- function createFrozenLiveCounts(columns, table, tombstones, storedFrequencies) {
11829
- const { postingOffsets, postingDocIds, postingFrequencies } = columns;
11710
+ function createFrozenLiveCounts(columns2, table, tombstones, storedFrequencies) {
11711
+ const { postingOffsets, postingDocIds, postingFrequencies } = columns2;
11830
11712
  let index = null;
11831
11713
  let lengths = null;
11832
11714
  let frequencies = null;
@@ -11880,10 +11762,10 @@ function createFrozenLiveCounts(columns, table, tombstones, storedFrequencies) {
11880
11762
  }
11881
11763
  return {
11882
11764
  totalDocuments() {
11883
- return columns.documentCount - tombstones.size;
11765
+ return columns2.documentCount - tombstones.size;
11884
11766
  },
11885
11767
  totalFieldLengths() {
11886
- return lengths ?? columns.totalFieldLengths;
11768
+ return lengths ?? columns2.totalFieldLengths;
11887
11769
  },
11888
11770
  documentFrequency,
11889
11771
  removedOccurrences(sortedIndex) {
@@ -11904,15 +11786,15 @@ function createFrozenLiveCounts(columns, table, tombstones, storedFrequencies) {
11904
11786
  return frequencies;
11905
11787
  },
11906
11788
  subtractRemoved(ordinal) {
11907
- lengths ??= { ...columns.totalFieldLengths };
11908
- for (let field = 0; field < columns.fieldLengthNames.length; field++) {
11909
- lengths[columns.fieldLengthNames[field]] -= columns.fieldLengthColumns[field][ordinal];
11789
+ lengths ??= { ...columns2.totalFieldLengths };
11790
+ for (let field = 0; field < columns2.fieldLengthNames.length; field++) {
11791
+ lengths[columns2.fieldLengthNames[field]] -= columns2.fieldLengthColumns[field][ordinal];
11910
11792
  }
11911
11793
  if (index !== null) {
11912
11794
  countRemoval(index, ordinal);
11913
11795
  return;
11914
11796
  }
11915
- const built = tryBuildRemovalIndex(columns, table);
11797
+ const built = tryBuildRemovalIndex(columns2, table);
11916
11798
  if (built === null) return;
11917
11799
  for (const removed of tombstones.values()) countRemoval(built, removed);
11918
11800
  index = built;
@@ -12076,7 +11958,7 @@ function createFrozenSurfaceSlot(load, documents, tableOnDisk) {
12076
11958
  for (const spelling of spellings) target.subtract(spelling, 1);
12077
11959
  }
12078
11960
  }
12079
- function loaded3() {
11961
+ function loaded2() {
12080
11962
  if (registry === null) {
12081
11963
  const built = createSurfaceRegistry();
12082
11964
  const forms = load();
@@ -12095,10 +11977,10 @@ function createFrozenSurfaceSlot(load, documents, tableOnDisk) {
12095
11977
  return {
12096
11978
  heldBytes: () => table?.heldBytes() ?? 0,
12097
11979
  reader: {
12098
- candidatesForPrefix: (prefix) => table !== void 0 && waitingRemovals.length === 0 ? table.candidatesForPrefix(prefix) : loaded3().candidatesForPrefix(prefix),
12099
- stemChangedTotalFor: (token) => loaded3().stemChangedTotalFor(token),
12100
- size: () => loaded3().size(),
12101
- serialize: () => loaded3().serialize()
11980
+ candidatesForPrefix: (prefix) => table !== void 0 && waitingRemovals.length === 0 ? table.candidatesForPrefix(prefix) : loaded2().candidatesForPrefix(prefix),
11981
+ stemChangedTotalFor: (token) => loaded2().stemChangedTotalFor(token),
11982
+ size: () => loaded2().size(),
11983
+ serialize: () => loaded2().serialize()
12102
11984
  },
12103
11985
  tableStaysOnDisk() {
12104
11986
  return registry === null && tableOnDisk !== void 0;
@@ -12110,20 +11992,20 @@ function createFrozenSurfaceSlot(load, documents, tableOnDisk) {
12110
11992
  waitingRemovals.push(ordinal);
12111
11993
  },
12112
11994
  holdsAny() {
12113
- return loaded3().size() > 0;
11995
+ return loaded2().size() > 0;
12114
11996
  },
12115
11997
  holds(spelling) {
12116
- return loaded3().holds(spelling);
11998
+ return loaded2().holds(spelling);
12117
11999
  },
12118
12000
  subtractSpellings(ordinal, spellings) {
12119
12001
  uncounted ??= new Uint8Array(documents.count);
12120
12002
  uncounted[ordinal] = 1;
12121
12003
  if (spellings.length === 0) return;
12122
- const target = loaded3();
12004
+ const target = loaded2();
12123
12005
  for (const spelling of spellings) target.subtract(spelling, 1);
12124
12006
  },
12125
12007
  addKeptForms(target, mergedOrdinals, analysis) {
12126
- const source = loaded3();
12008
+ const source = loaded2();
12127
12009
  if (analysis === null) {
12128
12010
  addForms(target, source.serialize());
12129
12011
  return;
@@ -12525,7 +12407,7 @@ function storedFrequenciesOf(source) {
12525
12407
  function buildGeoReaders(entries) {
12526
12408
  const readers = /* @__PURE__ */ new Map();
12527
12409
  for (const entry of entries) {
12528
- const index = createGeoIndex();
12410
+ const index = createLoadedGeoIndex();
12529
12411
  for (let i = 0; i < entry.docIds.length; i++) {
12530
12412
  index.insert(entry.docIds[i], entry.latitudes[i], entry.longitudes[i]);
12531
12413
  }
@@ -12581,6 +12463,7 @@ function assembleFrozenSegment(segmentId, source, documentSource, sharedSnapshot
12581
12463
  sharedSnapshot,
12582
12464
  paged: pagedParts?.access ?? null,
12583
12465
  arrays: source,
12466
+ tombstones,
12584
12467
  invertedIdx: createFrozenInvertedReader(source.tokenTable, postingViews, counts),
12585
12468
  docStore,
12586
12469
  stats: buildStatsView(counts),
@@ -13048,7 +12931,7 @@ function fieldIndexRemapOf(segment, fieldNames) {
13048
12931
  }
13049
12932
  function mergeFieldLengths(inputs, documentCount) {
13050
12933
  const names = [];
13051
- const columns = [];
12934
+ const columns2 = [];
13052
12935
  const totals = {};
13053
12936
  for (const input of inputs) {
13054
12937
  const arrays = input.segment.arrays;
@@ -13059,11 +12942,11 @@ function mergeFieldLengths(inputs, documentCount) {
13059
12942
  if (at < 0) {
13060
12943
  at = names.length;
13061
12944
  names.push(name);
13062
- columns.push(new Uint32Array(documentCount));
12945
+ columns2.push(new Uint32Array(documentCount));
13063
12946
  totals[name] = 0;
13064
12947
  }
13065
12948
  const source = arrays.fieldLengthColumns[f];
13066
- const column = columns[at];
12949
+ const column = columns2[at];
13067
12950
  for (let ordinal = 0; ordinal < source.length; ordinal++) {
13068
12951
  const target = remap[ordinal];
13069
12952
  if (target < 0) continue;
@@ -13072,7 +12955,7 @@ function mergeFieldLengths(inputs, documentCount) {
13072
12955
  }
13073
12956
  }
13074
12957
  }
13075
- return { fieldLengthNames: names, fieldLengthColumns: columns, totalFieldLengths: totals };
12958
+ return { fieldLengthNames: names, fieldLengthColumns: columns2, totalFieldLengths: totals };
13076
12959
  }
13077
12960
  function mergeSurfaceForms2(inputs, analysis) {
13078
12961
  const registry = createSurfaceRegistry();
@@ -13364,7 +13247,7 @@ function indexFilterValue(indexes, ordinal, fieldPath, fieldType, value) {
13364
13247
  for (const entry of fieldType === "enum" ? [value] : value) index.insert(ordinal, entry);
13365
13248
  } else if (fieldType === "geopoint") {
13366
13249
  const point = value;
13367
- indexOf(indexes.geoIndexes, fieldPath, createGeoIndex).insert(ordinal, point.lat, point.lon);
13250
+ indexOf(indexes.geoIndexes, fieldPath, createLoadedGeoIndex).insert(ordinal, point.lat, point.lon);
13368
13251
  }
13369
13252
  }
13370
13253
  function refuseRepeatedDocIds(documents) {
@@ -13515,7 +13398,7 @@ async function attachSegments(entry, action) {
13515
13398
  growPartitionsTo(entry.manager, segment.partitionId);
13516
13399
  const surfaceForms = segment.survivingSurfaceForms;
13517
13400
  const spellings = surfaceForms === void 0 ? void 0 : NO_REMOVED_SPELLINGS;
13518
- const frozen = isPagedSnapshot(segment.snapshot) ? (await import('./module-QT5HZAY4.mjs')).createPagedFrozenSegment(segment.snapshot) : createSharedFrozenSegment(segment.snapshot, surfaceForms);
13401
+ const frozen = isPagedSnapshot(segment.snapshot) ? (await import('./module-LBZPGOWH.mjs')).createPagedFrozenSegment(segment.snapshot) : createSharedFrozenSegment(segment.snapshot, surfaceForms);
13519
13402
  for (const docId of segment.tombstonedDocIds ?? []) frozen.tombstoneDocument(docId, spellings);
13520
13403
  entry.manager.attachFrozenSegment(segment.partitionId, frozen);
13521
13404
  }
@@ -13570,7 +13453,7 @@ function runSegmentAction(entry, action) {
13570
13453
  case "attachSegments":
13571
13454
  return attachSegments(entry, action);
13572
13455
  case "adoptDiskSegments":
13573
- return import('./module-QT5HZAY4.mjs').then((code) => code.adoptSegmentsOnWorker(entry.manager, action));
13456
+ return import('./module-LBZPGOWH.mjs').then((code) => code.adoptSegmentsOnWorker(entry.manager, action));
13574
13457
  case "compactSegments": {
13575
13458
  const partition = requireComposite(entry, action.indexName, action.partitionId, "compact");
13576
13459
  return mergeFrozenSegments(
@@ -13604,47 +13487,6 @@ function runSegmentAction(entry, action) {
13604
13487
  }
13605
13488
  }
13606
13489
 
13607
- // src/workers/vector-code.ts
13608
- var VECTOR_TYPE_NAME = "vector";
13609
- var loaded2 = null;
13610
- var loading2 = null;
13611
- function loadedVectorCode() {
13612
- return loaded2;
13613
- }
13614
- function requireLoadedVectorCode() {
13615
- if (loaded2 === null) throw new Error("The engine reached vector code before it loaded that code");
13616
- return loaded2;
13617
- }
13618
- function loadVectorCode() {
13619
- if (loaded2 !== null) return Promise.resolve(loaded2);
13620
- if (loading2 === null) {
13621
- loading2 = import('./module-S4DKSWMF.mjs').then(
13622
- (code) => {
13623
- loaded2 = code;
13624
- return code;
13625
- },
13626
- (err) => {
13627
- loading2 = null;
13628
- throw err;
13629
- }
13630
- );
13631
- }
13632
- return loading2;
13633
- }
13634
- function mayDeclareVectorField(schema, depth) {
13635
- if (!isPlainObject(schema) || depth > MAX_NESTING_DEPTH + 1) return false;
13636
- for (const type of Object.values(schema)) {
13637
- if (typeof type === "string" ? type.includes(VECTOR_TYPE_NAME) : mayDeclareVectorField(type, depth + 1)) {
13638
- return true;
13639
- }
13640
- }
13641
- return false;
13642
- }
13643
- function loadVectorCodeFor(schema) {
13644
- if (loaded2 !== null || !mayDeclareVectorField(schema, 1)) return null;
13645
- return loadVectorCode();
13646
- }
13647
-
13648
13490
  // src/workers/vector-copies.ts
13649
13491
  function createHeldVectorCopies() {
13650
13492
  return { searchers: /* @__PURE__ */ new Map(), fields: /* @__PURE__ */ new Map(), builds: /* @__PURE__ */ new Map() };
@@ -13850,8 +13692,8 @@ function createDirectExecutor(options) {
13850
13692
  );
13851
13693
  }
13852
13694
  case "createIndex": {
13853
- const loading3 = loadVectorCodeFor(action.config.schema);
13854
- if (loading3 !== null) await loading3;
13695
+ const loading2 = loadSchemaCodeFor(action.config.schema);
13696
+ if (loading2 !== null) await loading2;
13855
13697
  const language = getLanguage(action.config.language ?? "english");
13856
13698
  const manager = addIndex(
13857
13699
  action.indexName,
@@ -14034,7 +13876,7 @@ var TEXT_REBUILD_SWITCH_BACKLOG_DOCUMENTS = 1e3;
14034
13876
  // src/partitioning/rewrite-spill-of.ts
14035
13877
  async function rewriteSpillOf(storage, manager, target) {
14036
13878
  if (storage === void 0 || (target?.config ?? manager.config).textStorage !== "disk") return null;
14037
- const { openRewriteSpill } = await import('./module-QT5HZAY4.mjs');
13879
+ const { openRewriteSpill } = await import('./module-LBZPGOWH.mjs');
14038
13880
  return openRewriteSpill(storage, manager, target);
14039
13881
  }
14040
13882
 
@@ -14124,16 +13966,16 @@ async function rebuildTextIndexes(manager, hooks, target) {
14124
13966
  const partialWordAnalysis = target === void 0 ? manager.partialWordAnalysis : target.partialWordAnalysis;
14125
13967
  const spill = await rewriteSpillOf(hooks.rewriteStorage?.(), manager, target);
14126
13968
  while (hooks.isCurrent()) {
14127
- const log = manager.openWriteLog();
13969
+ const log2 = manager.openWriteLog();
14128
13970
  let swapped = false;
14129
13971
  try {
14130
- swapped = await rebuildOnce({ manager, log, hooks, language, partialWordAnalysis, options, spill });
13972
+ swapped = await rebuildOnce({ manager, log: log2, hooks, language, partialWordAnalysis, options, spill });
14131
13973
  if (swapped) {
14132
13974
  hooks.onRewriteSpill?.(spill);
14133
13975
  return true;
14134
13976
  }
14135
13977
  } finally {
14136
- log.close();
13978
+ log2.close();
14137
13979
  if (!swapped) await spill?.abandon();
14138
13980
  }
14139
13981
  }
@@ -14346,91 +14188,6 @@ function createAnalysisRebuildCoordinator(config, deps) {
14346
14188
  };
14347
14189
  }
14348
14190
 
14349
- // src/engine/durability-config.ts
14350
- var WAL_ONLY_FIELDS = ["directory", "mode", "flushIntervalMs", "segmentMaxBytes", "compactionThreshold"];
14351
- function configError(message) {
14352
- return new NarsilError(ErrorCodes.CONFIG_INVALID, message);
14353
- }
14354
- function requireKnob(name, value, minimum) {
14355
- if (value === void 0) {
14356
- return;
14357
- }
14358
- if (typeof value !== "number" || !Number.isFinite(value) || value < minimum) {
14359
- throw configError(`durability.${name} must be a finite number of at least ${minimum}, got ${String(value)}`);
14360
- }
14361
- }
14362
- function requireValidDurabilityConfig(durability) {
14363
- if (durability.tier !== void 0 && durability.tier !== "wal" && durability.tier !== "snapshot") {
14364
- throw configError(`durability.tier must be "wal" or "snapshot", got "${String(durability.tier)}"`);
14365
- }
14366
- if (durability.mode !== void 0 && durability.mode !== "sync" && durability.mode !== "async") {
14367
- throw configError(`durability.mode must be "sync" or "async", got "${String(durability.mode)}"`);
14368
- }
14369
- requireKnob("checkpointIntervalMs", durability.checkpointIntervalMs, 0);
14370
- requireKnob("checkpointMutationThreshold", durability.checkpointMutationThreshold, 1);
14371
- requireKnob("flushIntervalMs", durability.flushIntervalMs, 0);
14372
- requireKnob("segmentMaxBytes", durability.segmentMaxBytes, 1);
14373
- if (durability.segmentMaxBytes !== void 0 && durability.segmentMaxBytes > MAX_FILE_BYTES) {
14374
- throw configError(
14375
- `durability.segmentMaxBytes must be at most ${MAX_FILE_BYTES}, the largest file that every implementation reads, got ${durability.segmentMaxBytes}`
14376
- );
14377
- }
14378
- requireKnob("compactionThreshold", durability.compactionThreshold, 1);
14379
- if (durability.tier === "snapshot") {
14380
- for (const field of WAL_ONLY_FIELDS) {
14381
- if (durability[field] !== void 0) {
14382
- throw configError(
14383
- `durability.${field} applies to the write-ahead log tier only and cannot combine with durability.tier "snapshot"`
14384
- );
14385
- }
14386
- }
14387
- }
14388
- }
14389
- function filesystemBackedDirectory(config) {
14390
- const adapterDirectory = config.persistence?.directory;
14391
- if (adapterDirectory !== void 0 && adapterDirectory.trim().length > 0) {
14392
- return adapterDirectory;
14393
- }
14394
- return null;
14395
- }
14396
- function resolveDurabilityTier(config) {
14397
- const filesystemDirectory = filesystemBackedDirectory(config);
14398
- if (config.durability) {
14399
- requireValidDurabilityConfig(config.durability);
14400
- }
14401
- if (config.durability?.tier === "snapshot") {
14402
- if (config.persistence === void 0) {
14403
- throw configError(
14404
- "Snapshot durability persists through a persistence adapter. Configure persistence, or remove durability.tier"
14405
- );
14406
- }
14407
- return { kind: "snapshot", config: { ...config.durability }, adapter: config.persistence };
14408
- }
14409
- if (config.durability) {
14410
- if (config.durability.directory !== void 0 && config.durability.directory.trim().length > 0) {
14411
- return { kind: "wal", config: { ...config.durability } };
14412
- }
14413
- if (filesystemDirectory !== null) {
14414
- return { kind: "wal", config: { ...config.durability, directory: filesystemDirectory } };
14415
- }
14416
- if (config.persistence !== void 0) {
14417
- throw configError(
14418
- "WAL durability requires a filesystem directory, but the configured persistence adapter is not filesystem-backed. Use a filesystem persistence adapter or set durability.directory"
14419
- );
14420
- }
14421
- throw configError(
14422
- "Durability requires a directory. Set durability.directory explicitly, or configure a filesystem persistence adapter"
14423
- );
14424
- }
14425
- if (config.persistence === void 0) {
14426
- return null;
14427
- }
14428
- if (filesystemDirectory !== null) {
14429
- return { kind: "wal", config: { directory: filesystemDirectory } };
14430
- }
14431
- return { kind: "snapshot", config: {}, adapter: config.persistence };
14432
- }
14433
-
14434
14191
  // src/engine/array-positions.ts
14435
14192
  function holdsStringArrayField(schema) {
14436
14193
  return schemaFieldsOf(schema).some((field) => field.base === "string[]");
@@ -14722,12 +14479,12 @@ function recoveryFailure(metadata, err) {
14722
14479
  });
14723
14480
  }
14724
14481
  async function createIndexFromMetadata(deps, metadata, loadData) {
14725
- const loadingVectorCode = loadData ? loadVectorCodeFor(metadata.schema) : null;
14726
- if (loadingVectorCode !== null) await loadingVectorCode;
14482
+ const loadingSchemaCode = loadData ? loadSchemaCodeFor(metadata.schema) : null;
14483
+ if (loadingSchemaCode !== null) await loadingSchemaCode;
14727
14484
  const existing = deps.indexRegistry.get(metadata.indexName);
14728
14485
  if (existing !== void 0) {
14729
14486
  if ((metadata.analysisGeneration ?? 0) > existing.analysisGeneration) {
14730
- const { adoptSavedAnalysis } = await import('./analysis-change-EAYO3Y6Q.mjs');
14487
+ const { adoptSavedAnalysis } = await import('./analysis-change-LT5QBQ3H.mjs');
14731
14488
  adoptSavedAnalysis(deps.executor.getManager(metadata.indexName), existing, metadata);
14732
14489
  }
14733
14490
  if (loadData && deps.executor.getManager(metadata.indexName) === void 0) {
@@ -14783,7 +14540,8 @@ async function createIndexFromMetadata(deps, metadata, loadData) {
14783
14540
  analysisGeneration: metadata.analysisGeneration ?? 0,
14784
14541
  pendingAnalysis: metadata.pendingAnalysis ?? null,
14785
14542
  durableAnalysis: null,
14786
- sync: metadata.sync?.enabled === true ? (await import('./sync-state-PASCIHHT.mjs')).syncStateOfMetadata(metadata) : null
14543
+ sync: metadata.sync?.enabled === true ? (await import('./sync-state-PASCIHHT.mjs')).syncStateOfMetadata(metadata) : null,
14544
+ querySuggestions: metadata.querySuggestions ?? null
14787
14545
  });
14788
14546
  if (loadData) await deps.indexState().registerOpen(metadata.indexName);
14789
14547
  else deps.indexState().registerClosed(metadata.indexName);
@@ -16096,10 +15854,10 @@ async function replicateToWorkers(state, action) {
16096
15854
  }
16097
15855
  if (!copiesWillReceive(state, action.indexName)) return;
16098
15856
  const detached = detachCallerDocuments(state, action);
16099
- const loading3 = state.copyLoadBuffers.get(action.indexName);
16100
- if (loading3 !== void 0) {
15857
+ const loading2 = state.copyLoadBuffers.get(action.indexName);
15858
+ if (loading2 !== void 0) {
16101
15859
  queueForCopies(state, detached);
16102
- if (loading3.length % LOAD_BUFFER_YIELD_INTERVAL === 0) await yieldToEventLoop2();
15860
+ if (loading2.length % LOAD_BUFFER_YIELD_INTERVAL === 0) await yieldToEventLoop2();
16103
15861
  return;
16104
15862
  }
16105
15863
  const queue = state.replicationQueues.get(action.indexName);
@@ -16110,9 +15868,9 @@ async function replicateToWorkers(state, action) {
16110
15868
  }
16111
15869
  function queueForCopies(state, action) {
16112
15870
  if (!("indexName" in action)) return;
16113
- const loading3 = state.copyLoadBuffers.get(action.indexName);
16114
- if (loading3 !== void 0) {
16115
- loading3.push(action);
15871
+ const loading2 = state.copyLoadBuffers.get(action.indexName);
15872
+ if (loading2 !== void 0) {
15873
+ loading2.push(action);
16116
15874
  return;
16117
15875
  }
16118
15876
  if (state.workerPool === null || !state.scaledOutIndexes.has(action.indexName)) return;
@@ -16660,7 +16418,7 @@ async function startPool(state) {
16660
16418
  );
16661
16419
  }
16662
16420
  eligibleIndexNames(state);
16663
- const [factory, { createWorkerPool }] = await Promise.all([createWorkerFactory(), import('./pool-RTGXJXPU.mjs')]);
16421
+ const [factory, { createWorkerPool }] = await Promise.all([createWorkerFactory(), import('./pool-JR3NJCAF.mjs')]);
16664
16422
  let started = null;
16665
16423
  const pool = createWorkerPool({
16666
16424
  count: state.keywordWorkerCount + state.longQueryWorkerCount,
@@ -17299,10 +17057,10 @@ function createWorkerOrchestrator(config, executor, indexRegistry, callbacks, ve
17299
17057
  stopRequestThreads: () => stopRequestThreads(state),
17300
17058
  desyncIndex: (indexName) => {
17301
17059
  state.desyncedIndexes.add(indexName);
17302
- const loading3 = state.copyTransitions.get(indexName);
17060
+ const loading2 = state.copyTransitions.get(indexName);
17303
17061
  const wasScaledOut = state.scaledOutIndexes.delete(indexName);
17304
17062
  if (wasScaledOut) withdrawCopies(indexName);
17305
- return wasScaledOut || loading3 !== void 0 && loading3.kind !== "drop";
17063
+ return wasScaledOut || loading2 !== void 0 && loading2.kind !== "drop";
17306
17064
  },
17307
17065
  async releaseIndexCopies(indexName) {
17308
17066
  const hold = state.copyReleaseHolds.get(indexName);
@@ -17351,18 +17109,18 @@ async function emitWriteEventAfter(source, indexName, write) {
17351
17109
  // src/engine/core.ts
17352
17110
  async function createEngineCore(config, hooks, capacityScope = "index") {
17353
17111
  validateWorkerConfig(config?.workers, config?.lifecycle);
17354
- const rerankSettings = config?.rerankTimeout === void 0 && config?.maxRerankWindow === void 0 ? { timeoutMs: DEFAULT_RERANK_TIMEOUT_MS, maxWindow: DEFAULT_MAX_RERANK_WINDOW } : (await import('./runtime-KUATOLYB.mjs')).resolveRerankSettings(config);
17112
+ const rerankSettings = config?.rerankTimeout === void 0 && config?.maxRerankWindow === void 0 ? { timeoutMs: DEFAULT_RERANK_TIMEOUT_MS, maxWindow: DEFAULT_MAX_RERANK_WINDOW } : (await import('./runtime-R5E3TB3J.mjs')).resolveRerankSettings(config);
17355
17113
  const eventHandlers = eventHandlersOf(config?.events);
17356
17114
  const vectorWorkerCount = splitWorkerBudget(resolveWorkerCount(config?.workers?.count)).vector;
17357
17115
  const vectorCopyPolicy = {
17358
17116
  enabled: (config?.workers?.enabled ?? workersEnabledByDefault()) && vectorWorkerCount > 0,
17359
17117
  count: vectorWorkerCount
17360
17118
  };
17361
- const durabilityTier = config !== void 0 ? resolveDurabilityTier(config) : null;
17119
+ const durabilityTier = config !== void 0 && (config.durability || config.persistence !== void 0) ? (await import('./durability-config-QXVZEO7T.mjs')).resolveDurabilityTier(config) : null;
17362
17120
  if (config?.lifecycle !== void 0 && durabilityTier === null) {
17363
17121
  throw new NarsilError(ErrorCodes.CONFIG_INVALID, "Index lifecycle settings require durability");
17364
17122
  }
17365
- const durabilityWiring = durabilityTier === null ? null : await import('./durability-wiring-RRDYJLLM.mjs');
17123
+ const durabilityWiring = durabilityTier === null ? null : await import('./durability-wiring-34OYO32E.mjs');
17366
17124
  const filesystemDurability = durabilityTier?.kind === "wal";
17367
17125
  const executor = createDirectExecutor({
17368
17126
  vectorWorkerCopies: vectorCopyPolicy,
@@ -17548,7 +17306,7 @@ async function createEngineCore(config, hooks, capacityScope = "index") {
17548
17306
  requireManager,
17549
17307
  resumeChange: async (indexName) => {
17550
17308
  if ((indexRegistry.get(indexName)?.pendingAnalysis ?? null) === null) return;
17551
- await (await import('./analysis-change-entry-TNLUC6IZ.mjs')).resumeChangeOf(engineCore, indexName);
17309
+ await (await import('./analysis-change-entry-SCVWK6OU.mjs')).resumeChangeOf(engineCore, indexName);
17552
17310
  },
17553
17311
  onClose: hooks?.onIndexClose,
17554
17312
  onOpen: (indexName) => {
@@ -17611,6 +17369,7 @@ async function createEngineCore(config, hooks, capacityScope = "index") {
17611
17369
  orchestrator,
17612
17370
  rebalanceRouter,
17613
17371
  rebalancingIndexes,
17372
+ restoresInFlight: /* @__PURE__ */ new Map(),
17614
17373
  waqMap,
17615
17374
  guardShutdown,
17616
17375
  requireIndex,
@@ -17635,7 +17394,7 @@ async function startEngineCore(core, config) {
17635
17394
  checkHeapAfterRecovery(core);
17636
17395
  }
17637
17396
  if (core.invalidation) await core.invalidation.start();
17638
- if (core.durability) await (await import('./analysis-change-entry-TNLUC6IZ.mjs')).resumeEveryChange(core);
17397
+ if (core.durability) await (await import('./analysis-change-entry-SCVWK6OU.mjs')).resumeEveryChange(core);
17639
17398
  if (config?.lifecycle === void 0) await core.analysisRebuild.reviewStaleIndexes();
17640
17399
  } catch (err) {
17641
17400
  await core.durability?.manager.shutdown().catch(() => void 0);
@@ -17645,6 +17404,7 @@ async function startEngineCore(core, config) {
17645
17404
  }
17646
17405
  async function shutdownEngine(core) {
17647
17406
  const { executor, durability, indexRegistry, eventHandlers, orchestrator } = core;
17407
+ await core.querySuggestionHooks?.shutdown();
17648
17408
  core.indexState.dispose();
17649
17409
  if (durability) {
17650
17410
  await durability.manager.shutdown();
@@ -17673,7 +17433,7 @@ async function shutdownEngine(core) {
17673
17433
  }
17674
17434
  }
17675
17435
  if (core.rerankAdapters.size > 0) {
17676
- await (await import('./runtime-KUATOLYB.mjs')).shutdownRerankAdapters(core.rerankAdapters);
17436
+ await (await import('./runtime-R5E3TB3J.mjs')).shutdownRerankAdapters(core.rerankAdapters);
17677
17437
  }
17678
17438
  await orchestrator.shutdown();
17679
17439
  await executor.shutdown();
@@ -17681,6 +17441,874 @@ async function shutdownEngine(core) {
17681
17441
  indexRegistry.clear();
17682
17442
  }
17683
17443
 
17444
+ // src/core/keyword-score/layout.ts
17445
+ var TERM_SLOT = 0;
17446
+ var GROUP_SLOT = 1;
17447
+ var PHRASE_SLOT = 2;
17448
+ var SLOT_STRIDE = 4;
17449
+ var SLOT_KIND = 0;
17450
+ var SLOT_TERM = 1;
17451
+ var SLOT_LIST_END = 2;
17452
+ var SLOT_VALUE_END = 3;
17453
+ var LIST_STRIDE = 3;
17454
+ var LIST_FROM_ROWS = 1;
17455
+ var LIST_ORDERED = 2;
17456
+ var LIST_VALUE_STRIDE = 2;
17457
+ var LIST_DOCUMENT_FREQUENCY = 0;
17458
+ var LIST_FACTOR = 0;
17459
+ var LIST_PARTIAL_FACTOR = 1;
17460
+ var FIELD_BOOSTS = 0;
17461
+ var FIELD_AVERAGE_LENGTHS = 1;
17462
+ var FIELD_K1 = 2;
17463
+ var FIELD_B = 3;
17464
+ var FIELD_NUMBER_COLUMNS = 4;
17465
+ var SETTING_SLOTS = 0;
17466
+ var SETTING_TERMS = 1;
17467
+ var SETTING_CAPACITY = 2;
17468
+ var SETTING_TOTAL_DOCUMENTS = 3;
17469
+ var SETTING_TERM_MATCH = 4;
17470
+ var SETTING_ANCHOR = 5;
17471
+ var SETTING_LIMIT = 6;
17472
+ var SETTING_MIN_SCORE = 7;
17473
+ var SETTING_COLLECT = 8;
17474
+ var SETTING_COUNT = 9;
17475
+ var NO_LIMIT = -1;
17476
+ var OUTCOME_COUNT = 0;
17477
+ var OUTCOME_TOTAL_MATCHED = 1;
17478
+ var OUTCOME_LENGTH = 3;
17479
+
17480
+ // src/core/keyword-score/constants.ts
17481
+ var KEYWORD_FIRST_SLOTS = 16;
17482
+ var KEYWORD_FIRST_LISTS = 64;
17483
+ var KEYWORD_FIRST_ROWS = 1024;
17484
+ var KEYWORD_INSERTION_SORT_ROWS = 16;
17485
+
17486
+ // src/core/keyword-score/rows.ts
17487
+ var UNKNOWN_FIELD_RANK = 65536;
17488
+ function rankOf(keys, row) {
17489
+ const field = keys.fields[row];
17490
+ return field < keys.nameRanks.length ? keys.nameRanks[field] : UNKNOWN_FIELD_RANK;
17491
+ }
17492
+ function rowBefore(keys, left, right) {
17493
+ const leftDoc = keys.docIds[left];
17494
+ const rightDoc = keys.docIds[right];
17495
+ if (leftDoc !== rightDoc) return leftDoc < rightDoc;
17496
+ return rankOf(keys, left) < rankOf(keys, right);
17497
+ }
17498
+ function insertionSort(keys, order, from, count) {
17499
+ for (let at = from + 1; at < from + count; at++) {
17500
+ const row = order[at];
17501
+ let to = at;
17502
+ while (to > from && rowBefore(keys, row, order[to - 1])) {
17503
+ order[to] = order[to - 1];
17504
+ to--;
17505
+ }
17506
+ order[to] = row;
17507
+ }
17508
+ }
17509
+ function mergeRuns(keys, source, target, from, middle, end) {
17510
+ let left = from;
17511
+ let right = middle;
17512
+ let out = from;
17513
+ while (left < middle && right < end) {
17514
+ if (rowBefore(keys, source[right], source[left])) target[out++] = source[right++];
17515
+ else target[out++] = source[left++];
17516
+ }
17517
+ while (left < middle) target[out++] = source[left++];
17518
+ while (right < end) target[out++] = source[right++];
17519
+ }
17520
+ function sortRows(keys, order, spare, count) {
17521
+ if (count <= KEYWORD_INSERTION_SORT_ROWS) {
17522
+ insertionSort(keys, order, 0, count);
17523
+ return order;
17524
+ }
17525
+ for (let from = 0; from < count; from += KEYWORD_INSERTION_SORT_ROWS) {
17526
+ insertionSort(keys, order, from, Math.min(KEYWORD_INSERTION_SORT_ROWS, count - from));
17527
+ }
17528
+ let source = order;
17529
+ let target = spare;
17530
+ for (let width = KEYWORD_INSERTION_SORT_ROWS; width < count; width *= 2) {
17531
+ for (let from = 0; from < count; from += 2 * width) {
17532
+ const middle = Math.min(from + width, count);
17533
+ const end = Math.min(from + 2 * width, count);
17534
+ mergeRuns(keys, source, target, from, middle, end);
17535
+ }
17536
+ const held = source;
17537
+ source = target;
17538
+ target = held;
17539
+ }
17540
+ return source;
17541
+ }
17542
+
17543
+ // src/core/partition/keyword-components.ts
17544
+ function holds(bits, ordinal) {
17545
+ const word = ordinal >>> 5;
17546
+ return word < bits.length && (bits[word] >>> (ordinal & 31) & 1) === 1;
17547
+ }
17548
+ function scorable(request, ordinal) {
17549
+ if (!holds(request.live, ordinal) || holds(request.removed, ordinal)) return false;
17550
+ return request.filter === null || holds(request.filter, ordinal);
17551
+ }
17552
+ function rowsOfList(request, list, wanted) {
17553
+ const flags = request.lists[list * LIST_STRIDE];
17554
+ const start = request.lists[list * LIST_STRIDE + 1];
17555
+ const length = request.lists[list * LIST_STRIDE + 2];
17556
+ const fromRows = (flags & LIST_FROM_ROWS) !== 0;
17557
+ const docIds = fromRows ? request.rowDocIds : request.pool.docIds;
17558
+ const keys = {
17559
+ docIds,
17560
+ fields: fromRows ? request.rowFields : request.pool.fields,
17561
+ nameRanks: request.fields.nameRanks
17562
+ };
17563
+ const gathered = /* @__PURE__ */ new Map();
17564
+ for (let row = start; row < start + length; row++) {
17565
+ const ordinal = docIds[row];
17566
+ if (!wanted.has(ordinal)) continue;
17567
+ const rows = gathered.get(ordinal);
17568
+ if (rows === void 0) gathered.set(ordinal, [row]);
17569
+ else rows.push(row);
17570
+ }
17571
+ const byDocument = /* @__PURE__ */ new Map();
17572
+ for (const [ordinal, rows] of gathered) {
17573
+ const order = Uint32Array.from(rows);
17574
+ byDocument.set(ordinal, sortRows(keys, order, new Uint32Array(order.length), order.length));
17575
+ }
17576
+ return { keys, frequencies: fromRows ? request.rowFrequencies : request.pool.frequencies, byDocument };
17577
+ }
17578
+ function componentsOf(found, ordinal) {
17579
+ let held = found.get(ordinal);
17580
+ if (held === void 0) {
17581
+ held = { termFrequencies: {}, fieldLengths: {}, idf: {} };
17582
+ found.set(ordinal, held);
17583
+ }
17584
+ return held;
17585
+ }
17586
+ function lengthIn(request, field, ordinal) {
17587
+ const fieldCount = request.fields.searchable.length;
17588
+ const average = request.fields.numbers[FIELD_AVERAGE_LENGTHS * fieldCount + field];
17589
+ const column = request.fields.lengths[field];
17590
+ const stored = column !== null && ordinal < column.length ? column[ordinal] : 0;
17591
+ return stored > 0 ? stored : average;
17592
+ }
17593
+ function rowScore(request, frequency, idf, field, ordinal) {
17594
+ const fieldCount = request.fields.searchable.length;
17595
+ const numbers = request.fields.numbers;
17596
+ const bm25 = computeBM25WithIDF(
17597
+ frequency,
17598
+ idf,
17599
+ lengthIn(request, field, ordinal),
17600
+ numbers[FIELD_AVERAGE_LENGTHS * fieldCount + field],
17601
+ numbers[FIELD_K1 * fieldCount + field],
17602
+ numbers[FIELD_B * fieldCount + field]
17603
+ );
17604
+ return bm25 * numbers[FIELD_BOOSTS * fieldCount + field];
17605
+ }
17606
+ function searchableField(request, field) {
17607
+ return field < request.fields.searchable.length && request.fields.searchable[field] !== 0;
17608
+ }
17609
+ function record(request, found, names, source, rows, ordinal, label, idf) {
17610
+ for (let at = 0; at < rows.length; at++) {
17611
+ const row = rows[at];
17612
+ const field = source.keys.fields[row];
17613
+ if (!searchableField(request, field)) continue;
17614
+ const components = componentsOf(found, ordinal);
17615
+ const name = names[field];
17616
+ components.termFrequencies[`${name}:${label}`] = source.frequencies[row];
17617
+ components.fieldLengths[name] = lengthIn(request, field, ordinal);
17618
+ components.idf[label] = idf;
17619
+ }
17620
+ }
17621
+ function groupWinners(request, wanted, listFrom, listEnd, idf) {
17622
+ const winners = /* @__PURE__ */ new Map();
17623
+ for (let list = listFrom; list < listEnd; list++) {
17624
+ const factor = request.listValues[list * LIST_VALUE_STRIDE + LIST_FACTOR];
17625
+ const partialFactor = request.listValues[list * LIST_VALUE_STRIDE + LIST_PARTIAL_FACTOR];
17626
+ const source = rowsOfList(request, list, wanted);
17627
+ for (const [ordinal, rows] of source.byDocument) {
17628
+ if (!scorable(request, ordinal)) continue;
17629
+ let sum = 0;
17630
+ const kept = [];
17631
+ for (const row of rows) {
17632
+ const field = source.keys.fields[row];
17633
+ if (!searchableField(request, field)) continue;
17634
+ const rowFactor = request.fields.partialMarks[field] === 1 ? partialFactor : factor;
17635
+ if (!(rowFactor > 0)) continue;
17636
+ sum += rowScore(request, source.frequencies[row], idf, field, ordinal) * rowFactor;
17637
+ kept.push(row);
17638
+ }
17639
+ if (kept.length === 0) continue;
17640
+ const best = winners.get(ordinal);
17641
+ if (best === void 0 || sum > best.sum) winners.set(ordinal, { sum, rows: kept, list, source });
17642
+ }
17643
+ }
17644
+ return winners;
17645
+ }
17646
+ function keywordComponents(request, labels, names, ordinals, count) {
17647
+ const wanted = /* @__PURE__ */ new Set();
17648
+ for (let at = 0; at < count; at++) wanted.add(ordinals[at]);
17649
+ const found = /* @__PURE__ */ new Map();
17650
+ const { slots, settings, listValues, slotValues } = request;
17651
+ const totalDocuments = settings[SETTING_TOTAL_DOCUMENTS];
17652
+ for (let slot = 0; slot < settings[SETTING_SLOTS]; slot++) {
17653
+ const base = slot * SLOT_STRIDE;
17654
+ const listFrom = slot === 0 ? 0 : slots[base - SLOT_STRIDE + SLOT_LIST_END];
17655
+ const listEnd = slots[base + SLOT_LIST_END];
17656
+ const valueFrom = slot === 0 ? 0 : slots[base - SLOT_STRIDE + SLOT_VALUE_END];
17657
+ const valueEnd = slots[base + SLOT_VALUE_END];
17658
+ const kind = slots[base + SLOT_KIND];
17659
+ if (kind === GROUP_SLOT) {
17660
+ const idf = computeIDF(slotValues[valueFrom], totalDocuments);
17661
+ for (const [ordinal, winner] of groupWinners(request, wanted, listFrom, listEnd, idf)) {
17662
+ record(request, found, names, winner.source, winner.rows, ordinal, labels[winner.list], idf);
17663
+ }
17664
+ continue;
17665
+ }
17666
+ let phraseIdf = 0;
17667
+ if (kind === PHRASE_SLOT) {
17668
+ for (let value = valueFrom; value < valueEnd; value++) phraseIdf += computeIDF(slotValues[value], totalDocuments);
17669
+ }
17670
+ for (let list = listFrom; list < listEnd; list++) {
17671
+ const idf = kind === PHRASE_SLOT ? phraseIdf : computeIDF(listValues[list * LIST_VALUE_STRIDE + LIST_DOCUMENT_FREQUENCY], totalDocuments);
17672
+ const source = rowsOfList(request, list, wanted);
17673
+ for (const [ordinal, rows] of source.byDocument) {
17674
+ if (scorable(request, ordinal)) record(request, found, names, source, rows, ordinal, labels[list], idf);
17675
+ }
17676
+ }
17677
+ }
17678
+ return found;
17679
+ }
17680
+
17681
+ // src/core/partition/keyword-fields.ts
17682
+ var columns = {
17683
+ searchable: new Uint8Array(0),
17684
+ partialMarks: new Uint8Array(0),
17685
+ nameRanks: new Uint16Array(0),
17686
+ numbers: new Float64Array(0),
17687
+ lengths: [],
17688
+ rankedNames: null
17689
+ };
17690
+ function sizedFor(fieldCount) {
17691
+ if (columns.searchable.length === fieldCount) return;
17692
+ columns.searchable = new Uint8Array(fieldCount);
17693
+ columns.partialMarks = new Uint8Array(fieldCount);
17694
+ columns.nameRanks = new Uint16Array(fieldCount);
17695
+ columns.numbers = new Float64Array(fieldCount * FIELD_NUMBER_COLUMNS);
17696
+ columns.lengths = new Array(fieldCount).fill(null);
17697
+ columns.rankedNames = null;
17698
+ }
17699
+ function rankNames(names) {
17700
+ if (columns.rankedNames === names) return;
17701
+ const order = names.map((_, index) => index).sort((left, right) => compareCodePoints(names[left], names[right]));
17702
+ for (let rank = 0; rank < order.length; rank++) columns.nameRanks[order[rank]] = rank;
17703
+ columns.rankedNames = names;
17704
+ }
17705
+ function loadKeywordFields(state, fields, boost, averageFieldLengths, bm25, partialFields) {
17706
+ const names = state.fieldNameTable.names;
17707
+ const fieldCount = names.length;
17708
+ sizedFor(fieldCount);
17709
+ rankNames(names);
17710
+ const k1 = bm25?.k1 ?? DEFAULT_BM25_K1;
17711
+ const b = bm25?.b ?? DEFAULT_BM25_B;
17712
+ const perField = bm25?.fields;
17713
+ const { searchable, partialMarks, numbers, lengths } = columns;
17714
+ for (let field = 0; field < fieldCount; field++) {
17715
+ const name = names[field];
17716
+ searchable[field] = fields === void 0 || fields.includes(name) ? 1 : 0;
17717
+ partialMarks[field] = partialFields?.includes(name) ? 1 : 0;
17718
+ numbers[FIELD_BOOSTS * fieldCount + field] = boost?.[name] ?? 1;
17719
+ numbers[FIELD_AVERAGE_LENGTHS * fieldCount + field] = averageFieldLengths[name] ?? 1;
17720
+ const pair = perField !== void 0 && Object.hasOwn(perField, name) ? perField[name] : void 0;
17721
+ numbers[FIELD_K1 * fieldCount + field] = pair?.k1 ?? k1;
17722
+ numbers[FIELD_B * fieldCount + field] = pair?.b ?? b;
17723
+ lengths[field] = state.docStore.fieldLengthColumn(name);
17724
+ }
17725
+ return columns;
17726
+ }
17727
+
17728
+ // src/core/partition/keyword-slots.ts
17729
+ var planned = { labels: [] };
17730
+ function frequencyOf(state, params, token, list) {
17731
+ const stats = params.globalStats;
17732
+ if (stats !== void 0 && Object.hasOwn(stats.docFrequencies, token)) return stats.docFrequencies[token];
17733
+ if (list !== void 0) return list.docIdSet.size;
17734
+ return state.invertedIdx.documentFrequency(token);
17735
+ }
17736
+ function planGroup(state, params, builder2, group, term) {
17737
+ const lookup = (token) => state.invertedIdx.lookup(token);
17738
+ const synonyms = group.synonyms;
17739
+ let documentFrequency = synonyms?.documentFrequency((token) => frequencyOf(state, params, token, void 0)) ?? 0;
17740
+ const members = [];
17741
+ for (const member of group.members) {
17742
+ documentFrequency = Math.max(documentFrequency, frequencyOf(state, params, member.token, void 0));
17743
+ const list = synonyms !== void 0 && member.token === group.token ? synonyms.postings(lookup, member.token) : lookup(member.token);
17744
+ if (list !== void 0)
17745
+ members.push({ token: member.token, factor: member.factor, partialFactor: member.partialFactor, list });
17746
+ }
17747
+ builder2.groupSlot(term, documentFrequency);
17748
+ for (const member of members) {
17749
+ builder2.memberList(member.list, member.factor, member.partialFactor);
17750
+ planned.labels.push(member.token);
17751
+ }
17752
+ }
17753
+ function planPhrases(state, params, builder2, phraseMatches) {
17754
+ for (const rows of phraseMatches.rows) {
17755
+ const frequencies = rows.phrase.tokens.map((token, at) => frequencyOf(state, params, token, rows.lists[at]));
17756
+ builder2.phraseSlot(frequencies, {
17757
+ docIds: rows.docIds.values,
17758
+ fields: rows.fieldIndices.values,
17759
+ frequencies: rows.frequencies.values,
17760
+ count: rows.docIds.length
17761
+ });
17762
+ planned.labels.push(rows.phrase.key);
17763
+ }
17764
+ }
17765
+ function planKeywordSlots(state, params, builder2, phraseMatches) {
17766
+ planned.labels.length = 0;
17767
+ const { queryTokens, termGroups } = params;
17768
+ for (let term = 0; term < queryTokens.length; term++) {
17769
+ const token = queryTokens[term].token;
17770
+ const group = termGroupOf(termGroups, token);
17771
+ const matches = typoMatchesFor(
17772
+ state.invertedIdx,
17773
+ token,
17774
+ group,
17775
+ params.exact ?? false,
17776
+ params.tolerance ?? 0,
17777
+ params.prefixLength ?? 2
17778
+ );
17779
+ builder2.termSlot(term);
17780
+ for (const match of matches) {
17781
+ builder2.termList(match.postingList, frequencyOf(state, params, match.token, match.postingList));
17782
+ planned.labels.push(match.token);
17783
+ }
17784
+ if (group !== void 0) planGroup(state, params, builder2, group, term);
17785
+ }
17786
+ if (phraseMatches !== null) planPhrases(state, params, builder2, phraseMatches);
17787
+ return planned;
17788
+ }
17789
+
17790
+ // src/core/keyword-score/request.ts
17791
+ var EMPTY_POOL = {
17792
+ docIds: new Uint32Array(0),
17793
+ frequencies: new Uint16Array(0),
17794
+ fields: new Uint16Array(0)
17795
+ };
17796
+ function grown(values, needed) {
17797
+ if (values.length >= needed) return values;
17798
+ const sized = new values.constructor(Math.max(needed, values.length * 2));
17799
+ sized.set(values);
17800
+ return sized;
17801
+ }
17802
+ function sharesPool(column, pooled, start) {
17803
+ if (!(column instanceof Uint32Array || column instanceof Uint16Array)) return false;
17804
+ if (column.buffer !== pooled.buffer || column.BYTES_PER_ELEMENT !== pooled.BYTES_PER_ELEMENT) return false;
17805
+ return column.byteOffset - pooled.byteOffset === start * pooled.BYTES_PER_ELEMENT;
17806
+ }
17807
+ var KeywordRequestBuilder = class {
17808
+ pool = EMPTY_POOL;
17809
+ slots = new Uint32Array(KEYWORD_FIRST_SLOTS * SLOT_STRIDE);
17810
+ slotCount = 0;
17811
+ lists = new Uint32Array(KEYWORD_FIRST_LISTS * LIST_STRIDE);
17812
+ listCount = 0;
17813
+ listValues = new Float64Array(KEYWORD_FIRST_LISTS * LIST_VALUE_STRIDE);
17814
+ slotValues = new Float64Array(KEYWORD_FIRST_SLOTS);
17815
+ valueCount = 0;
17816
+ rowDocIds = new Uint32Array(KEYWORD_FIRST_ROWS);
17817
+ rowFrequencies = new Float64Array(KEYWORD_FIRST_ROWS);
17818
+ rowFields = new Uint16Array(KEYWORD_FIRST_ROWS);
17819
+ rowCount = 0;
17820
+ settings = new Float64Array(SETTING_COUNT);
17821
+ begin(pool) {
17822
+ this.pool = pool ?? EMPTY_POOL;
17823
+ this.slotCount = 0;
17824
+ this.listCount = 0;
17825
+ this.valueCount = 0;
17826
+ this.rowCount = 0;
17827
+ }
17828
+ release() {
17829
+ this.pool = EMPTY_POOL;
17830
+ }
17831
+ get slotsWritten() {
17832
+ return this.slotCount;
17833
+ }
17834
+ termSlot(term) {
17835
+ this.openSlot(TERM_SLOT, term);
17836
+ }
17837
+ groupSlot(term, documentFrequency) {
17838
+ this.openSlot(GROUP_SLOT, term);
17839
+ this.pushSlotValue(documentFrequency);
17840
+ }
17841
+ phraseSlot(documentFrequencies, rows) {
17842
+ this.openSlot(PHRASE_SLOT, 0);
17843
+ for (const frequency of documentFrequencies) this.pushSlotValue(frequency);
17844
+ const start = this.reserveRows(rows.count);
17845
+ let ordered = true;
17846
+ for (let row = 0; row < rows.count; row++) {
17847
+ const at = start + row;
17848
+ this.rowDocIds[at] = rows.docIds[row];
17849
+ this.rowFields[at] = rows.fields[row];
17850
+ this.rowFrequencies[at] = rows.frequencies[row];
17851
+ if (row > 0 && this.rowDocIds[at] < this.rowDocIds[at - 1]) ordered = false;
17852
+ }
17853
+ this.pushList(LIST_FROM_ROWS | (ordered ? LIST_ORDERED : 0), start, rows.count, 0, 0);
17854
+ }
17855
+ termList(list, documentFrequency) {
17856
+ this.addList(list, documentFrequency, 0);
17857
+ }
17858
+ memberList(list, factor, partialFactor) {
17859
+ this.addList(list, factor, partialFactor);
17860
+ }
17861
+ request(scope, selection) {
17862
+ const settings = this.settings;
17863
+ settings[SETTING_SLOTS] = this.slotCount;
17864
+ settings[SETTING_TERMS] = selection.terms;
17865
+ settings[SETTING_CAPACITY] = scope.capacity;
17866
+ settings[SETTING_TOTAL_DOCUMENTS] = selection.totalDocuments;
17867
+ settings[SETTING_TERM_MATCH] = selection.termMatch;
17868
+ settings[SETTING_ANCHOR] = selection.anchor;
17869
+ settings[SETTING_LIMIT] = selection.limit;
17870
+ settings[SETTING_MIN_SCORE] = selection.minScore;
17871
+ settings[SETTING_COLLECT] = selection.collect ? 1 : 0;
17872
+ return {
17873
+ pool: this.pool,
17874
+ rowDocIds: this.rowDocIds,
17875
+ rowFrequencies: this.rowFrequencies,
17876
+ rowFields: this.rowFields,
17877
+ slots: this.slots,
17878
+ lists: this.lists,
17879
+ listValues: this.listValues,
17880
+ slotValues: this.slotValues,
17881
+ fields: scope.fields,
17882
+ filter: scope.filter,
17883
+ live: scope.live,
17884
+ removed: scope.removed,
17885
+ settings
17886
+ };
17887
+ }
17888
+ openSlot(kind, term) {
17889
+ this.slots = grown(this.slots, (this.slotCount + 1) * SLOT_STRIDE);
17890
+ const base = this.slotCount * SLOT_STRIDE;
17891
+ this.slots[base + SLOT_KIND] = kind;
17892
+ this.slots[base + SLOT_TERM] = term;
17893
+ this.slots[base + SLOT_LIST_END] = this.listCount;
17894
+ this.slots[base + SLOT_VALUE_END] = this.valueCount;
17895
+ this.slotCount++;
17896
+ }
17897
+ pushSlotValue(value) {
17898
+ this.slotValues = grown(this.slotValues, this.valueCount + 1);
17899
+ this.slotValues[this.valueCount++] = value;
17900
+ this.slots[(this.slotCount - 1) * SLOT_STRIDE + SLOT_VALUE_END] = this.valueCount;
17901
+ }
17902
+ pushList(flags, start, length, first, second) {
17903
+ this.lists = grown(this.lists, (this.listCount + 1) * LIST_STRIDE);
17904
+ this.listValues = grown(this.listValues, (this.listCount + 1) * LIST_VALUE_STRIDE);
17905
+ const base = this.listCount * LIST_STRIDE;
17906
+ this.lists[base] = flags;
17907
+ this.lists[base + 1] = start;
17908
+ this.lists[base + 2] = length;
17909
+ this.listValues[this.listCount * LIST_VALUE_STRIDE] = first;
17910
+ this.listValues[this.listCount * LIST_VALUE_STRIDE + 1] = second;
17911
+ this.listCount++;
17912
+ this.slots[(this.slotCount - 1) * SLOT_STRIDE + SLOT_LIST_END] = this.listCount;
17913
+ }
17914
+ reserveRows(count) {
17915
+ const start = this.rowCount;
17916
+ const needed = start + count;
17917
+ this.rowDocIds = grown(this.rowDocIds, needed);
17918
+ this.rowFrequencies = grown(this.rowFrequencies, needed);
17919
+ this.rowFields = grown(this.rowFields, needed);
17920
+ this.rowCount = needed;
17921
+ return start;
17922
+ }
17923
+ addList(list, first, second) {
17924
+ const docIds = list.docIds;
17925
+ const frequencies = list.termFrequencies;
17926
+ const fields = list.fieldNameIndices;
17927
+ const length = Math.min(list.length, docIds.length, frequencies.length, fields.length);
17928
+ const orderedFlag = list.ordered ? LIST_ORDERED : 0;
17929
+ const pool = this.pool;
17930
+ if (docIds instanceof Uint32Array && docIds.buffer === pool.docIds.buffer) {
17931
+ const start2 = (docIds.byteOffset - pool.docIds.byteOffset) / Uint32Array.BYTES_PER_ELEMENT;
17932
+ if (Number.isInteger(start2) && start2 >= 0 && start2 + length <= pool.docIds.length && start2 + length <= pool.frequencies.length && start2 + length <= pool.fields.length && sharesPool(frequencies, pool.frequencies, start2) && sharesPool(fields, pool.fields, start2)) {
17933
+ this.pushList(orderedFlag, start2, length, first, second);
17934
+ return;
17935
+ }
17936
+ }
17937
+ const start = this.reserveRows(length);
17938
+ for (let row = 0; row < length; row++) {
17939
+ this.rowDocIds[start + row] = docIds[row];
17940
+ this.rowFrequencies[start + row] = frequencies[row];
17941
+ this.rowFields[start + row] = fields[row];
17942
+ }
17943
+ this.pushList(LIST_FROM_ROWS | orderedFlag, start, length, first, second);
17944
+ }
17945
+ };
17946
+
17947
+ // src/core/keyword-score/segment-storage.ts
17948
+ var bitsByTombstones = /* @__PURE__ */ new WeakMap();
17949
+ function isFrozenSegment(state) {
17950
+ return "tombstones" in state && "arrays" in state && "paged" in state;
17951
+ }
17952
+ function tombstoneBits(tombstones) {
17953
+ let held = bitsByTombstones.get(tombstones);
17954
+ if (held === void 0) {
17955
+ held = { bits: new Uint32Array(0), read: 0 };
17956
+ bitsByTombstones.set(tombstones, held);
17957
+ }
17958
+ for (; held.read < tombstones.size; held.read++) {
17959
+ const ordinal = tombstones.at(held.read);
17960
+ const word = ordinal >>> 5;
17961
+ if (word >= held.bits.length) {
17962
+ const grown2 = new Uint32Array(Math.max(word + 1, held.bits.length * 2));
17963
+ grown2.set(held.bits);
17964
+ held.bits = grown2;
17965
+ }
17966
+ held.bits[word] |= 1 << (ordinal & 31);
17967
+ }
17968
+ return held.bits;
17969
+ }
17970
+ function segmentStorageOf(state) {
17971
+ if (isFrozenSegment(state)) {
17972
+ const { arrays } = state;
17973
+ const pool2 = state.paged === null ? { docIds: arrays.postingDocIds, frequencies: arrays.postingFrequencies, fields: arrays.postingFieldIndices } : null;
17974
+ return { pool: pool2, removed: tombstoneBits(state.tombstones) };
17975
+ }
17976
+ const postings = state.invertedIdx.livePostings;
17977
+ if (postings === void 0) return null;
17978
+ const { pool } = postings;
17979
+ return {
17980
+ pool: { docIds: pool.docIds, frequencies: pool.frequencies, fields: pool.fieldIndices },
17981
+ removed: postings.retired
17982
+ };
17983
+ }
17984
+
17985
+ // src/core/keyword-score/native.ts
17986
+ var TERM_MATCH_LEFT_TO_THE_CALLER = 0;
17987
+ var NO_MINIMUM_SCORE = 0;
17988
+ var FIRST_TERM_ANCHOR = 0;
17989
+ var builder = new KeywordRequestBuilder();
17990
+ var output = {
17991
+ ordinals: new Int32Array(0),
17992
+ scores: new Float64Array(0),
17993
+ matched: new Uint32Array(0),
17994
+ outcome: new Float64Array(OUTCOME_LENGTH)
17995
+ };
17996
+ var everyOrdinal = new Uint32Array(0);
17997
+ function outputFor(capacity) {
17998
+ if (output.ordinals.length < capacity) {
17999
+ output.ordinals = new Int32Array(capacity);
18000
+ output.scores = new Float64Array(capacity);
18001
+ output.matched = new Uint32Array(capacity + 31 >>> 5);
18002
+ }
18003
+ return output;
18004
+ }
18005
+ function everyOrdinalBelow(capacity) {
18006
+ const words = capacity + 31 >>> 5;
18007
+ if (everyOrdinal.length < words) everyOrdinal = new Uint32Array(Math.max(words, everyOrdinal.length * 2)).fill(-1);
18008
+ return everyOrdinal;
18009
+ }
18010
+ function scoredByTheCore(core, request, written) {
18011
+ const { pool, fields } = request;
18012
+ const status = core.keywordScore(
18013
+ pool.docIds,
18014
+ pool.frequencies,
18015
+ pool.fields,
18016
+ request.rowDocIds,
18017
+ request.rowFrequencies,
18018
+ request.rowFields,
18019
+ request.slots,
18020
+ request.lists,
18021
+ request.listValues,
18022
+ request.slotValues,
18023
+ fields.searchable,
18024
+ fields.partialMarks,
18025
+ fields.nameRanks,
18026
+ fields.numbers,
18027
+ fields.lengths,
18028
+ request.filter,
18029
+ request.live,
18030
+ request.removed,
18031
+ request.settings,
18032
+ written.ordinals,
18033
+ written.scores,
18034
+ written.matched,
18035
+ written.outcome
18036
+ );
18037
+ if (status === NATIVE_OK) return true;
18038
+ noteFallback("keywordScore");
18039
+ return false;
18040
+ }
18041
+ function byScoreThenId(left, right) {
18042
+ if (left.score !== right.score) return left.score > right.score ? -1 : 1;
18043
+ return compareCodePoints(left.docId, right.docId);
18044
+ }
18045
+ function pageOf(state, written, count, maxResults, components) {
18046
+ const resolver = state.docStore.resolver();
18047
+ const page = [];
18048
+ for (let at = 0; at < count; at++) {
18049
+ const ordinal = written.ordinals[at];
18050
+ const docId = resolver.toExternal(ordinal);
18051
+ if (docId === void 0) continue;
18052
+ const record2 = components?.get(ordinal);
18053
+ page.push({
18054
+ docId,
18055
+ score: written.scores[at],
18056
+ termFrequencies: record2?.termFrequencies ?? EMPTY_COMPONENTS,
18057
+ fieldLengths: record2?.fieldLengths ?? EMPTY_COMPONENTS,
18058
+ idf: record2?.idf ?? EMPTY_COMPONENTS
18059
+ });
18060
+ }
18061
+ page.sort(byScoreThenId);
18062
+ if (maxResults !== void 0 && page.length > maxResults) page.length = Math.max(0, Math.floor(maxResults));
18063
+ return page;
18064
+ }
18065
+ function matchedIdsOf(state, matched, capacity) {
18066
+ const resolver = state.docStore.resolver();
18067
+ const ids = [];
18068
+ const words = Math.min(matched.length, capacity + 31 >>> 5);
18069
+ for (let word = 0; word < words; word++) {
18070
+ let bits = matched[word];
18071
+ while (bits !== 0) {
18072
+ const low = bits & -bits;
18073
+ const ordinal = word * 32 + (31 - Math.clz32(low));
18074
+ const docId = resolver.toExternal(ordinal);
18075
+ if (docId !== void 0) ids.push(docId);
18076
+ bits ^= low;
18077
+ }
18078
+ }
18079
+ return ids;
18080
+ }
18081
+ function plannedRequest(state, params, phraseMatches, storage, capacity) {
18082
+ const { queryTokens, globalStats, maxResults } = params;
18083
+ const fields = loadKeywordFields(
18084
+ state,
18085
+ params.fields,
18086
+ params.boost,
18087
+ globalStats?.averageFieldLengths ?? state.stats.averageFieldLengths,
18088
+ params.bm25Params,
18089
+ params.partialFields
18090
+ );
18091
+ builder.begin(storage.pool);
18092
+ const planned2 = planKeywordSlots(state, params, builder, phraseMatches);
18093
+ const request = builder.request(
18094
+ {
18095
+ fields,
18096
+ filter: phraseMatches?.matched ?? params.filterBitset ?? null,
18097
+ live: everyOrdinalBelow(capacity),
18098
+ removed: storage.removed,
18099
+ capacity
18100
+ },
18101
+ {
18102
+ terms: queryTokens.length,
18103
+ totalDocuments: globalStats?.totalDocuments ?? state.stats.totalDocuments,
18104
+ termMatch: TERM_MATCH_LEFT_TO_THE_CALLER,
18105
+ anchor: FIRST_TERM_ANCHOR,
18106
+ limit: maxResults === void 0 ? NO_LIMIT : Math.max(0, Math.floor(maxResults)),
18107
+ minScore: NO_MINIMUM_SCORE,
18108
+ collect: params.collectMatchedSet !== void 0
18109
+ }
18110
+ );
18111
+ return { request, labels: planned2.labels };
18112
+ }
18113
+ function searchInTheCore(state, params, phraseMatches) {
18114
+ if (!nativeSearchCoreIsEnabled()) return null;
18115
+ const core = loadNativeCore();
18116
+ if (core === null) return null;
18117
+ const storage = segmentStorageOf(state);
18118
+ if (storage === null) return null;
18119
+ const capacity = state.docStore.internalIdCapacity();
18120
+ const written = outputFor(capacity);
18121
+ const components = componentsScoredByTheCore(core, state, params, phraseMatches, storage, capacity, written);
18122
+ if (components === void 0) return null;
18123
+ const totalMatched = written.outcome[OUTCOME_TOTAL_MATCHED];
18124
+ const scored = pageOf(state, written, written.outcome[OUTCOME_COUNT], params.maxResults, components);
18125
+ const result = params.collectMatchedSet === void 0 ? { scored, totalMatched } : params.collectMatchedSet === "ordinals" ? { scored, totalMatched, matchedOrdinalBitset: written.matched.slice(0, capacity + 31 >>> 5 || 1) } : { scored, totalMatched, matchedIds: matchedIdsOf(state, written.matched, capacity) };
18126
+ return result;
18127
+ }
18128
+ function componentsScoredByTheCore(core, state, params, phraseMatches, storage, capacity, written) {
18129
+ try {
18130
+ const { request, labels } = plannedRequest(state, params, phraseMatches, storage, capacity);
18131
+ if (!scoredByTheCore(core, request, written)) return void 0;
18132
+ if (params.collectComponents === false) return null;
18133
+ const count = written.outcome[OUTCOME_COUNT];
18134
+ return keywordComponents(request, labels, state.fieldNameTable.names, written.ordinals, count);
18135
+ } finally {
18136
+ builder.release();
18137
+ }
18138
+ }
18139
+
18140
+ // src/core/tokenizer/native-analysis.ts
18141
+ var STEM_FLAG = 1;
18142
+ var REMOVE_STOP_WORDS_FLAG = 2;
18143
+ var REMOVE_DIACRITICS_FLAG = 4;
18144
+ var COLLECT_SURFACES_FLAG = 8;
18145
+ var SPELLINGS_FLAG = 16;
18146
+ var TOKEN_RECORD_WORDS = 8;
18147
+ var NO_SURFACE = 4294967295;
18148
+ var COPY_PREFIX = " ";
18149
+ var coreOfNames = null;
18150
+ var indexByName = /* @__PURE__ */ new Map();
18151
+ var languagesOfCore = /* @__PURE__ */ new WeakMap();
18152
+ var heldStopWords = /* @__PURE__ */ new WeakMap();
18153
+ var sharedRecords = new Uint32Array(1 + NATIVE_ANALYSIS_FIRST_TOKEN_RECORDS * TOKEN_RECORD_WORDS);
18154
+ var recordsInUse = false;
18155
+ var termsBySlot = null;
18156
+ function activeCore() {
18157
+ if (!nativeSearchCoreIsEnabled()) return null;
18158
+ const core = loadNativeCore();
18159
+ if (core === null) return null;
18160
+ if (core !== coreOfNames) {
18161
+ coreOfNames = core;
18162
+ indexByName = /* @__PURE__ */ new Map();
18163
+ languagesOfCore = /* @__PURE__ */ new WeakMap();
18164
+ heldStopWords = /* @__PURE__ */ new WeakMap();
18165
+ termsBySlot = null;
18166
+ const count = core.languageCount();
18167
+ for (let index = 0; index < count; index++) indexByName.set(core.languageName(index), index);
18168
+ }
18169
+ return core;
18170
+ }
18171
+ function stringsOf(words) {
18172
+ const strings = [];
18173
+ for (const word of words) if (typeof word === "string") strings.push(word);
18174
+ return strings;
18175
+ }
18176
+ function holdsTheCoreList(core, index, words) {
18177
+ const coreWords = core.languageStopWords(index);
18178
+ if (coreWords.length !== words.size) return false;
18179
+ for (const word of coreWords) if (!words.has(word)) return false;
18180
+ return true;
18181
+ }
18182
+ function coreLanguageOf(core, module) {
18183
+ const known = languagesOfCore.get(module);
18184
+ if (known !== void 0) return known;
18185
+ const index = indexByName.get(module.name);
18186
+ let language = null;
18187
+ if (index !== void 0 && core.languageRevision(index) === module.revision) {
18188
+ const moduleStopWords = holdsTheCoreList(core, index, module.stopWords) ? null : core.createStopWordSet(stringsOf(module.stopWords));
18189
+ language = { index, moduleStopWords };
18190
+ }
18191
+ languagesOfCore.set(module, language);
18192
+ return language;
18193
+ }
18194
+ function holdsTheSameWords(held, words) {
18195
+ let strings = 0;
18196
+ for (const word of words) {
18197
+ if (typeof word !== "string") continue;
18198
+ if (!held.has(word)) return false;
18199
+ strings++;
18200
+ }
18201
+ return strings === held.size;
18202
+ }
18203
+ function heldSetFor(core, owner, words) {
18204
+ const held = heldStopWords.get(owner);
18205
+ if (held !== void 0 && holdsTheSameWords(held.words, words)) return held.handle;
18206
+ const strings = stringsOf(words);
18207
+ const handle = core.createStopWordSet(strings);
18208
+ heldStopWords.set(owner, { handle, words: new Set(strings) });
18209
+ return handle;
18210
+ }
18211
+ function stopWordsFor(core, language, module, override) {
18212
+ if (!override) return language.moduleStopWords;
18213
+ const words = override instanceof Set ? override : override(module.stopWords);
18214
+ if (words === module.stopWords) return language.moduleStopWords;
18215
+ return heldSetFor(core, override, words);
18216
+ }
18217
+ function analyseWith(core, index, flags, text, stopWords) {
18218
+ let records = recordsInUse ? new Uint32Array(sharedRecords.length) : sharedRecords;
18219
+ let result = core.analyse(index, flags, text, stopWords, records);
18220
+ if (result === null) {
18221
+ records = new Uint32Array(1 + records[0] * TOKEN_RECORD_WORDS);
18222
+ if (!recordsInUse) sharedRecords = records;
18223
+ result = core.analyse(index, flags, text, stopWords, records);
18224
+ }
18225
+ if (typeof result !== "string") {
18226
+ noteFallback("analyse");
18227
+ return null;
18228
+ }
18229
+ return { arena: result, records };
18230
+ }
18231
+ function holdsUnits(held, arena, start, length) {
18232
+ if (held.length !== length) return false;
18233
+ for (let unit = 0; unit < length; unit++) {
18234
+ if (held.charCodeAt(unit) !== arena.charCodeAt(start + unit)) return false;
18235
+ }
18236
+ return true;
18237
+ }
18238
+ function termOf(arena, start, length, slot) {
18239
+ if (slot >= NATIVE_ANALYSIS_HELD_TERMS) return arena.substring(start, start + length);
18240
+ if (termsBySlot === null) termsBySlot = new Array(NATIVE_ANALYSIS_HELD_TERMS);
18241
+ const held = termsBySlot[slot];
18242
+ if (held !== void 0 && holdsUnits(held, arena, start, length)) return held;
18243
+ const term = (COPY_PREFIX + arena.substring(start, start + length)).slice(COPY_PREFIX.length);
18244
+ termsBySlot[slot] = term;
18245
+ return term;
18246
+ }
18247
+ function visitRecords(analysed, visit) {
18248
+ const { arena, records } = analysed;
18249
+ const count = records[0];
18250
+ const ownsShared = records === sharedRecords;
18251
+ if (ownsShared) recordsInUse = true;
18252
+ try {
18253
+ for (let token = 0, at = 1; token < count; token++, at += TOKEN_RECORD_WORDS) {
18254
+ const surfaceStart = records[at + 3];
18255
+ const originalStart = records[at + 5];
18256
+ visit(
18257
+ termOf(arena, records[at + 1], records[at + 2], records[at + 7]),
18258
+ records[at],
18259
+ surfaceStart === NO_SURFACE ? void 0 : arena.substring(surfaceStart, surfaceStart + records[at + 4]),
18260
+ arena.substring(originalStart, originalStart + records[at + 6])
18261
+ );
18262
+ }
18263
+ } finally {
18264
+ if (ownsShared) recordsInUse = false;
18265
+ }
18266
+ }
18267
+ function visitTokens2(text, language, options, visit) {
18268
+ const core = activeCore();
18269
+ if (core === null) return false;
18270
+ const coreLanguage = coreLanguageOf(core, language);
18271
+ if (coreLanguage === null) return false;
18272
+ const removeStopWords = options?.removeStopWords ?? true;
18273
+ const flags = (options?.stem ?? true ? STEM_FLAG : 0) | (removeStopWords ? REMOVE_STOP_WORDS_FLAG : 0) | (options?.removeDiacritics === true ? REMOVE_DIACRITICS_FLAG : 0) | (options?.collectSurfaces === true ? COLLECT_SURFACES_FLAG : 0);
18274
+ const stopWords = removeStopWords ? stopWordsFor(core, coreLanguage, language, options?.stopWordOverride) : null;
18275
+ const analysed = analyseWith(core, coreLanguage.index, flags, text, stopWords);
18276
+ if (analysed === null) return false;
18277
+ visitRecords(analysed, visit);
18278
+ return true;
18279
+ }
18280
+ function visitSpellings(text, language, visit) {
18281
+ const core = activeCore();
18282
+ if (core === null) return false;
18283
+ const coreLanguage = coreLanguageOf(core, language);
18284
+ if (coreLanguage === null) return false;
18285
+ const analysed = analyseWith(core, coreLanguage.index, SPELLINGS_FLAG, text, null);
18286
+ if (analysed === null) return false;
18287
+ visitRecords(analysed, (spelling) => visit(spelling));
18288
+ return true;
18289
+ }
18290
+ function transform(raw, language, stem, removeDiacritics) {
18291
+ const core = activeCore();
18292
+ if (core === null) return null;
18293
+ const coreLanguage = coreLanguageOf(core, language);
18294
+ if (coreLanguage === null) return null;
18295
+ const result = core.transform(
18296
+ coreLanguage.index,
18297
+ (stem ? STEM_FLAG : 0) | (removeDiacritics ? REMOVE_DIACRITICS_FLAG : 0),
18298
+ raw
18299
+ );
18300
+ if (typeof result === "string") return result;
18301
+ noteFallback("analyse");
18302
+ return null;
18303
+ }
18304
+ var nativeCoreAnalysis = { visitTokens: visitTokens2, visitSpellings, transform };
18305
+
18306
+ // src/engine/search-backend-settings.react-native.ts
18307
+ function requireSearchBackendSettings() {
18308
+ installNativeAnalysis(nativeCoreAnalysis);
18309
+ installNativeKeywordSearch(searchInTheCore);
18310
+ }
18311
+
17684
18312
  // src/engine/startup-checks.ts
17685
18313
  var announcedMissingWorkerEntry = false;
17686
18314
  function withoutWorkers(config, reason) {
@@ -17693,6 +18321,7 @@ function withoutWorkers(config, reason) {
17693
18321
  return { ...config, workers: { ...config?.workers, enabled: false } };
17694
18322
  }
17695
18323
  async function resolveRunnableConfig(config) {
18324
+ requireSearchBackendSettings();
17696
18325
  if (!(config?.workers?.enabled ?? workersEnabledByDefault())) return config;
17697
18326
  const runtime = detectRuntime();
17698
18327
  if (!runtime.supportsWorkerThreads && !runtime.supportsWebWorkers) return config;
@@ -17849,7 +18478,8 @@ function indexConfigurationOf(entry) {
17849
18478
  synonyms,
17850
18479
  entry.analysisGeneration
17851
18480
  );
17852
- return entry.sync === null ? payload : { ...payload, syncEpoch: entry.sync.epoch };
18481
+ const withSuggestions = { ...payload, ...entry.querySuggestions };
18482
+ return entry.sync === null ? withSuggestions : { ...withSuggestions, syncEpoch: entry.sync.epoch };
17853
18483
  }
17854
18484
  function requireConfigurationWithinSizeLimit(config, language) {
17855
18485
  const adapter = config.embedding?.adapter;
@@ -17936,8 +18566,8 @@ async function announceIndexDropped(core, name, config) {
17936
18566
  }
17937
18567
  async function createEngineIndex(core, config, name, requestedConfig, creation = {}) {
17938
18568
  const { indexUuid, adapterBinding = "required", appliesCreationLimits = false } = creation;
17939
- const loadingVectorCode = loadVectorCodeFor(requestedConfig.schema);
17940
- if (loadingVectorCode !== null) await loadingVectorCode;
18569
+ const loadingSchemaCode = loadSchemaCodeFor(requestedConfig.schema);
18570
+ if (loadingSchemaCode !== null) await loadingSchemaCode;
17941
18571
  core.guardShutdown();
17942
18572
  validateIndexName(name);
17943
18573
  if (core.indexRegistry.has(name)) {
@@ -18016,6 +18646,7 @@ async function createEngineIndex(core, config, name, requestedConfig, creation =
18016
18646
  const language = getLanguage(indexConfig.language ?? "english");
18017
18647
  if (appliesCreationLimits) requireConfigurationWithinSizeLimit(indexConfig, language);
18018
18648
  const synonyms = prepareConfiguredSynonyms(configured, language, appliesCreationLimits);
18649
+ await core.querySuggestionHooks?.beforeCreate(name);
18019
18650
  core.executor.createIndex(name, indexConfig, language, false, synonyms?.lookup ?? null);
18020
18651
  core.indexRegistry.set(name, {
18021
18652
  config: indexConfig,
@@ -18033,7 +18664,8 @@ async function createEngineIndex(core, config, name, requestedConfig, creation =
18033
18664
  analysisGeneration: 0,
18034
18665
  pendingAnalysis: null,
18035
18666
  durableAnalysis: null,
18036
- sync: null
18667
+ sync: null,
18668
+ querySuggestions: creation.querySuggestions ?? null
18037
18669
  });
18038
18670
  await core.indexState.registerOpen(name);
18039
18671
  if (core.durability) {
@@ -18046,10 +18678,11 @@ async function dropEngineIndex(core, name) {
18046
18678
  const entry = core.requireIndex(name);
18047
18679
  const changeRecorded = () => entry.pendingAnalysis !== null || entry.durableAnalysis !== null;
18048
18680
  const abandonChange = async () => {
18049
- await (await import('./analysis-change-entry-TNLUC6IZ.mjs')).abandonChangeOf(core, name);
18681
+ await (await import('./analysis-change-entry-SCVWK6OU.mjs')).abandonChangeOf(core, name);
18050
18682
  };
18051
18683
  if (changeRecorded()) await abandonChange();
18052
18684
  await core.indexState.drop(name, async () => {
18685
+ await core.querySuggestionHooks?.beforeDrop(name);
18053
18686
  await core.analysisRebuild.abandon(name);
18054
18687
  if (changeRecorded()) await abandonChange();
18055
18688
  await core.orchestrator.closeIndex(name);
@@ -18067,6 +18700,7 @@ async function dropEngineIndex(core, name) {
18067
18700
  core.analysisRebuild.clearStale(name);
18068
18701
  if (entry.sync !== null) emitSyncChange(core.indexRegistry, { kind: "dropped", indexName: name });
18069
18702
  });
18703
+ await core.querySuggestionHooks?.afterDrop(name);
18070
18704
  await runLifecycleHook(core, "onIndexDrop", { indexName: name, config: entry.config });
18071
18705
  }
18072
18706
  function registerEngineEmbeddingAdapter(core, name, adapter) {
@@ -19805,7 +20439,7 @@ async function dropEngineIndex2(core, name) {
19805
20439
  // src/engine/sync-epoch.ts
19806
20440
  async function holdSyncEpochChange(core, indexName) {
19807
20441
  if ((core.indexRegistry.get(indexName)?.sync ?? null) === null) return () => void 0;
19808
- return (await import('./operations-RYKTSZQA.mjs')).holdRenewedSyncEpoch(core, indexName);
20442
+ return (await import('./operations-GNRMD6EX.mjs')).holdRenewedSyncEpoch(core, indexName);
19809
20443
  }
19810
20444
  async function withRenewedSyncEpoch(core, indexName, change) {
19811
20445
  const release = await holdSyncEpochChange(core, indexName);
@@ -19897,6 +20531,9 @@ var engineCores = /* @__PURE__ */ new WeakMap();
19897
20531
  function bindEngineCore(engine, core) {
19898
20532
  engineCores.set(engine, core);
19899
20533
  }
20534
+ function engineCoreOf(engine) {
20535
+ return engineCores.get(engine);
20536
+ }
19900
20537
 
19901
20538
  // src/narsil/portability.ts
19902
20539
  function portabilityOperations(core, config, engine) {
@@ -19910,7 +20547,23 @@ function portabilityOperations(core, config, engine) {
19910
20547
  release();
19911
20548
  }
19912
20549
  }
19913
- const restoresInFlight = /* @__PURE__ */ new Map();
20550
+ function queueRestore(indexName, data) {
20551
+ const { restoresInFlight } = core;
20552
+ const previous = restoresInFlight.get(indexName) ?? Promise.resolve();
20553
+ const restored = previous.then(async () => {
20554
+ const { runRestore } = await import('./restore-queue-ZZX54AH7.mjs');
20555
+ await runRestore(core, restoreHost, indexName, data, engine());
20556
+ });
20557
+ const settled2 = restored.then(
20558
+ () => void 0,
20559
+ () => void 0
20560
+ );
20561
+ restoresInFlight.set(indexName, settled2);
20562
+ void settled2.then(() => {
20563
+ if (restoresInFlight.get(indexName) === settled2) restoresInFlight.delete(indexName);
20564
+ });
20565
+ return restored;
20566
+ }
19914
20567
  const restoreHost = {
19915
20568
  getVectorFieldPaths,
19916
20569
  announceIndexCreated: (name, restoredConfig) => announceIndexCreated(core, name, restoredConfig),
@@ -19927,26 +20580,23 @@ function portabilityOperations(core, config, engine) {
19927
20580
  };
19928
20581
  }
19929
20582
  return {
19930
- snapshot(indexName) {
20583
+ snapshot(indexName, options) {
19931
20584
  return withOpenIndex2(indexName, async () => {
19932
- const { createSnapshot } = await import('./snapshot-ZBIEOZTZ.mjs');
19933
- return createSnapshot(snapshotDepsOf(indexName));
20585
+ const { createSnapshot } = await import('./snapshot-REYVIN3X.mjs');
20586
+ return createSnapshot(snapshotDepsOf(indexName), options?.queryHistory === true ? core : null);
19934
20587
  });
19935
20588
  },
19936
20589
  async restore(indexName, data) {
19937
20590
  core.guardShutdown();
19938
20591
  validateIndexName(indexName);
19939
- const restored = import('./restore-queue-ZBVIKJWI.mjs').then(
19940
- ({ queueRestore }) => queueRestore(core, restoreHost, restoresInFlight, indexName, data)
19941
- );
19942
- await emitWriteEventAfter(core, indexName, restored);
20592
+ await emitWriteEventAfter(core, indexName, queueRestore(indexName, data));
19943
20593
  core.heapPressureNotifier.check(indexName);
19944
20594
  },
19945
20595
  exportDocuments(indexName) {
19946
20596
  return withOpenIndex2(indexName, async () => {
19947
20597
  const [{ checkpointForArchive }, { documentExportStream }] = await Promise.all([
19948
- import('./snapshot-ZBIEOZTZ.mjs'),
19949
- import('./write-2W4FTX7J.mjs')
20598
+ import('./snapshot-REYVIN3X.mjs'),
20599
+ import('./write-FQAYCZF5.mjs')
19950
20600
  ]);
19951
20601
  const header = indexConfigurationOf(core.requireIndex(indexName));
19952
20602
  return documentExportStream(header, await checkpointForArchive(snapshotDepsOf(indexName)));
@@ -19954,7 +20604,7 @@ function portabilityOperations(core, config, engine) {
19954
20604
  },
19955
20605
  importDocumentExport(indexName, data) {
19956
20606
  core.guardShutdown();
19957
- const imported = import('./import-JYBMEJPQ.mjs').then(
20607
+ const imported = import('./import-H6AQREWI.mjs').then(
19958
20608
  ({ readDocumentExport }) => readDocumentExport(engine(), indexName, data)
19959
20609
  );
19960
20610
  return emitWriteEventAfter(core, indexName, imported);
@@ -19980,9 +20630,9 @@ function flush(stream) {
19980
20630
  }
19981
20631
  function ensureCapacity(stream, extra) {
19982
20632
  if (stream.length + extra <= stream.bytes.length) return;
19983
- const grown = new Uint8Array(Math.max(stream.bytes.length * 2, stream.length + extra));
19984
- grown.set(stream.bytes.subarray(0, stream.length));
19985
- stream.bytes = grown;
20633
+ const grown2 = new Uint8Array(Math.max(stream.bytes.length * 2, stream.length + extra));
20634
+ grown2.set(stream.bytes.subarray(0, stream.length));
20635
+ stream.bytes = grown2;
19986
20636
  }
19987
20637
  function writeByte(stream, value) {
19988
20638
  ensureCapacity(stream, 1);
@@ -20076,14 +20726,14 @@ function writeValue(stream, value) {
20076
20726
  }
20077
20727
  return;
20078
20728
  }
20079
- const record = value;
20080
- const keys = Object.keys(record).sort(compareCodePoints);
20729
+ const record2 = value;
20730
+ const keys = Object.keys(record2).sort(compareCodePoints);
20081
20731
  writeByte(stream, MAP_TAG);
20082
20732
  writeUint32(stream, keys.length);
20083
20733
  for (const key of keys) {
20084
20734
  writeByte(stream, STRING_TAG);
20085
20735
  writeString(stream, key);
20086
- writeValue(stream, record[key] ?? null);
20736
+ writeValue(stream, record2[key] ?? null);
20087
20737
  }
20088
20738
  }
20089
20739
  function boundVectorOf(vector) {
@@ -20105,9 +20755,9 @@ function boundRerankOf(rerank) {
20105
20755
  }
20106
20756
  return present;
20107
20757
  }
20108
- function presentMembersOf(record) {
20758
+ function presentMembersOf(record2) {
20109
20759
  const present = {};
20110
- for (const [key, value] of Object.entries(record)) {
20760
+ for (const [key, value] of Object.entries(record2)) {
20111
20761
  if (value !== void 0) present[key] = value;
20112
20762
  }
20113
20763
  return present;
@@ -21261,7 +21911,7 @@ function requireCursorDepth(cursor, signature, binding) {
21261
21911
  }
21262
21912
  function hybridSearchOf(params, context, limit, offset, cursorDepth) {
21263
21913
  if ((params.hybrid?.depth ?? null) === null) return executeHybridSearch(params, context, limit, offset, cursorDepth);
21264
- return import('./runtime-KUATOLYB.mjs').then(
21914
+ return import('./runtime-R5E3TB3J.mjs').then(
21265
21915
  (runtime) => runtime.searchFixedDepthHybrid(params, context, { cursorDepth: cursorDepth ?? 0, offset, limit }, runtimeHost)
21266
21916
  );
21267
21917
  }
@@ -21271,7 +21921,7 @@ function executeQuery(request, callerContext) {
21271
21921
  if (loadingPhraseCode === null) return runQuery(request, callerContext);
21272
21922
  return loadingPhraseCode.then(() => runQuery(request, callerContext));
21273
21923
  }
21274
- return import('./runtime-KUATOLYB.mjs').then(
21924
+ return import('./runtime-R5E3TB3J.mjs').then(
21275
21925
  (runtime) => runtime.executeRerankedQuery(request, callerContext, executeQuery, runtimeHost)
21276
21926
  );
21277
21927
  }
@@ -21670,7 +22320,7 @@ async function runEngineQuery(core, indexName, params, options) {
21670
22320
  const manager = core.requireManager(indexName);
21671
22321
  const scoped = scopedParams(params, options);
21672
22322
  await core.pluginRegistry.runHook("beforeSearch", { indexName, params: scoped });
21673
- const rerank = scoped.rerank === void 0 ? void 0 : await import('./runtime-KUATOLYB.mjs');
22323
+ const rerank = scoped.rerank === void 0 ? void 0 : await import('./runtime-R5E3TB3J.mjs');
21674
22324
  const resolvedParams = await resolveVectorText(
21675
22325
  rerank === void 0 ? scoped : rerank.withRerankQueryText(scoped),
21676
22326
  entry.embeddingAdapter,
@@ -21792,8 +22442,8 @@ async function runEngineListDocuments(core, indexName, params, partitionIds) {
21792
22442
  // src/narsil/sync.ts
21793
22443
  function syncOperations(core) {
21794
22444
  return {
21795
- updateSync: async (indexName, setting) => (await import('./methods-X6F36SJE.mjs')).updateSyncOf(core, indexName, setting),
21796
- getSync: async (indexName) => (await import('./methods-X6F36SJE.mjs')).syncOf(core, indexName)
22445
+ updateSync: async (indexName, setting) => (await import('./methods-6W5U4C3H.mjs')).updateSyncOf(core, indexName, setting),
22446
+ getSync: async (indexName) => (await import('./methods-6W5U4C3H.mjs')).syncOf(core, indexName)
21797
22447
  };
21798
22448
  }
21799
22449
 
@@ -21975,7 +22625,7 @@ function createNarsilFromCore(core, config) {
21975
22625
  const entry = requireIndex(indexName);
21976
22626
  await withOpenIndexWrite(indexName, async () => {
21977
22627
  if (entry.pendingAnalysis === null) return core.analysisRebuild.rebuild(indexName);
21978
- return (await import('./analysis-change-EAYO3Y6Q.mjs')).resumeAnalysisChange(core, indexName);
22628
+ return (await import('./analysis-change-LT5QBQ3H.mjs')).resumeAnalysisChange(core, indexName);
21979
22629
  });
21980
22630
  },
21981
22631
  async changeAnalysis(indexName, change) {
@@ -21983,7 +22633,7 @@ function createNarsilFromCore(core, config) {
21983
22633
  requireIndex(indexName);
21984
22634
  const changed = withOpenIndex2(
21985
22635
  indexName,
21986
- async () => (await import('./analysis-change-EAYO3Y6Q.mjs')).changeIndexAnalysis(core, indexName, change)
22636
+ async () => (await import('./analysis-change-LT5QBQ3H.mjs')).changeIndexAnalysis(core, indexName, change)
21987
22637
  );
21988
22638
  await emitWriteEventAfter(core, indexName, changed);
21989
22639
  },
@@ -22018,7 +22668,7 @@ function createNarsilFromCore(core, config) {
22018
22668
  const rebalanced = withOpenIndex2(
22019
22669
  indexName,
22020
22670
  () => withRenewedSyncEpoch(core, indexName, async () => {
22021
- const { executeRebalance } = await import('./analysis-change-EAYO3Y6Q.mjs');
22671
+ const { executeRebalance } = await import('./analysis-change-LT5QBQ3H.mjs');
22022
22672
  const running = executeRebalance(requireManager(indexName), indexName, targetPartitionCount, rebalanceCtx);
22023
22673
  releaseWrites();
22024
22674
  await running;
@@ -22103,8 +22753,8 @@ function createNarsilFromCore(core, config) {
22103
22753
  guardShutdown();
22104
22754
  requireIndex(indexName);
22105
22755
  const manager = executor.getManager(indexName);
22106
- const vectorCode = loadedVectorCode();
22107
- return manager === void 0 || vectorCode === null ? [] : vectorCode.getVectorMaintenanceStatus(manager);
22756
+ const vectorCode2 = loadedVectorCode();
22757
+ return manager === void 0 || vectorCode2 === null ? [] : vectorCode2.getVectorMaintenanceStatus(manager);
22108
22758
  },
22109
22759
  on(event, handler) {
22110
22760
  const key = event;
@@ -22140,10 +22790,14 @@ async function createNarsil(config) {
22140
22790
  const runnableConfig = await resolveRunnableConfig(config);
22141
22791
  const core = await createEngineCore(runnableConfig);
22142
22792
  await startEngineCore(core, runnableConfig);
22143
- return createNarsilFromCore(core, runnableConfig);
22793
+ const engine = createNarsilFromCore(core, runnableConfig);
22794
+ if (runnableConfig?.querySuggestions !== void 0 || core.durability !== null) {
22795
+ await (await import('./engine-hooks-M7JV46NH.mjs')).startQuerySuggestions(core, engine, runnableConfig);
22796
+ }
22797
+ return engine;
22144
22798
  }
22145
22799
 
22146
22800
  // src/index.ts
22147
22801
  var VERSION = "0.1.0";
22148
22802
 
22149
- export { ARRAY_POSITION_GAP, DEFAULT_BM25_B, DEFAULT_BM25_K1, DEFAULT_WRITE_AHEAD_QUEUE_MAX_SIZE, REBALANCE_CHUNK_SIZE, VERSION, arrayPositionsAreStale, assemblePagedFrozenSegment, buildPartialWordTableFrom, buildSegmentPayload, createCompositePartition, createEncodedDocumentSource, createFrozenSegment, createNarsil, createPartitionIndex, createPartitionManager, createPartitionRouter, createSharedFrozenSegment, decodeEveryStoredDocument, decodeMapWithoutFields, decodeStoredDocument, decodeSurfaceTable, deleteNestedValue, emitEngineEvent, encodeIndexConfiguration, encodeSurfaceTable, endOfValue, engineVersionParts, extractVectorFromDoc, fieldIndexRemapOf, freezeSegmentShared, generateId, holdSyncEpochChange, holdsADiscardedField, insertDocumentVectors, isCompositePartition, loadVectorCodeFor, mergeDocFrequencies, mergeFieldIndexes2 as mergeFieldIndexes, mergeFieldLengths, mergePartialWords, mergeSegmentContents, mergeSurfaceForms2 as mergeSurfaceForms, packChecksummedEnvelope, packEnvelopeWithChecksum, partitionStateOf, prepareConfiguredSynonyms, prepareDocumentVectors, prepareStoredSynonyms, readResidentMemory, rebuildTextIndexes, reconstructSchemaFromMetadata, registerPartialWordSearch, registerPatternSearch, registerSynonyms, removeDocumentVectors, requireConfigurationWithinSizeLimit, requireSurfaceFormsForPartialFields, resolvePartialWordAnalysis, resolvePartitionInsertOptions, rewriteSpillOf, rulesOfStoredSynonyms, scanPostingBlocks, segmentArraysOf, selectionKeeps, shareSegmentArrays, storedArrayPositionGap, survivorDocumentsOf, textRebuildTargetOf, toError2 as toError, validateEmbeddingConfig, validatePatternValueLimit, validateRequiredFieldsInSchema, vectorsEqual, wrapFrozenTokenTable, yieldToEventLoop2 as yieldToEventLoop };
22803
+ export { ARRAY_POSITION_GAP, DEFAULT_BM25_B, DEFAULT_BM25_K1, DEFAULT_WRITE_AHEAD_QUEUE_MAX_SIZE, REBALANCE_CHUNK_SIZE, VERSION, arrayPositionsAreStale, assemblePagedFrozenSegment, buildPartialWordTableFrom, buildSegmentPayload, createCompositePartition, createEncodedDocumentSource, createEngineIndex, createFrozenSegment, createNarsil, createPartitionIndex, createPartitionManager, createPartitionRouter, createSharedFrozenSegment, decodeEveryStoredDocument, decodeMapWithoutFields, decodeStoredDocument, decodeSurfaceTable, deleteNestedValue, dropEngineIndex, emitEngineEvent, emitWriteEventAfter, encodeIndexConfiguration, encodeSurfaceTable, endOfValue, engineCoreOf, engineVersionParts, extractVectorFromDoc, fieldIndexRemapOf, freezeSegmentShared, generateId, holdSyncEpochChange, holdsADiscardedField, insertDocumentVectors, isCompositePartition, loadSchemaCodeFor, mergeDocFrequencies, mergeFieldIndexes2 as mergeFieldIndexes, mergeFieldLengths, mergePartialWords, mergeSegmentContents, mergeSurfaceForms2 as mergeSurfaceForms, packChecksummedEnvelope, packEnvelopeWithChecksum, partitionStateOf, prepareConfiguredSynonyms, prepareDocumentVectors, prepareStoredSynonyms, readResidentMemory, rebuildTextIndexes, reconstructSchemaFromMetadata, registerPartialWordSearch, registerPatternSearch, registerSynonyms, removeDocumentBatch2 as removeDocumentBatch, removeDocumentVectors, requireConfigurationWithinSizeLimit, requireSurfaceFormsForPartialFields, resolvePartialWordAnalysis, resolvePartitionInsertOptions, rewriteSpillOf, rulesOfStoredSynonyms, scanPostingBlocks, segmentArraysOf, selectionKeeps, shareSegmentArrays, storedArrayPositionGap, survivorDocumentsOf, textRebuildTargetOf, toError2 as toError, validateEmbeddingConfig, validatePatternValueLimit, validateRequiredFieldsInSchema, vectorsEqual, wrapFrozenTokenTable, yieldToEventLoop2 as yieldToEventLoop };