@delali/narsil 0.3.1-next.155 → 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 (195) hide show
  1. package/NOTICE +45 -0
  2. package/dist/{analysis-change-3TFIHT5E.mjs → analysis-change-5BQOQ4BF.mjs} +25 -18
  3. package/dist/{react-native/chunks/analysis-change-entry-JLL42PH6.mjs → analysis-change-entry-TXX6JSMX.mjs} +1 -1
  4. package/dist/browser/{analysis-change-TC36BU47.mjs → analysis-change-435CUEPZ.mjs} +8 -7
  5. package/dist/{analysis-change-entry-KA6JAO4X.mjs → browser/analysis-change-entry-HZXKPPGV.mjs} +1 -1
  6. package/dist/browser/{chunk-A5KUEGDY.mjs → chunk-2CFI5VVV.mjs} +2 -2
  7. package/dist/browser/{chunk-BXM5XOCA.mjs → chunk-2TI4SSUP.mjs} +2 -2
  8. package/dist/browser/{chunk-CJSYBQ4J.mjs → chunk-3SSRJMFN.mjs} +1 -1
  9. package/dist/browser/{chunk-SMEQ36NT.mjs → chunk-3V7DNNZL.mjs} +458 -622
  10. package/dist/browser/{chunk-RRO3EV4C.mjs → chunk-4NGKC4H4.mjs} +7 -7
  11. package/dist/browser/{chunk-ABCXENU5.mjs → chunk-6LWDPLTB.mjs} +1 -1
  12. package/dist/browser/{chunk-FNIFPFB7.mjs → chunk-7U3WVJUP.mjs} +2 -2
  13. package/dist/browser/{chunk-KKAMCABR.mjs → chunk-BHFQATSC.mjs} +1 -1
  14. package/dist/browser/{chunk-IKDKX5VQ.mjs → chunk-CRE3G7F3.mjs} +3 -3
  15. package/dist/browser/{chunk-56W3HQVJ.mjs → chunk-EA63E3D2.mjs} +4 -4
  16. package/dist/browser/{chunk-K5AXJBLL.mjs → chunk-IZXVW2ZJ.mjs} +3 -3
  17. package/dist/browser/{chunk-RND5CLX3.mjs → chunk-K4Q6KX3R.mjs} +16 -16
  18. package/dist/browser/{chunk-XY4VVBBO.mjs → chunk-KZWSX6BH.mjs} +2 -2
  19. package/dist/browser/{chunk-3UIEB4QF.mjs → chunk-MGI4BCXC.mjs} +2 -2
  20. package/dist/browser/chunk-MOG4OVDK.mjs +51 -0
  21. package/dist/browser/{chunk-RQBUNZQW.mjs → chunk-NQAME3RK.mjs} +2 -2
  22. package/dist/browser/{chunk-LFIWRCEA.mjs → chunk-NXQG7DRA.mjs} +29 -6
  23. package/dist/browser/{chunk-JVBP5EYO.mjs → chunk-SSTPBZZX.mjs} +7 -7
  24. package/dist/browser/{chunk-JIJXMI42.mjs → chunk-STOWQFT3.mjs} +1 -1
  25. package/dist/browser/{chunk-26A5JFT2.mjs → chunk-TK63WFXK.mjs} +2 -1
  26. package/dist/browser/{chunk-4EWUGZYZ.mjs → chunk-U4YDIBUT.mjs} +2 -2
  27. package/dist/browser/{chunk-K4GCSZLI.mjs → chunk-VLJQW4J6.mjs} +2985 -2985
  28. package/dist/browser/{chunk-SUDNZKPL.mjs → chunk-WI4MR75E.mjs} +1 -1
  29. package/dist/browser/{chunk-5TCXK5SB.mjs → chunk-WN464PTL.mjs} +1 -1
  30. package/dist/browser/{cold-module-NEUGHUPA.mjs → cold-module-2EHCIV4K.mjs} +15 -14
  31. package/dist/browser/{durability-wiring-CVGPRO6D.mjs → durability-wiring-A7BVG2DW.mjs} +20 -19
  32. package/dist/browser/{engine-hooks-YXMPHZKZ.mjs → engine-hooks-E4UD67JD.mjs} +7 -6
  33. package/dist/browser/geo-index-HHWGMNIS.mjs +1386 -0
  34. package/dist/browser/{import-OM6QAW45.mjs → import-DXYB6756.mjs} +8 -7
  35. package/dist/browser/{module-E33X4AOK.mjs → module-NIYMEA5R.mjs} +11 -10
  36. package/dist/browser/{module-3HNFCBJ5.mjs → module-TCT66FWA.mjs} +6 -6
  37. package/dist/browser/{phrase-module-ZXXU7S3B.mjs → phrase-module-HAT3TLZN.mjs} +1 -1
  38. package/dist/browser/{restore-hooks-IF2ZROUP.mjs → restore-hooks-YPN4ZFCY.mjs} +10 -9
  39. package/dist/browser/{restore-queue-ZBS7CJA6.mjs → restore-queue-G3RQGL3Y.mjs} +3 -3
  40. package/dist/browser/{retention-ASWUHAYI.mjs → retention-ZWVMNC3Q.mjs} +9 -8
  41. package/dist/browser/{snapshot-PN7ZW6Q4.mjs → snapshot-VEQNIE6C.mjs} +24 -23
  42. package/dist/browser/{start-ZIRB7MQ2.mjs → start-BM442C6R.mjs} +11 -10
  43. package/dist/browser/{write-HMDYCTV2.mjs → write-2EVMZWDE.mjs} +12 -11
  44. package/dist/{chunk-2MANFZJ3.mjs → chunk-25KDNIZZ.mjs} +1 -1
  45. package/dist/{chunk-3HHQLEEQ.mjs → chunk-2UV4QBHW.mjs} +7 -7
  46. package/dist/{chunk-BY6ZDGYS.mjs → chunk-3HYC4JRF.mjs} +1 -1
  47. package/dist/{chunk-HW5TNXBO.mjs → chunk-46KY2PJD.mjs} +7 -6
  48. package/dist/{chunk-SY3EWKQY.mjs → chunk-4KKXNJM6.mjs} +1 -1
  49. package/dist/{chunk-VQEUR6T6.mjs → chunk-5VV4R6P7.mjs} +3040 -3040
  50. package/dist/chunk-6HTGOXIK.mjs +875 -0
  51. package/dist/{chunk-RSVULW4Q.mjs → chunk-6I6AYAXS.mjs} +4 -4
  52. package/dist/chunk-7GFE3PEY.mjs +40 -0
  53. package/dist/{chunk-3R4UZWQG.mjs → chunk-7LXHHCXZ.mjs} +15 -15
  54. package/dist/{chunk-JUKYYXSP.mjs → chunk-7V5IUP2T.mjs} +1 -31
  55. package/dist/{chunk-4BYWRYPM.mjs → chunk-A4L7YTKX.mjs} +52 -89
  56. package/dist/{chunk-WQRN64Q6.mjs → chunk-BU4SAIC4.mjs} +1 -1
  57. package/dist/{chunk-5FVU47TB.mjs → chunk-BWZ3P4MU.mjs} +3 -3
  58. package/dist/{chunk-LC3FDWTX.mjs → chunk-CITFCZKF.mjs} +3 -2
  59. package/dist/{chunk-PCRA7HTI.mjs → chunk-CSLGFPFQ.mjs} +1 -1
  60. package/dist/{chunk-VHBNF4MA.mjs → chunk-DP5C7YFQ.mjs} +2 -2
  61. package/dist/{chunk-3HB3PEC6.mjs → chunk-DWEPMFJE.mjs} +5 -5
  62. package/dist/{chunk-KMUNHGBQ.mjs → chunk-EFBDHH5P.mjs} +29 -28
  63. package/dist/{chunk-DCNKVEDB.mjs → chunk-FAKFUDZZ.mjs} +5 -6
  64. package/dist/chunk-FB6463IN.mjs +1499 -0
  65. package/dist/{chunk-KFLK5NA2.mjs → chunk-FCJ553HS.mjs} +1 -1
  66. package/dist/{chunk-SG3JBNHY.mjs → chunk-FJKKCV4D.mjs} +1 -1
  67. package/dist/{chunk-H6VIGE62.mjs → chunk-FNGAM5B7.mjs} +10 -9
  68. package/dist/{chunk-VGF7CFRP.mjs → chunk-FRBFVQFN.mjs} +5 -4
  69. package/dist/{chunk-QH3YIQP4.mjs → chunk-FYOVBEMM.mjs} +2 -2
  70. package/dist/chunk-G6HRSGOU.mjs +74 -0
  71. package/dist/{chunk-DUOLGBTE.mjs → chunk-HFPMMRQT.mjs} +3 -3
  72. package/dist/{chunk-ZHCUZZE5.mjs → chunk-HHBUCIUY.mjs} +1 -1
  73. package/dist/{chunk-ZTW5WTGG.mjs → chunk-I2KPOLOZ.mjs} +3 -3
  74. package/dist/{chunk-L7ZD4L3K.mjs → chunk-I53G4JAU.mjs} +7 -6
  75. package/dist/{chunk-YEDIDCR7.mjs → chunk-I5B7RXU7.mjs} +91 -22
  76. package/dist/{react-native/chunks/chunk-KWRW5U65.mjs → chunk-J4IJTTEX.mjs} +1 -1
  77. package/dist/{chunk-S2EQU2GE.mjs → chunk-JDJBQLRO.mjs} +9 -9
  78. package/dist/{chunk-KPIV4RUC.mjs → chunk-JWRUUCWD.mjs} +2 -2
  79. package/dist/{chunk-KBKEXQZA.mjs → chunk-K5QFDYST.mjs} +1 -1
  80. package/dist/{chunk-DIBHI6W5.mjs → chunk-KF4EXSM4.mjs} +2 -2
  81. package/dist/{chunk-Q7G3BV3Y.mjs → chunk-KKQC526K.mjs} +19 -11
  82. package/dist/{chunk-4KRC2APY.mjs → chunk-L6V6BST3.mjs} +6 -19
  83. package/dist/{chunk-U4BS74YN.mjs → chunk-MQOJIO5B.mjs} +1 -1
  84. package/dist/chunk-ORN5BLL7.mjs +11 -0
  85. package/dist/{chunk-ZAUJFLEN.mjs → chunk-P5ZI2P2W.mjs} +122 -1697
  86. package/dist/{chunk-AILVAOLX.mjs → chunk-PWC4VB3Q.mjs} +2 -2
  87. package/dist/{chunk-J4IWBIVY.mjs → chunk-QOW2JPUI.mjs} +5 -5
  88. package/dist/{chunk-PHQNACDT.mjs → chunk-RDXO6JST.mjs} +2 -2
  89. package/dist/chunk-RLOES5SX.mjs +31 -0
  90. package/dist/{chunk-6L3XJXGU.mjs → chunk-SA5LOGO3.mjs} +1 -1
  91. package/dist/chunk-SQJWAIF4.mjs +12 -0
  92. package/dist/{react-native/chunks/chunk-PPEPTUVV.mjs → chunk-TBC3XUL2.mjs} +29 -6
  93. package/dist/chunk-TDIK6NTV.mjs +10 -0
  94. package/dist/{chunk-MT2NRTA6.mjs → chunk-TGS5UXBE.mjs} +3 -3
  95. package/dist/{chunk-KBDBPVLN.mjs → chunk-TZ3355VS.mjs} +1 -1
  96. package/dist/{chunk-Q622CTMC.mjs → chunk-TZTRKM33.mjs} +1 -1
  97. package/dist/{react-native/chunks/chunk-JV6VQY2S.mjs → chunk-U55XJEIG.mjs} +2 -1
  98. package/dist/{chunk-Z2BE2MAM.mjs → chunk-VTTRFF2C.mjs} +28 -15
  99. package/dist/{chunk-KXCVQWOR.mjs → chunk-WX4LAO6M.mjs} +3 -3
  100. package/dist/{chunk-BDRIVYOK.mjs → chunk-XAXKV65G.mjs} +1 -1
  101. package/dist/{chunk-UZRZKNNZ.mjs → chunk-XXHN7J46.mjs} +1 -1
  102. package/dist/{chunk-H4KHPLHJ.mjs → chunk-YTWZVGCB.mjs} +1 -1
  103. package/dist/{chunk-QUJHMPTP.mjs → chunk-Z2KAFCRT.mjs} +2 -2
  104. package/dist/{chunk-SMVH6JBE.mjs → chunk-ZKP7G7TV.mjs} +1 -1
  105. package/dist/{cold-module-7XXCEGTZ.mjs → cold-module-6MO2XJF2.mjs} +29 -23
  106. package/dist/direct-executor-FTMYY3TI.mjs +34 -0
  107. package/dist/distribution/coordinator/etcd.mjs +2 -2
  108. package/dist/distribution/coordinator/in-memory.mjs +2 -2
  109. package/dist/distribution.mjs +57 -51
  110. package/dist/{durability-wiring-NCKUC5EO.mjs → durability-wiring-VIF5MOSY.mjs} +41 -34
  111. package/dist/{engine-hooks-DHCMOADY.mjs → engine-hooks-EGUGNZYE.mjs} +24 -17
  112. package/dist/geo-index-MRH5JMIR.mjs +1387 -0
  113. package/dist/{import-NBFXFCSG.mjs → import-XKDPJQDP.mjs} +24 -17
  114. package/dist/index.browser.mjs +6 -5
  115. package/dist/index.d.ts +127 -2
  116. package/dist/index.mjs +23 -16
  117. package/dist/index.react-native.mjs +12 -10
  118. package/dist/invalidation/filesystem.mjs +2 -2
  119. package/dist/{long-query-thread-J4DVRM4A.mjs → long-query-thread-YA4IAYSY.mjs} +25 -20
  120. package/dist/{module-DWKPBSMN.mjs → module-FQ4JWNQJ.mjs} +26 -19
  121. package/dist/{module-UN76TF7I.mjs → module-N55W4Q5C.mjs} +9 -9
  122. package/dist/{paged-partition-archive-DPNWVSK2.mjs → paged-partition-archive-PXW5XAYU.mjs} +32 -26
  123. package/dist/partial-words.mjs +8 -6
  124. package/dist/pattern.mjs +4 -3
  125. package/dist/persistence/durability/checkpoint-worker.mjs +30 -21
  126. package/dist/{phrase-module-ZI4WSQVH.mjs → phrase-module-XW5MKWP5.mjs} +3 -2
  127. package/dist/query-suggestions/merge-worker.mjs +25 -18
  128. package/dist/query-suggestions.browser.mjs +12 -11
  129. package/dist/query-suggestions.mjs +34 -27
  130. package/dist/react-native/chunks/{analysis-change-6BPDPH6K.mjs → analysis-change-LT5QBQ3H.mjs} +13 -11
  131. package/dist/{browser/analysis-change-entry-4MH3CZXH.mjs → react-native/chunks/analysis-change-entry-SCVWK6OU.mjs} +1 -1
  132. package/dist/react-native/chunks/{chunk-7PXRWYUU.mjs → chunk-2PRHILX3.mjs} +53 -19
  133. package/dist/react-native/chunks/{chunk-C3PTWYKT.mjs → chunk-3JWDECAZ.mjs} +4 -4
  134. package/dist/{chunk-R6A773WK.mjs → react-native/chunks/chunk-3WI35N75.mjs} +1 -1
  135. package/dist/react-native/chunks/{chunk-CUH5F57W.mjs → chunk-4JYO3JD2.mjs} +2 -2
  136. package/dist/react-native/chunks/{chunk-3JIBF3XT.mjs → chunk-DNXOMPAQ.mjs} +1 -1
  137. package/dist/react-native/chunks/chunk-DXRSEWA2.mjs +12 -0
  138. package/dist/{chunk-YTJCGKM4.mjs → react-native/chunks/chunk-EJ33LCHV.mjs} +29 -6
  139. package/dist/react-native/chunks/{chunk-EIOYM5TO.mjs → chunk-ENLMYKSX.mjs} +3024 -3054
  140. package/dist/react-native/chunks/chunk-FHPW7P2O.mjs +40 -0
  141. package/dist/{chunk-4UMZ7KQL.mjs → react-native/chunks/chunk-FTZHMRD2.mjs} +2 -1
  142. package/dist/react-native/chunks/{chunk-OL3WDV53.mjs → chunk-G43IPIDG.mjs} +3 -3
  143. package/dist/react-native/chunks/{chunk-4Y53T4YE.mjs → chunk-GXX3DQXP.mjs} +5 -19
  144. package/dist/react-native/chunks/{chunk-GIZTJXYW.mjs → chunk-KV46CT4D.mjs} +2 -2
  145. package/dist/react-native/chunks/{chunk-HUOYZJ3Q.mjs → chunk-MIP4SOR6.mjs} +1419 -711
  146. package/dist/react-native/chunks/{chunk-ALOIBXWN.mjs → chunk-MUWD2H2S.mjs} +2 -2
  147. package/dist/react-native/chunks/{chunk-4LCEN2IU.mjs → chunk-NB3LP33V.mjs} +2 -2
  148. package/dist/react-native/chunks/{chunk-VXGE4ZXL.mjs → chunk-PDRWWPKV.mjs} +17 -17
  149. package/dist/react-native/chunks/{chunk-N2WUOWLL.mjs → chunk-POPDAGH6.mjs} +7 -7
  150. package/dist/react-native/chunks/{chunk-GJFXPHXI.mjs → chunk-QUKQNI3H.mjs} +3 -3
  151. package/dist/react-native/chunks/{chunk-KTTAU63H.mjs → chunk-SK2PWYDH.mjs} +2 -2
  152. package/dist/react-native/chunks/{chunk-7GRCBBME.mjs → chunk-TP6KCKER.mjs} +2 -2
  153. package/dist/react-native/chunks/{chunk-KJIG57UD.mjs → chunk-UQ4OAXKU.mjs} +7 -7
  154. package/dist/react-native/chunks/{chunk-PEHS2UO3.mjs → chunk-VWUDIOT6.mjs} +3 -3
  155. package/dist/react-native/chunks/{chunk-JLIIWJUV.mjs → chunk-YZW4CHM6.mjs} +50 -11
  156. package/dist/react-native/chunks/{chunk-QJXTNPLQ.mjs → chunk-ZLWVW734.mjs} +1 -1
  157. package/dist/react-native/chunks/{chunk-TYIRMPD3.mjs → chunk-ZXZFN7FI.mjs} +1 -1
  158. package/dist/react-native/chunks/{cold-module-5PHF6DZR.mjs → cold-module-KVZYUGRY.mjs} +19 -17
  159. package/dist/react-native/chunks/{durability-wiring-KO565FZC.mjs → durability-wiring-34OYO32E.mjs} +27 -25
  160. package/dist/react-native/chunks/{engine-hooks-MVRRHH6B.mjs → engine-hooks-M7JV46NH.mjs} +13 -11
  161. package/dist/react-native/chunks/geo-index-PX3BIHAH.mjs +1387 -0
  162. package/dist/react-native/chunks/{import-YVZA4V4V.mjs → import-H6AQREWI.mjs} +14 -12
  163. package/dist/react-native/chunks/{module-ZL5ZG6YB.mjs → module-LBZPGOWH.mjs} +15 -13
  164. package/dist/react-native/chunks/{module-H5MVPSP2.mjs → module-TTEVPRCW.mjs} +8 -8
  165. package/dist/react-native/chunks/{phrase-module-RTVKEWJT.mjs → phrase-module-QK22HSQ2.mjs} +1 -1
  166. package/dist/react-native/chunks/{restore-hooks-SILFPU6B.mjs → restore-hooks-IBGIY3DR.mjs} +17 -15
  167. package/dist/react-native/chunks/{restore-queue-HSYP2AEC.mjs → restore-queue-ZZX54AH7.mjs} +3 -3
  168. package/dist/react-native/chunks/{retention-7I7UAWYK.mjs → retention-EW4TTDFB.mjs} +18 -16
  169. package/dist/react-native/chunks/{snapshot-EZYB6SLF.mjs → snapshot-REYVIN3X.mjs} +31 -29
  170. package/dist/react-native/chunks/{start-SHVZ72I5.mjs → start-BQK6KN3R.mjs} +18 -16
  171. package/dist/react-native/chunks/{write-JUESXHDL.mjs → write-FQAYCZF5.mjs} +16 -14
  172. package/dist/react-native/partial-words.mjs +7 -6
  173. package/dist/react-native/pattern.mjs +1 -1
  174. package/dist/react-native/query-suggestions.mjs +19 -17
  175. package/dist/react-native/sync.mjs +7 -7
  176. package/dist/react-native/synonyms.mjs +92 -24
  177. package/dist/{restore-hooks-HZ3ILAMO.mjs → restore-hooks-CDERDEF4.mjs} +28 -21
  178. package/dist/{restore-queue-JVGENGGE.mjs → restore-queue-7NNSTROA.mjs} +3 -3
  179. package/dist/{retention-HROPV2QU.mjs → retention-QSVBBNRM.mjs} +28 -21
  180. package/dist/server.mjs +45 -39
  181. package/dist/{snapshot-4HS2G2UM.mjs → snapshot-RH4NSKIZ.mjs} +44 -38
  182. package/dist/{start-UTWHGH42.mjs → start-MCKCOGIW.mjs} +31 -24
  183. package/dist/sync/filesystem.mjs +3 -3
  184. package/dist/sync.browser.mjs +5 -5
  185. package/dist/sync.mjs +5 -5
  186. package/dist/synonyms.mjs +7 -6
  187. package/dist/{thread-6MOXY2KD.mjs → thread-O4SBJJJS.mjs} +24 -19
  188. package/dist/vector/search-worker.mjs +6 -6
  189. package/dist/workers/entry.mjs +17 -6
  190. package/dist/{write-GTTWWRRG.mjs → write-3FK7NG3Y.mjs} +26 -19
  191. package/package.json +15 -8
  192. package/dist/chunk-DJHHF2L5.mjs +0 -17
  193. package/dist/chunk-HNVVEQP7.mjs +0 -44
  194. package/dist/direct-executor-G5TK7NLA.mjs +0 -29
  195. package/dist/browser/{chunk-4WCVMOU3.mjs → chunk-XAWNZ4G2.mjs} +10 -10
@@ -1,25 +1,27 @@
1
+ import { createRequestId } from './chunk-NNE4VDMM.mjs';
1
2
  import { DEFAULT_MAX_RERANK_WINDOW, DEFAULT_RERANK_TIMEOUT_MS } from './chunk-IO2SMUQD.mjs';
2
- import { createDocIdMap, turnsAreBudgeted, turnIsSpent, yieldTurn, detectRuntime, indexChangeOutsideExternalWaits, changeIndexOutsideExternalWaits, countWrite, 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 } from './chunk-JLIIWJUV.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';
3
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';
4
6
  import { reactNativeHost } from './chunk-MVXELMJX.mjs';
5
- import { createRequestId } from './chunk-NNE4VDMM.mjs';
6
- import { splitWorkerBudget, resolveWorkerCount, resolveRequestThreadCount, DEFAULT_REQUEST_TIMEOUT_MS, MAX_RENUMBERED_SEARCH_ATTEMPTS } from './chunk-LU3Y3P63.mjs';
7
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, MAX_LATITUDE_DEGREES, isLongitude, MAX_LONGITUDE_DEGREES, MIN_POLYGON_POINTS, expandTermPrefix, getNestedValue, tokenizeOptions, raiseEarlierReleaseGraphSetting, messagePackUpperBoundBytes, validateVectorPromotion, validateVectorStorage, validateTextStorage, suggestDisplayTerms, validateDocument, validateDocumentStrict, textFieldsChanged, sameFields, getFlatSchema, getOrCreateFieldNameIndex, partitionDocumentFrequency, visitDocumentSurfaceSpellings, visitDocumentSpellings, 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-4Y53T4YE.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';
9
9
  import { fuzzyPrefixOf, boundedLevenshtein, fuzzyTermMatches } from './chunk-UNUFZ2QY.mjs';
10
10
  import { emitSyncChange, withOpenIndex, oneAtATime } from './chunk-JDOEEMEF.mjs';
11
- import { encodeStringBlob, encodeLookupKey, visitTokens, codePointOrder, tokenize } from './chunk-7PXRWYUU.mjs';
11
+ import { encodeStringBlob, encodeLookupKey, visitTokens, codePointOrder, tokenize, installNativeAnalysis, NATIVE_ANALYSIS_FIRST_TOKEN_RECORDS, NATIVE_ANALYSIS_HELD_TERMS } from './chunk-2PRHILX3.mjs';
12
12
  import { requireWithinFileLimit, HEADER_SIZE, payloadByteLength, checksumOfChunks, packEnvelopeWithEngineVersion, INDEX_CONFIGURATION_ENVELOPE_VERSION, readHeapStatistics, readOldGenerationStatistics } from './chunk-YH7QY657.mjs';
13
13
  import { fnv1a, FNV_OFFSET_BASIS, fnv1aContinue, fnv1aContinueTaggedNumbers } from './chunk-CHPTFFJM.mjs';
14
- import { flattenSchema, partialFieldsOf, schemaFieldsOf, validateSchema, requireCreatableSchema, encodeDocument, extractVectorFieldsFromSchema } from './chunk-3JIBF3XT.mjs';
14
+ import { flattenSchema, partialFieldsOf, schemaFieldsOf, validateSchema, requireCreatableSchema, encodeDocument, extractVectorFieldsFromSchema } from './chunk-DNXOMPAQ.mjs';
15
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, MAX_NESTING_DEPTH, isWordIndexedFieldType, isStringValuedBase, withSortableOption, isGeopointOrVectorType, isListBase, VECTOR_PATTERN } from './chunk-C5G6TJ7A.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
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-KWRW5U65.mjs';
19
- import { compareCodePoints, holdsUnpairedSurrogate, exceedsCodePoints, codePointCount } from './chunk-PPEPTUVV.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';
20
22
  import { bitsetHas, createBitSet, GrowableUint32, bitsetIsEmpty, bitsetSet, bitsetOrInto, bitsetAndNotInto, bitsetAndInto, bitsetFromSet } from './chunk-LVIKKAA6.mjs';
21
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';
22
- 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';
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';
23
25
  import { ErrorCodes, NarsilError } from './chunk-DZ7H7D2C.mjs';
24
26
  import { Decoder, decode, encode } from '@msgpack/msgpack';
25
27
 
@@ -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) {
@@ -1316,6 +1318,11 @@ function validateRequiredFieldsInSchema(required, schema) {
1316
1318
  }
1317
1319
  }
1318
1320
 
1321
+ // src/core/document-copy.browser.ts
1322
+ function copyStoredValue(value) {
1323
+ return structuredClone(value);
1324
+ }
1325
+
1319
1326
  // src/core/projection.ts
1320
1327
  function requireFieldPathList(paths, option) {
1321
1328
  if (paths === void 0) return;
@@ -1366,9 +1373,9 @@ function readProjectedPath(source, path) {
1366
1373
  for (const segment of path) {
1367
1374
  if (typeof current !== "object" || current === null || Array.isArray(current))
1368
1375
  return { found: false, value: void 0 };
1369
- const record = current;
1370
- if (!Object.hasOwn(record, segment)) return { found: false, value: void 0 };
1371
- current = record[segment];
1376
+ const record2 = current;
1377
+ if (!Object.hasOwn(record2, segment)) return { found: false, value: void 0 };
1378
+ current = record2[segment];
1372
1379
  }
1373
1380
  return { found: true, value: current };
1374
1381
  }
@@ -1389,8 +1396,8 @@ function writePath(target, path, value) {
1389
1396
  }
1390
1397
  function cloneExcept(value, path, exclude) {
1391
1398
  const reachesDeeper = exclude.some((excluded) => excluded.length > path.length && covers(path, excluded));
1392
- if (!reachesDeeper) return structuredClone(value);
1393
- 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);
1394
1401
  const source = value;
1395
1402
  const kept = {};
1396
1403
  for (const key of Object.keys(source)) {
@@ -1429,7 +1436,7 @@ function projectionKeepsField(projection, fieldPath) {
1429
1436
  return !projection.exclude.some((excluded) => covers(excluded, path));
1430
1437
  }
1431
1438
  function cloneProjected(document, projection) {
1432
- if (projection === void 0 || projection.kind === "full") return structuredClone(document);
1439
+ if (projection === void 0 || projection.kind === "full") return copyStoredValue(document);
1433
1440
  if (projection.kind === "none") return {};
1434
1441
  if (projection.include === null) return cloneExcept(document, [], projection.exclude);
1435
1442
  return projectIncludedPaths(projection.include, projection.exclude, (path) => readProjectedPath(document, path));
@@ -1577,9 +1584,9 @@ function createDocumentStore() {
1577
1584
  for (const fieldName of Object.keys(fieldLengths)) {
1578
1585
  let column = lengthColumns.get(fieldName);
1579
1586
  if (column === void 0 || column.length <= internalId) {
1580
- const grown = new Uint32Array(Math.max(internalId + 1, (column?.length ?? 0) * 2, 64));
1581
- if (column !== void 0) grown.set(column);
1582
- 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;
1583
1590
  lengthColumns.set(fieldName, column);
1584
1591
  }
1585
1592
  column[internalId] = fieldLengths[fieldName];
@@ -2010,9 +2017,9 @@ var PositionPool = class {
2010
2017
  reserve(needed) {
2011
2018
  if (needed <= this.values.length) return;
2012
2019
  const capacity = grownCapacity(this.values.length, needed);
2013
- const grown = new Uint32Array(capacity);
2014
- grown.set(this.values.subarray(0, this.end));
2015
- this.values = grown;
2020
+ const grown2 = new Uint32Array(capacity);
2021
+ grown2.set(this.values.subarray(0, this.end));
2022
+ this.values = grown2;
2016
2023
  }
2017
2024
  };
2018
2025
 
@@ -2054,9 +2061,9 @@ var PostingPool2 = class extends PostingPool {
2054
2061
  if (this.copy !== null || this.replaced) return;
2055
2062
  const capacity = this.docIds.length;
2056
2063
  if (this.end < capacity * POOL_GROWTH_START_FRACTION) return;
2057
- const grown = grownCapacity(capacity, this.end + 1);
2058
- if (grown <= capacity) return;
2059
- 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);
2060
2067
  this.copy = copy;
2061
2068
  void copyBetweenTurns(copy);
2062
2069
  }
@@ -2098,9 +2105,9 @@ var PositionPool2 = class extends PositionPool {
2098
2105
  if (this.copy !== null || this.replaced) return;
2099
2106
  const capacity = this.values.length;
2100
2107
  if (this.end < capacity * POOL_GROWTH_START_FRACTION) return;
2101
- const grown = grownCapacity(capacity, this.end + 1);
2102
- if (grown <= capacity) return;
2103
- 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);
2104
2111
  this.copy = copy;
2105
2112
  void copyBetweenTurns(copy);
2106
2113
  }
@@ -2472,7 +2479,7 @@ var LivePostings = class {
2472
2479
  terms = new TermColumns(TERM_TABLE_START_CAPACITY);
2473
2480
  pool = new PostingPool2(POSTING_POOL_START_ENTRIES);
2474
2481
  positions = new PositionPool2(POSITION_POOL_START_VALUES);
2475
- retired = new Uint8Array(RETIRED_DOCUMENTS_START_CAPACITY);
2482
+ retired = new Uint32Array(RETIRED_DOCUMENTS_START_CAPACITY >>> 5);
2476
2483
  batchMode = false;
2477
2484
  dirty = /* @__PURE__ */ new Set();
2478
2485
  cachedViews = /* @__PURE__ */ new Map();
@@ -2559,7 +2566,7 @@ var LivePostings = class {
2559
2566
  this.repackIfSparse();
2560
2567
  }
2561
2568
  isRetired(internalId) {
2562
- return internalId < this.retired.length && this.retired[internalId] === 1;
2569
+ return bitsetHas(this.retired, internalId);
2563
2570
  }
2564
2571
  beginBatch() {
2565
2572
  this.batchMode = true;
@@ -2583,7 +2590,7 @@ var LivePostings = class {
2583
2590
  this.pool = new PostingPool2(POSTING_POOL_START_ENTRIES);
2584
2591
  this.pool.epoch = epoch;
2585
2592
  this.positions = new PositionPool2(POSITION_POOL_START_VALUES);
2586
- this.retired = new Uint8Array(RETIRED_DOCUMENTS_START_CAPACITY);
2593
+ this.retired = new Uint32Array(RETIRED_DOCUMENTS_START_CAPACITY >>> 5);
2587
2594
  this.dirty.clear();
2588
2595
  this.cachedViews.clear();
2589
2596
  this.compactedSlack = 0;
@@ -2592,12 +2599,13 @@ var LivePostings = class {
2592
2599
  return this.terms.byteLength() + this.pool.byteLength() + this.positions.values.byteLength + this.retired.byteLength;
2593
2600
  }
2594
2601
  retire(internalId) {
2595
- if (internalId >= this.retired.length) {
2596
- const grown = new Uint8Array(Math.max(internalId + 1, this.retired.length * 2));
2597
- grown.set(this.retired);
2598
- 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;
2599
2607
  }
2600
- this.retired[internalId] = 1;
2608
+ bitsetSet(this.retired, internalId);
2601
2609
  }
2602
2610
  purgeRetired() {
2603
2611
  const terms = this.terms;
@@ -2609,7 +2617,7 @@ var LivePostings = class {
2609
2617
  compact(ordinal) {
2610
2618
  if (this.terms.deadDocuments[ordinal] === 0) return;
2611
2619
  const retired = this.retired;
2612
- this.filterEntries(ordinal, (id) => id < retired.length && retired[id] === 1);
2620
+ this.filterEntries(ordinal, (id) => bitsetHas(retired, id));
2613
2621
  this.terms.deadDocuments[ordinal] = 0;
2614
2622
  }
2615
2623
  filterEntries(ordinal, drop) {
@@ -2819,6 +2827,7 @@ function createInvertedIndex(fieldNameTable) {
2819
2827
  return entries;
2820
2828
  }
2821
2829
  return {
2830
+ livePostings: postings,
2822
2831
  insert(token, internalId, termFrequency, fieldNameIndex2, positions) {
2823
2832
  postings.insert(token, internalId, termFrequency, fieldNameIndex2, positions);
2824
2833
  },
@@ -3324,420 +3333,54 @@ function patternIndexOf(indexes, fieldPath) {
3324
3333
  return index;
3325
3334
  }
3326
3335
 
3327
- // src/geo/cells.ts
3328
- var AXIS_CELLS = 2 ** LOCATION_CODE_BITS_PER_AXIS;
3329
- function axisCell(value, lowest, span) {
3330
- const cell = Math.floor((value - lowest) / span * AXIS_CELLS);
3331
- if (!(cell > 0)) return 0;
3332
- return cell >= AXIS_CELLS ? AXIS_CELLS - 1 : cell;
3333
- }
3334
- function latitudeCell(lat) {
3335
- return axisCell(lat, -MAX_LATITUDE_DEGREES, 2 * MAX_LATITUDE_DEGREES);
3336
- }
3337
- function longitudeCell(lon) {
3338
- return axisCell(lon, -MAX_LONGITUDE_DEGREES, FULL_TURN_DEGREES);
3339
- }
3340
- function interleave(row, column, bits) {
3341
- let code = 0;
3342
- for (let bit = bits - 1; bit >= 0; bit--) code = code * 4 + (row >>> bit & 1) * 2 + (column >>> bit & 1);
3343
- return code;
3344
- }
3345
- function locationCode(lat, lon) {
3346
- return interleave(latitudeCell(lat), longitudeCell(lon), LOCATION_CODE_BITS_PER_AXIS);
3347
- }
3348
- function appendBoxRanges(box, out) {
3349
- const south = latitudeCell(box.south);
3350
- const north = latitudeCell(box.north);
3351
- const west = longitudeCell(box.west);
3352
- const east = longitudeCell(box.east);
3353
- let level = LOCATION_CODE_BITS_PER_AXIS;
3354
- while (level > 0) {
3355
- const shift2 = LOCATION_CODE_BITS_PER_AXIS - level;
3356
- const rows = (north >>> shift2) - (south >>> shift2) + 1;
3357
- const columns = (east >>> shift2) - (west >>> shift2) + 1;
3358
- if (rows * columns <= MAX_COVERING_CELLS) break;
3359
- level--;
3360
- }
3361
- const shift = LOCATION_CODE_BITS_PER_AXIS - level;
3362
- const codesPerCell = 4 ** shift;
3363
- for (let row = south >>> shift; row <= north >>> shift; row++) {
3364
- for (let column = west >>> shift; column <= east >>> shift; column++) {
3365
- const from = interleave(row, column, level) * codesPerCell;
3366
- out.push({ from, to: from + codesPerCell });
3367
- }
3368
- }
3369
- }
3370
- function coveringRanges(boxes) {
3371
- const ranges = [];
3372
- for (const box of boxes) appendBoxRanges(box, ranges);
3373
- ranges.sort((left, right) => left.from - right.from);
3374
- const merged = [];
3375
- for (const range of ranges) {
3376
- const last = merged[merged.length - 1];
3377
- if (last !== void 0 && range.from <= last.to) {
3378
- if (range.to > last.to) last.to = range.to;
3379
- } else {
3380
- merged.push({ from: range.from, to: range.to });
3381
- }
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;
3382
3341
  }
3383
- return merged;
3342
+ return false;
3384
3343
  }
3385
- function longitudeBoxes(south, north, west, east) {
3386
- if (east - west >= FULL_TURN_DEGREES) {
3387
- return [{ south, north, west: -MAX_LONGITUDE_DEGREES, east: MAX_LONGITUDE_DEGREES }];
3388
- }
3389
- if (west < -MAX_LONGITUDE_DEGREES) {
3390
- return [
3391
- { south, north, west: west + FULL_TURN_DEGREES, east: MAX_LONGITUDE_DEGREES },
3392
- { south, north, west: -MAX_LONGITUDE_DEGREES, east }
3393
- ];
3394
- }
3395
- if (east > MAX_LONGITUDE_DEGREES) {
3396
- return [
3397
- { south, north, west, east: MAX_LONGITUDE_DEGREES },
3398
- { south, north, west: -MAX_LONGITUDE_DEGREES, east: east - FULL_TURN_DEGREES }
3399
- ];
3400
- }
3401
- return [{ south, north, west, east }];
3402
- }
3403
- function radiusBoxes(lat, lon, distanceMeters) {
3404
- const angle = distanceMeters / EARTH_RADIUS_METERS * RADIUS_BOX_MARGIN_RATIO + RADIUS_BOX_MARGIN_RADIANS;
3405
- const angleDegrees = angle / DEG_TO_RAD;
3406
- const south = lat - angleDegrees;
3407
- const north = lat + angleDegrees;
3408
- if (angle >= Math.PI || south <= -MAX_LATITUDE_DEGREES || north >= MAX_LATITUDE_DEGREES) {
3409
- return [
3410
- {
3411
- south: Math.max(south, -MAX_LATITUDE_DEGREES),
3412
- north: Math.min(north, MAX_LATITUDE_DEGREES),
3413
- west: -MAX_LONGITUDE_DEGREES,
3414
- east: MAX_LONGITUDE_DEGREES
3415
- }
3416
- ];
3417
- }
3418
- const spread = Math.asin(Math.sin(angle) / Math.cos(lat * DEG_TO_RAD)) / DEG_TO_RAD;
3419
- return longitudeBoxes(south, north, lon - spread, lon + spread);
3420
- }
3421
-
3422
- // src/geo/haversine.ts
3423
- function haversineDistance(lat1, lon1, lat2, lon2) {
3424
- const phi1 = lat1 * DEG_TO_RAD;
3425
- const phi2 = lat2 * DEG_TO_RAD;
3426
- const deltaPhi = (lat2 - lat1) * DEG_TO_RAD;
3427
- const deltaLambda = (lon2 - lon1) * DEG_TO_RAD;
3428
- const halfDeltaPhi = Math.sin(deltaPhi / 2);
3429
- const halfDeltaLambda = Math.sin(deltaLambda / 2);
3430
- const a = halfDeltaPhi * halfDeltaPhi + Math.cos(phi1) * Math.cos(phi2) * halfDeltaLambda * halfDeltaLambda;
3431
- const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
3432
- return EARTH_RADIUS_METERS * c;
3433
- }
3434
-
3435
- // src/geo/edge-tree.ts
3436
- function buildLongitudeEdgeTree(lons) {
3437
- const n = lons.length;
3438
- const edges = [];
3439
- for (let i = 0; i < n; i++) {
3440
- if (lons[i] !== lons[i === 0 ? n - 1 : i - 1]) edges.push(i);
3441
- }
3442
- const lowOf = (i) => Math.min(lons[i], lons[i === 0 ? n - 1 : i - 1]);
3443
- edges.sort((left, right) => lowOf(left) - lowOf(right));
3444
- const count = edges.length;
3445
- const tree = {
3446
- from: new Int32Array(count),
3447
- to: new Int32Array(count),
3448
- low: new Float64Array(count),
3449
- high: new Float64Array(count),
3450
- subtreeHigh: new Float64Array(count)
3451
- };
3452
- edges.forEach((i, at) => {
3453
- const j = i === 0 ? n - 1 : i - 1;
3454
- tree.from[at] = i;
3455
- tree.to[at] = j;
3456
- tree.low[at] = Math.min(lons[i], lons[j]);
3457
- tree.high[at] = Math.max(lons[i], lons[j]);
3458
- });
3459
- const fillSubtreeHigh = (start, end) => {
3460
- if (start >= end) return Number.NEGATIVE_INFINITY;
3461
- const mid = start + end >>> 1;
3462
- const highest = Math.max(tree.high[mid], fillSubtreeHigh(start, mid), fillSubtreeHigh(mid + 1, end));
3463
- tree.subtreeHigh[mid] = highest;
3464
- return highest;
3465
- };
3466
- fillSubtreeHigh(0, count);
3467
- return tree;
3468
- }
3469
- function forEachEdgeSpanning(tree, lon, visit) {
3470
- const walk = (start, end) => {
3471
- if (start >= end) return;
3472
- const mid = start + end >>> 1;
3473
- if (tree.subtreeHigh[mid] <= lon) return;
3474
- walk(start, mid);
3475
- if (tree.low[mid] > lon) return;
3476
- if (lon < tree.high[mid]) visit(tree.from[mid], tree.to[mid]);
3477
- walk(mid + 1, end);
3478
- };
3479
- walk(0, tree.from.length);
3344
+ function schemaMayDeclare(schema, typeName) {
3345
+ return mayDeclare(schema, typeName, 1);
3480
3346
  }
3481
3347
 
3482
- // src/geo/polygon.ts
3483
- function requirePolygonRing(points) {
3484
- if (!Array.isArray(points) || points.length < MIN_POLYGON_POINTS) {
3485
- throw new NarsilError(
3486
- ErrorCodes.SEARCH_INVALID_FILTER,
3487
- `A polygon encloses an area only with at least ${MIN_POLYGON_POINTS} points`,
3488
- { points: Array.isArray(points) ? points.length : typeof points, minimum: MIN_POLYGON_POINTS }
3489
- );
3490
- }
3491
- points.forEach((point, position) => {
3492
- const { lat, lon } = point ?? {};
3493
- if (typeof lat !== "number" || !Number.isFinite(lat) || typeof lon !== "number" || !Number.isFinite(lon)) {
3494
- throw new NarsilError(
3495
- ErrorCodes.SEARCH_INVALID_FILTER,
3496
- `A polygon point carries a finite "lat" and "lon", and the point at position ${position} does not`,
3497
- { 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
+ }
3498
3364
  );
3499
3365
  }
3500
- if (isLatitude(lat) && isLongitude(lon)) return;
3501
- throw new NarsilError(
3502
- ErrorCodes.SEARCH_INVALID_FILTER,
3503
- `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}`,
3504
- { position, lat, lon }
3505
- );
3506
- });
3507
- }
3508
- function signedArea(polygon) {
3509
- let area = 0;
3510
- for (let i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {
3511
- area += polygon[j].lon * polygon[i].lat - polygon[i].lon * polygon[j].lat;
3512
- }
3513
- return area;
3514
- }
3515
- function crossesAntimeridian(polygon) {
3516
- let west = Number.POSITIVE_INFINITY;
3517
- let east = Number.NEGATIVE_INFINITY;
3518
- for (const point of polygon) {
3519
- if (point.lon < west) west = point.lon;
3520
- if (point.lon > east) east = point.lon;
3521
- }
3522
- return east - west >= ANTIMERIDIAN_SPAN_DEGREES && signedArea(polygon) < 0;
3523
- }
3524
- function eastward(lon) {
3525
- return lon < 0 ? lon + FULL_TURN_DEGREES : lon;
3526
- }
3527
- function polygonContainment(polygon) {
3528
- const n = polygon.length;
3529
- if (n < MIN_POLYGON_POINTS) return () => false;
3530
- const unwrap = crossesAntimeridian(polygon);
3531
- const lats = new Float64Array(n);
3532
- const lons = new Float64Array(n);
3533
- for (let i = 0; i < n; i++) {
3534
- lats[i] = polygon[i].lat;
3535
- lons[i] = unwrap ? eastward(polygon[i].lon) : polygon[i].lon;
3536
- }
3537
- const edges = buildLongitudeEdgeTree(lons);
3538
- return (lat, rawLon) => {
3539
- const lon = unwrap ? eastward(rawLon) : rawLon;
3540
- let inside = false;
3541
- forEachEdgeSpanning(edges, lon, (i, j) => {
3542
- const intersectLat = lats[i] + (lats[j] - lats[i]) / (lons[j] - lons[i]) * (lon - lons[i]);
3543
- if (lat < intersectLat) inside = !inside;
3544
- });
3545
- return inside;
3546
- };
3547
- }
3548
- function polygonBoxes(polygon) {
3549
- if (polygon.length < MIN_POLYGON_POINTS) return [];
3550
- const unwrap = crossesAntimeridian(polygon);
3551
- let south = Number.POSITIVE_INFINITY;
3552
- let north = Number.NEGATIVE_INFINITY;
3553
- let west = Number.POSITIVE_INFINITY;
3554
- let east = Number.NEGATIVE_INFINITY;
3555
- for (const point of polygon) {
3556
- const lon = unwrap ? eastward(point.lon) : point.lon;
3557
- south = Math.min(south, point.lat);
3558
- north = Math.max(north, point.lat);
3559
- west = Math.min(west, lon);
3560
- east = Math.max(east, lon);
3561
- }
3562
- if (west >= MAX_LONGITUDE_DEGREES)
3563
- return longitudeBoxes(south, north, west - FULL_TURN_DEGREES, east - FULL_TURN_DEGREES);
3564
- return longitudeBoxes(south, north, west, east);
3565
- }
3566
-
3567
- // src/geo/vincenty.ts
3568
- var WGS84_A = 6378137;
3569
- var WGS84_F = 1 / 298.257223563;
3570
- var WGS84_B = WGS84_A * (1 - WGS84_F);
3571
- function vincentyDistance(lat1, lon1, lat2, lon2) {
3572
- const phi1 = lat1 * DEG_TO_RAD;
3573
- const phi2 = lat2 * DEG_TO_RAD;
3574
- const L = (lon2 - lon1) * DEG_TO_RAD;
3575
- const U1 = Math.atan((1 - WGS84_F) * Math.tan(phi1));
3576
- const U2 = Math.atan((1 - WGS84_F) * Math.tan(phi2));
3577
- const sinU1 = Math.sin(U1);
3578
- const cosU1 = Math.cos(U1);
3579
- const sinU2 = Math.sin(U2);
3580
- const cosU2 = Math.cos(U2);
3581
- let lambda = L;
3582
- let prevLambda;
3583
- let sinSigma = 0;
3584
- let cosSigma = 0;
3585
- let sigma = 0;
3586
- let sinAlpha = 0;
3587
- let cos2Alpha = 0;
3588
- let cos2SigmaM = 0;
3589
- let iterations = VINCENTY_MAX_ITERATIONS;
3590
- do {
3591
- const sinLambda = Math.sin(lambda);
3592
- const cosLambda = Math.cos(lambda);
3593
- const term1 = cosU2 * sinLambda;
3594
- const term2 = cosU1 * sinU2 - sinU1 * cosU2 * cosLambda;
3595
- sinSigma = Math.sqrt(term1 * term1 + term2 * term2);
3596
- if (sinSigma === 0) return 0;
3597
- cosSigma = sinU1 * sinU2 + cosU1 * cosU2 * cosLambda;
3598
- sigma = Math.atan2(sinSigma, cosSigma);
3599
- sinAlpha = cosU1 * cosU2 * sinLambda / sinSigma;
3600
- cos2Alpha = 1 - sinAlpha * sinAlpha;
3601
- cos2SigmaM = cos2Alpha === 0 ? 0 : cosSigma - 2 * sinU1 * sinU2 / cos2Alpha;
3602
- const C = WGS84_F / 16 * cos2Alpha * (4 + WGS84_F * (4 - 3 * cos2Alpha));
3603
- prevLambda = lambda;
3604
- lambda = L + (1 - C) * WGS84_F * sinAlpha * (sigma + C * sinSigma * (cos2SigmaM + C * cosSigma * (-1 + 2 * cos2SigmaM * cos2SigmaM)));
3605
- } while (Math.abs(lambda - prevLambda) > VINCENTY_CONVERGENCE_THRESHOLD && --iterations > 0);
3606
- if (iterations === 0) {
3607
- return haversineDistance(lat1, lon1, lat2, lon2);
3608
- }
3609
- const uSq = cos2Alpha * (WGS84_A * WGS84_A - WGS84_B * WGS84_B) / (WGS84_B * WGS84_B);
3610
- const A = 1 + uSq / 16384 * (4096 + uSq * (-768 + uSq * (320 - 175 * uSq)));
3611
- const B = uSq / 1024 * (256 + uSq * (-128 + uSq * (74 - 47 * uSq)));
3612
- const deltaSigma = B * sinSigma * (cos2SigmaM + B / 4 * (cosSigma * (-1 + 2 * cos2SigmaM * cos2SigmaM) - B / 6 * cos2SigmaM * (-3 + 4 * sinSigma * sinSigma) * (-3 + 4 * cos2SigmaM * cos2SigmaM)));
3613
- return WGS84_B * A * (sigma - deltaSigma);
3614
- }
3615
-
3616
- // src/geo/geo-index.ts
3617
- var REMOVED_DOC_ID = -1;
3618
- function firstAtOrAfter(entries, code) {
3619
- let lo = 0;
3620
- let hi = entries.length;
3621
- while (lo < hi) {
3622
- const mid = lo + hi >>> 1;
3623
- if (entries[mid].code < code) lo = mid + 1;
3624
- else hi = mid;
3625
- }
3626
- return lo;
3627
- }
3628
- function dropRemoved(entries) {
3629
- let write = 0;
3630
- for (let read = 0; read < entries.length; read++) {
3631
- if (entries[read].docId !== REMOVED_DOC_ID) entries[write++] = entries[read];
3632
- }
3633
- entries.length = write;
3634
- }
3635
- function mergeSortedPending(entries, pending) {
3636
- pending.sort((left2, right2) => left2.code - right2.code || left2.docId - right2.docId);
3637
- const mainLength = entries.length;
3638
- for (const entry of pending) entries.push(entry);
3639
- let left = mainLength - 1;
3640
- let right = pending.length - 1;
3641
- let write = entries.length - 1;
3642
- while (right >= 0) {
3643
- const later = left >= 0 ? entries[left] : void 0;
3644
- const next = pending[right];
3645
- if (later !== void 0 && (later.code > next.code || later.code === next.code && later.docId > next.docId)) {
3646
- entries[write--] = later;
3647
- left--;
3648
- } else {
3649
- entries[write--] = next;
3650
- right--;
3651
- }
3366
+ return loading2;
3652
3367
  }
3653
- }
3654
- function createGeoIndex() {
3655
- let entries = [];
3656
- let pending = [];
3657
- const byDocument = /* @__PURE__ */ new Map();
3658
- let removedCount = 0;
3659
- function ensureSorted() {
3660
- if (removedCount > 0) {
3661
- dropRemoved(entries);
3662
- dropRemoved(pending);
3663
- removedCount = 0;
3664
- }
3665
- if (pending.length === 0) return;
3666
- if (entries.length === 0) {
3667
- pending.sort((left, right) => left.code - right.code || left.docId - right.docId);
3668
- entries = pending;
3669
- } else {
3670
- mergeSortedPending(entries, pending);
3671
- }
3672
- pending = [];
3673
- }
3674
- function removeEntry(entry) {
3675
- byDocument.delete(entry.docId);
3676
- entry.docId = REMOVED_DOC_ID;
3677
- removedCount++;
3678
- const held = entries.length + pending.length;
3679
- if (removedCount >= Math.max(PENDING_REMOVAL_MERGE_FLOOR, held / PENDING_REMOVAL_MERGE_DIVISOR)) ensureSorted();
3680
- }
3681
- function matching(boxes, passes, inside) {
3682
- ensureSorted();
3683
- const within = /* @__PURE__ */ new Set();
3684
- for (const range of coveringRanges(boxes)) {
3685
- for (let at = firstAtOrAfter(entries, range.from); at < entries.length && entries[at].code < range.to; at++) {
3686
- if (passes(entries[at])) within.add(entries[at].docId);
3687
- }
3688
- }
3689
- if (inside) return within;
3690
- const outside = /* @__PURE__ */ new Set();
3691
- for (const entry of entries) {
3692
- if (!within.has(entry.docId)) outside.add(entry.docId);
3693
- }
3694
- return outside;
3695
- }
3696
- const index = {
3697
- insert(internalId, lat, lon) {
3698
- const existing = byDocument.get(internalId);
3699
- if (existing !== void 0) removeEntry(existing);
3700
- const entry = { lat, lon, docId: internalId, code: locationCode(lat, lon) };
3701
- pending.push(entry);
3702
- byDocument.set(internalId, entry);
3703
- },
3704
- remove(internalId) {
3705
- const existing = byDocument.get(internalId);
3706
- if (existing !== void 0) removeEntry(existing);
3707
- },
3708
- radiusQuery(lat, lon, distanceMeters, inside, highPrecision) {
3709
- const distanceFn = highPrecision ? vincentyDistance : haversineDistance;
3710
- return matching(
3711
- radiusBoxes(lat, lon, distanceMeters),
3712
- (entry) => distanceFn(lat, lon, entry.lat, entry.lon) <= distanceMeters,
3713
- inside
3714
- );
3715
- },
3716
- polygonQuery(points, inside) {
3717
- const contains = polygonContainment(points);
3718
- return matching(polygonBoxes(points), (entry) => contains(entry.lat, entry.lon), inside);
3719
- },
3720
- documentsBitset(capacity) {
3721
- const bits = createBitSet(capacity);
3722
- for (const docId of byDocument.keys()) bitsetSet(bits, docId);
3723
- return bits;
3724
- },
3725
- clear() {
3726
- entries = [];
3727
- pending = [];
3728
- byDocument.clear();
3729
- removedCount = 0;
3730
- },
3731
- serialize() {
3732
- ensureSorted();
3733
- 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;
3734
3373
  },
3735
- deserialize(data) {
3736
- index.clear();
3737
- for (const entry of data) index.insert(entry.docId, entry.lat, entry.lon);
3738
- }
3374
+ load,
3375
+ loadFor: (schema) => loaded2 !== null || !schemaMayDeclare(schema, typeName) ? null : load()
3739
3376
  };
3740
- 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);
3741
3384
  }
3742
3385
 
3743
3386
  // src/core/field-index/boolean.ts
@@ -3821,7 +3464,7 @@ function reversedUnits(value) {
3821
3464
  for (let at = value.length - 1; at >= 0; at--) reversed += value[at];
3822
3465
  return reversed;
3823
3466
  }
3824
- function firstAtOrAfter2(sorted, key) {
3467
+ function firstAtOrAfter(sorted, key) {
3825
3468
  let lo = 0;
3826
3469
  let hi = sorted.length;
3827
3470
  while (lo < hi) {
@@ -3831,10 +3474,10 @@ function firstAtOrAfter2(sorted, key) {
3831
3474
  }
3832
3475
  return lo;
3833
3476
  }
3834
- function settledColumn(column, holds) {
3477
+ function settledColumn(column, holds2) {
3835
3478
  const { keys, values } = column;
3836
3479
  const order = [];
3837
- 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);
3838
3481
  order.sort((left, right) => compareUnits(keys[left], keys[right]) || compareUnits(values[left], values[right]));
3839
3482
  const settled2 = { keys: [], values: [] };
3840
3483
  for (const at of order) {
@@ -3846,8 +3489,8 @@ function settledColumn(column, holds) {
3846
3489
  return settled2;
3847
3490
  }
3848
3491
  var ValueAffixes = class {
3849
- constructor(holds, values) {
3850
- this.holds = holds;
3492
+ constructor(holds2, values) {
3493
+ this.holds = holds2;
3851
3494
  for (const value of values) this.add(value);
3852
3495
  }
3853
3496
  forward = { keys: [], values: [] };
@@ -3879,7 +3522,7 @@ var ValueAffixes = class {
3879
3522
  }
3880
3523
  matching(column, start) {
3881
3524
  const found = [];
3882
- 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++) {
3883
3526
  if (!column.keys[at].startsWith(start)) break;
3884
3527
  found.push(column.values[at]);
3885
3528
  }
@@ -4117,7 +3760,7 @@ function removeFromPending(pending, marked, byDocument) {
4117
3760
  }
4118
3761
  pending.length = write;
4119
3762
  }
4120
- function mergeSortedPending2(entries, pending) {
3763
+ function mergeSortedPending(entries, pending) {
4121
3764
  pending.sort((a, b) => a.value - b.value);
4122
3765
  const mainLength = entries.length;
4123
3766
  for (const entry of pending) entries.push(entry);
@@ -4153,7 +3796,7 @@ function createNumericIndex() {
4153
3796
  pending.sort((a, b) => a.value - b.value);
4154
3797
  entries = pending;
4155
3798
  } else {
4156
- mergeSortedPending2(entries, pending);
3799
+ mergeSortedPending(entries, pending);
4157
3800
  }
4158
3801
  pending = [];
4159
3802
  }
@@ -4341,7 +3984,7 @@ function ensureFieldIndex(state, fieldPath, base) {
4341
3984
  } else if ((base === "enum" || base === "enum[]") && !state.enumIndexes.has(fieldPath)) {
4342
3985
  state.enumIndexes.set(fieldPath, createEnumIndex());
4343
3986
  } else if (base === "geopoint" && !state.geoIndexes.has(fieldPath)) {
4344
- state.geoIndexes.set(fieldPath, createGeoIndex());
3987
+ state.geoIndexes.set(fieldPath, createLoadedGeoIndex());
4345
3988
  }
4346
3989
  }
4347
3990
  function getOrCreateNumericIndex(state, fieldPath) {
@@ -4924,6 +4567,33 @@ var FIELD_FILTER_OPERATORS = [
4924
4567
  "polygon"
4925
4568
  ];
4926
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
+
4927
4597
  // src/filters/operands/geo.ts
4928
4598
  function requireFlag(fieldPath, operator, flag, value) {
4929
4599
  if (value === void 0 || typeof value === "boolean") return;
@@ -5287,11 +4957,11 @@ function noteUnknownExpressionKey(expression, walk) {
5287
4957
  return;
5288
4958
  }
5289
4959
  }
5290
- function setOwn(record, key, value) {
4960
+ function setOwn(record2, key, value) {
5291
4961
  if (key === PROTOTYPE_KEY) {
5292
- Object.defineProperty(record, key, { value, enumerable: true, writable: true, configurable: true });
4962
+ Object.defineProperty(record2, key, { value, enumerable: true, writable: true, configurable: true });
5293
4963
  } else {
5294
- record[key] = value;
4964
+ record2[key] = value;
5295
4965
  }
5296
4966
  }
5297
4967
  function ownedOperandOf(value, fieldPath, operator, depth) {
@@ -5302,9 +4972,9 @@ function ownedOperandOf(value, fieldPath, operator, depth) {
5302
4972
  for (let at = 0; at < value.length; at++) owned2.push(ownedOperandOf(value[at], fieldPath, operator, depth + 1));
5303
4973
  return owned2;
5304
4974
  }
5305
- const record = value;
4975
+ const record2 = value;
5306
4976
  const owned = {};
5307
- 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));
5308
4978
  return owned;
5309
4979
  }
5310
4980
  function ownedFieldFilterOf(fieldPath, filter) {
@@ -5532,20 +5202,20 @@ function createValueStore(initialKind) {
5532
5202
  function setNumber(internalId, value) {
5533
5203
  if (numbers === null) return;
5534
5204
  if (internalId >= numbers.length) {
5535
- const grown = new Float64Array(grow2(numbers.length, internalId));
5536
- grown.fill(Number.NaN, numbers.length);
5537
- grown.set(numbers);
5538
- 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;
5539
5209
  }
5540
5210
  numbers[internalId] = value;
5541
5211
  }
5542
5212
  function setBoolean(internalId, value) {
5543
5213
  if (booleans === null) return;
5544
5214
  if (internalId >= booleans.length) {
5545
- const grown = new Uint8Array(grow2(booleans.length, internalId));
5546
- grown.fill(BOOLEAN_MISSING, booleans.length);
5547
- grown.set(booleans);
5548
- 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;
5549
5219
  }
5550
5220
  booleans[internalId] = value;
5551
5221
  }
@@ -5640,7 +5310,7 @@ function liveInternalIds(docStore) {
5640
5310
  return ids;
5641
5311
  }
5642
5312
  function createSortColumnSet(docStore) {
5643
- const columns = /* @__PURE__ */ new Map();
5313
+ const columns2 = /* @__PURE__ */ new Map();
5644
5314
  function rebuildThreshold() {
5645
5315
  const count = docStore.count();
5646
5316
  const fraction = count >> SORT_COLUMN_REBUILD_FRACTION_SHIFT;
@@ -5665,7 +5335,7 @@ function createSortColumnSet(docStore) {
5665
5335
  dirty: /* @__PURE__ */ new Set(),
5666
5336
  dirtyStream: null
5667
5337
  };
5668
- columns.set(key, entry);
5338
+ columns2.set(key, entry);
5669
5339
  return entry;
5670
5340
  }
5671
5341
  function buildDirtyStream(entry) {
@@ -5719,11 +5389,11 @@ function createSortColumnSet(docStore) {
5719
5389
  }
5720
5390
  return {
5721
5391
  holds(field, fieldType, mode) {
5722
- return columns.has(columnKeyOf(field, fieldType, mode));
5392
+ return columns2.has(columnKeyOf(field, fieldType, mode));
5723
5393
  },
5724
5394
  column(field, fieldType, mode) {
5725
5395
  const key = columnKeyOf(field, fieldType, mode);
5726
- let entry = columns.get(key);
5396
+ let entry = columns2.get(key);
5727
5397
  if (entry === void 0) {
5728
5398
  entry = backfill(key, field, fieldType, mode);
5729
5399
  } else if (entry.dirty.size > rebuildThreshold()) {
@@ -5732,14 +5402,14 @@ function createSortColumnSet(docStore) {
5732
5402
  return viewOf(entry);
5733
5403
  },
5734
5404
  record(internalId, document) {
5735
- for (const entry of columns.values()) {
5405
+ for (const entry of columns2.values()) {
5736
5406
  entry.store.set(internalId, toReducedSortValue(readSortField(document, entry.field), entry.mode));
5737
5407
  entry.dirty.add(internalId);
5738
5408
  entry.dirtyStream = null;
5739
5409
  }
5740
5410
  },
5741
5411
  forget(internalId) {
5742
- for (const entry of columns.values()) {
5412
+ for (const entry of columns2.values()) {
5743
5413
  entry.store.clear(internalId);
5744
5414
  entry.dirty.delete(internalId);
5745
5415
  entry.dirtyStream = null;
@@ -5747,16 +5417,16 @@ function createSortColumnSet(docStore) {
5747
5417
  },
5748
5418
  refresh() {
5749
5419
  const threshold = rebuildThreshold();
5750
- for (const entry of columns.values()) {
5420
+ for (const entry of columns2.values()) {
5751
5421
  if (entry.dirty.size > threshold) rebuild(entry);
5752
5422
  }
5753
5423
  },
5754
5424
  fieldCount() {
5755
- return columns.size;
5425
+ return columns2.size;
5756
5426
  },
5757
5427
  estimateBytes() {
5758
5428
  let bytes = 0;
5759
- for (const entry of columns.values()) {
5429
+ for (const entry of columns2.values()) {
5760
5430
  bytes += entry.store.estimateBytes() + estimateOrderBytes(entry.order);
5761
5431
  }
5762
5432
  return bytes;
@@ -5825,26 +5495,26 @@ function compareColumnValue(column, aId, bId, direction) {
5825
5495
  if (!rankIsBetweenValues(aRank)) return 0;
5826
5496
  return compareComparableValues(column.valueOf(aId), column.valueOf(bId), direction);
5827
5497
  }
5828
- function compareCandidates(columns, directions, a, b) {
5829
- for (let i = 0; i < columns.length; i++) {
5830
- 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]);
5831
5501
  if (comparison !== 0) return comparison;
5832
5502
  }
5833
5503
  return compareCodePoints(a.externalId, b.externalId);
5834
5504
  }
5835
- function compareWithAnchor(columns, directions, candidate, anchorKey, anchorId) {
5836
- 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++) {
5837
5507
  const comparison = compareComparableValues(candidate.key[i], anchorKey[i] ?? null, directions[i]);
5838
5508
  if (comparison !== 0) return comparison;
5839
5509
  }
5840
5510
  return compareCodePoints(candidate.externalId, anchorId);
5841
5511
  }
5842
- function insertOrdered(page, entry, columns, directions) {
5512
+ function insertOrdered(page, entry, columns2, directions) {
5843
5513
  let low = 0;
5844
5514
  let high = page.length;
5845
5515
  while (low < high) {
5846
5516
  const mid = low + high >>> 1;
5847
- if (compareCandidates(columns, directions, page[mid], entry) <= 0) low = mid + 1;
5517
+ if (compareCandidates(columns2, directions, page[mid], entry) <= 0) low = mid + 1;
5848
5518
  else high = mid;
5849
5519
  }
5850
5520
  page.splice(low, 0, entry);
@@ -5934,11 +5604,11 @@ function selectSortedPage(state, request) {
5934
5604
  if (limit <= 0 || fields.length === 0) return [];
5935
5605
  const set = state.sortColumns;
5936
5606
  if (set === null) return [];
5937
- const columns = fields.map(
5607
+ const columns2 = fields.map(
5938
5608
  (field, index) => set.column(field, fieldTypes[index], modes[index] ?? defaultSortMode(directions[index] ?? "asc"))
5939
5609
  );
5940
5610
  const resolver = state.docStore.resolver();
5941
- const leading = columns[0];
5611
+ const leading = columns2[0];
5942
5612
  const leadingDirection = directions[0];
5943
5613
  const anchorRank = anchorKey === null || anchorId === null ? null : rankOfValue(leading.order, anchorKey[0] ?? null);
5944
5614
  const next = createStream(leading, leadingDirection, anchorRank);
@@ -5953,17 +5623,17 @@ function selectSortedPage(state, request) {
5953
5623
  if (page.length === limit && rankOrdersAfter(leadingRank, page[limit - 1].leadingRank, leadingDirection)) {
5954
5624
  break;
5955
5625
  }
5956
- const key = new Array(columns.length);
5957
- 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);
5958
5628
  const candidate = { internalId, externalId, leadingRank, key };
5959
5629
  if (anchorKey !== null && anchorId !== null) {
5960
- if (compareWithAnchor(columns, directions, candidate, anchorKey, anchorId) <= 0) continue;
5630
+ if (compareWithAnchor(columns2, directions, candidate, anchorKey, anchorId) <= 0) continue;
5961
5631
  }
5962
5632
  if (page.length === limit) {
5963
- if (compareCandidates(columns, directions, candidate, page[limit - 1]) >= 0) continue;
5633
+ if (compareCandidates(columns2, directions, candidate, page[limit - 1]) >= 0) continue;
5964
5634
  page.pop();
5965
5635
  }
5966
- insertOrdered(page, candidate, columns, directions);
5636
+ insertOrdered(page, candidate, columns2, directions);
5967
5637
  }
5968
5638
  return page.map((entry) => ({ id: entry.externalId, key: entry.key }));
5969
5639
  }
@@ -6046,17 +5716,21 @@ function presentBitsetOf(state, fieldPath, type, capacity) {
6046
5716
  if (base === "number") present = state.numericIndexes.get(fieldPath)?.getAllDocIdsBitset(capacity);
6047
5717
  else if (base === "boolean") present = state.booleanIndexes.get(fieldPath)?.getAllDocIdsBitset(capacity);
6048
5718
  else if (base === "enum") present = state.enumIndexes.get(fieldPath)?.getAllDocIdsBitset(capacity);
6049
- else if (base === "geopoint") present = state.geoIndexes.get(fieldPath)?.documentsBitset(capacity);
5719
+ else if (base === "geopoint") present = geoDocumentsBitset(state, fieldPath, capacity);
6050
5720
  else if (base !== void 0 && keepsValueSize(base)) {
6051
5721
  present = state.sizeIndexes.get(fieldPath)?.getAllDocIdsBitset(capacity);
6052
5722
  }
6053
5723
  return present ?? createBitSet(capacity);
6054
5724
  }
6055
- function liveDocumentsBitset(state, capacity) {
5725
+ function bitsetOfDocuments(internalIds, capacity) {
6056
5726
  const bits = createBitSet(capacity);
6057
- for (const internalId of state.docStore.allInternalIds()) bitsetSet(bits, internalId);
5727
+ for (const internalId of internalIds) bitsetSet(bits, internalId);
6058
5728
  return bits;
6059
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
+ }
6060
5734
  function buildFilterContext(state, schema, meter) {
6061
5735
  const flat = getFlatSchema(state, schema);
6062
5736
  const capacity = state.docStore.internalIdCapacity();
@@ -6108,7 +5782,7 @@ function buildFilterContext(state, schema, meter) {
6108
5782
  },
6109
5783
  capacity,
6110
5784
  get allDocIdsBitset() {
6111
- cachedAllDocIdsBitset ??= liveDocumentsBitset(state, capacity);
5785
+ cachedAllDocIdsBitset ??= bitsetOfDocuments(state.docStore.allInternalIds(), capacity);
6112
5786
  return cachedAllDocIdsBitset;
6113
5787
  }
6114
5788
  };
@@ -6182,7 +5856,7 @@ function requireLoadedPhraseCode() {
6182
5856
  }
6183
5857
  function loadPhraseCode() {
6184
5858
  if (loading === null) {
6185
- loading = import('./phrase-module-RTVKEWJT.mjs').then(
5859
+ loading = import('./phrase-module-QK22HSQ2.mjs').then(
6186
5860
  (code) => {
6187
5861
  loaded = code;
6188
5862
  return code;
@@ -6216,10 +5890,82 @@ function analyseQueryPhrases(term, language, analysis) {
6216
5890
  );
6217
5891
  }
6218
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
+
6219
5965
  // src/core/scorer.ts
6220
5966
  function computeIDF(docFrequency, totalDocs) {
6221
5967
  if (totalDocs === 0) return 0;
6222
- return Math.log((totalDocs - docFrequency + 0.5) / (docFrequency + 0.5) + 1);
5968
+ return log((totalDocs - docFrequency + 0.5) / (docFrequency + 0.5) + 1);
6223
5969
  }
6224
5970
  function pairKeepsBoundSound(k1, b) {
6225
5971
  return k1 >= 0 && k1 <= MAX_BM25_K1 && b >= 0 && b <= MAX_BM25_B;
@@ -6283,6 +6029,43 @@ function computeBM25WithIDF(termFrequency, idf, fieldLength, avgFieldLength, k1,
6283
6029
  return idf * (numerator / denominator);
6284
6030
  }
6285
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
+
6286
6069
  // src/core/partition/field-scoring.ts
6287
6070
  var NO_FIELD_VALUES = new Float64Array(0);
6288
6071
  function differentPairsOf(searchable, k1s, bs) {
@@ -6310,7 +6093,8 @@ function loadFieldScoring(state, fields, boost, averageFieldLengths, bm25) {
6310
6093
  lengthColumns: new Array(fieldCount).fill(null),
6311
6094
  k1s: perField === void 0 ? NO_FIELD_VALUES : new Float64Array(fieldCount),
6312
6095
  bs: perField === void 0 ? NO_FIELD_VALUES : new Float64Array(fieldCount),
6313
- boundPairs: [k1, b]
6096
+ boundPairs: [k1, b],
6097
+ nameRanks: fieldNameRanks(fieldNames)
6314
6098
  };
6315
6099
  for (let fieldIndex = 0; fieldIndex < fieldCount; fieldIndex++) {
6316
6100
  const fieldName = fieldNames[fieldIndex];
@@ -6327,8 +6111,8 @@ function loadFieldScoring(state, fields, boost, averageFieldLengths, bm25) {
6327
6111
  if (perField !== void 0) scoring.boundPairs = differentPairsOf(scoring.searchable, scoring.k1s, scoring.bs);
6328
6112
  return scoring;
6329
6113
  }
6330
- function fieldLengthOf(columns, fieldIndex, internalId, averageLength) {
6331
- const column = fieldIndex < columns.length ? columns[fieldIndex] : null;
6114
+ function fieldLengthOf(columns2, fieldIndex, internalId, averageLength) {
6115
+ const column = fieldIndex < columns2.length ? columns2[fieldIndex] : null;
6332
6116
  if (column === null || internalId >= column.length) return averageLength;
6333
6117
  const stored = column[internalId];
6334
6118
  return stored > 0 ? stored : averageLength;
@@ -6413,20 +6197,26 @@ function termGroupOf(groups, token) {
6413
6197
  function typoMatchesFor(index, token, group, exact, tolerance, prefixLength) {
6414
6198
  if (group !== void 0) {
6415
6199
  if (!group.typoMatches || exact || tolerance === 0) return [];
6416
- 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;
6417
6205
  }
6418
- if (!exact) return index.fuzzyLookup(token, tolerance, prefixLength);
6419
6206
  const postingList = index.lookup(token);
6420
6207
  return postingList ? [{ token, postingList }] : [];
6421
6208
  }
6209
+ function byToken(left, right) {
6210
+ return compareCodePoints(left.token, right.token);
6211
+ }
6422
6212
  function resolveGroupMatches(context, group) {
6423
- const frequencyOf = (token) => context.globalFrequency(token) ?? context.index.documentFrequency(token);
6213
+ const frequencyOf2 = (token) => context.globalFrequency(token) ?? context.index.documentFrequency(token);
6424
6214
  const lookup = (token) => context.index.lookup(token);
6425
6215
  const synonyms = group.synonyms;
6426
- let groupDocumentFrequency = synonyms?.documentFrequency(frequencyOf) ?? 0;
6216
+ let groupDocumentFrequency = synonyms?.documentFrequency(frequencyOf2) ?? 0;
6427
6217
  const found = [];
6428
6218
  for (const member of group.members) {
6429
- const documents = frequencyOf(member.token);
6219
+ const documents = frequencyOf2(member.token);
6430
6220
  if (documents > groupDocumentFrequency) groupDocumentFrequency = documents;
6431
6221
  const postingList = synonyms !== void 0 && member.token === group.token ? synonyms.postings(lookup, member.token) : lookup(member.token);
6432
6222
  if (postingList === void 0) continue;
@@ -6451,10 +6241,20 @@ function computeGroupContributions(context, matches, collect) {
6451
6241
  const { docIds, termFrequencies, fieldNameIndices, deletedDocs, hasDeleted, count } = postingColumns(
6452
6242
  match.postingList
6453
6243
  );
6454
- for (let pi = 0; pi < count; pi++) {
6455
- 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];
6456
6248
  if (hasDeleted && deletedDocs.has(internalId)) continue;
6457
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
+ }
6458
6258
  const fieldIndex = fieldNameIndices[pi];
6459
6259
  if (fields.searchable[fieldIndex] === 0) continue;
6460
6260
  const factor = partialMarks[fieldIndex] === 1 ? match.partialFactor : match.factor;
@@ -6732,7 +6532,7 @@ function mergeFieldIndexes(target, source, idMapping) {
6732
6532
  for (const [fieldPath, index] of source.geoIndexes) {
6733
6533
  let targetIndex = target.geoIndexes.get(fieldPath);
6734
6534
  if (targetIndex === void 0) {
6735
- targetIndex = createGeoIndex();
6535
+ targetIndex = createLoadedGeoIndex();
6736
6536
  target.geoIndexes.set(fieldPath, targetIndex);
6737
6537
  }
6738
6538
  for (const entry of index.serialize()) {
@@ -6763,8 +6563,8 @@ function mergeSegmentState(target, source) {
6763
6563
  // src/core/partition/block-bounds.ts
6764
6564
  var ABSENT_FIELD_LENGTH_BOUND = 0;
6765
6565
  var boundsByList = /* @__PURE__ */ new WeakMap();
6766
- function fieldLengthBound(columns, fieldIndex, internalId) {
6767
- const column = fieldIndex < columns.length ? columns[fieldIndex] : null;
6566
+ function fieldLengthBound(columns2, fieldIndex, internalId) {
6567
+ const column = fieldIndex < columns2.length ? columns2[fieldIndex] : null;
6768
6568
  if (column === null || internalId >= column.length) return ABSENT_FIELD_LENGTH_BOUND;
6769
6569
  const stored = column[internalId];
6770
6570
  return stored > 0 ? stored : ABSENT_FIELD_LENGTH_BOUND;
@@ -6772,7 +6572,7 @@ function fieldLengthBound(columns, fieldIndex, internalId) {
6772
6572
  function entriesCovered(bounds) {
6773
6573
  return bounds.blockCount === 0 ? 0 : bounds.entryEnd[bounds.blockCount - 1];
6774
6574
  }
6775
- function scanPostingBlocks(list, columns, previous, keepBlocks) {
6575
+ function scanPostingBlocks(list, columns2, previous, keepBlocks) {
6776
6576
  const { docIds, termFrequencies, fieldNameIndices, length } = list;
6777
6577
  const startEntry = previous !== null && keepBlocks > 0 ? previous.entryEnd[keepBlocks - 1] : 0;
6778
6578
  const capacity = keepBlocks + Math.ceil((length - startEntry) / TARGET_BLOCK_ENTRIES) + 1;
@@ -6806,7 +6606,7 @@ function scanPostingBlocks(list, columns, previous, keepBlocks) {
6806
6606
  const position = entry + run;
6807
6607
  const termFrequency = termFrequencies[position];
6808
6608
  if (termFrequency > blockMaxTf) blockMaxTf = termFrequency;
6809
- const fieldLength = fieldLengthBound(columns, fieldNameIndices[position], docId);
6609
+ const fieldLength = fieldLengthBound(columns2, fieldNameIndices[position], docId);
6810
6610
  if (fieldLength < blockMinLen) blockMinLen = fieldLength;
6811
6611
  }
6812
6612
  run++;
@@ -6840,19 +6640,19 @@ function scanPostingBlocks(list, columns, previous, keepBlocks) {
6840
6640
  documentCount
6841
6641
  };
6842
6642
  }
6843
- function blockBoundsFor(list, columns) {
6643
+ function blockBoundsFor(list, columns2) {
6844
6644
  const existing = boundsByList.get(list);
6845
6645
  if (existing !== void 0 && existing.structureRevision === list.structureRevision) {
6846
6646
  const covered = entriesCovered(existing);
6847
6647
  if (covered === list.length) return existing;
6848
6648
  if (list.ordered && covered < list.length) {
6849
- 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));
6850
6650
  boundsByList.set(list, extended);
6851
6651
  return extended;
6852
6652
  }
6853
6653
  }
6854
6654
  const stored = list.storedBlockBounds?.() ?? null;
6855
- 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 };
6856
6656
  boundsByList.set(list, built);
6857
6657
  return built;
6858
6658
  }
@@ -6913,9 +6713,9 @@ function beginScoring(buffer, capacity) {
6913
6713
  }
6914
6714
  function appendTouched(buffer, internalId) {
6915
6715
  if (buffer.touchedCount === buffer.touched.length) {
6916
- const grown = new Int32Array(buffer.touched.length * 2);
6917
- grown.set(buffer.touched);
6918
- buffer.touched = grown;
6716
+ const grown2 = new Int32Array(buffer.touched.length * 2);
6717
+ grown2.set(buffer.touched);
6718
+ buffer.touched = grown2;
6919
6719
  }
6920
6720
  buffer.touched[buffer.touchedCount] = internalId;
6921
6721
  buffer.touchedCount++;
@@ -7005,13 +6805,13 @@ function topKFromBuffer(buffer, k, resolver, components) {
7005
6805
  const result = new Array(heap.length);
7006
6806
  for (let index = 0; index < heap.length; index++) {
7007
6807
  const entry = heap[index];
7008
- const record = components?.get(entry.internalId);
6808
+ const record2 = components?.get(entry.internalId);
7009
6809
  result[index] = {
7010
6810
  docId: entry.externalId,
7011
6811
  score: entry.score,
7012
- termFrequencies: record?.termFrequencies ?? EMPTY_COMPONENTS,
7013
- fieldLengths: record?.fieldLengths ?? EMPTY_COMPONENTS,
7014
- idf: record?.idf ?? EMPTY_COMPONENTS
6812
+ termFrequencies: record2?.termFrequencies ?? EMPTY_COMPONENTS,
6813
+ fieldLengths: record2?.fieldLengths ?? EMPTY_COMPONENTS,
6814
+ idf: record2?.idf ?? EMPTY_COMPONENTS
7015
6815
  };
7016
6816
  }
7017
6817
  return result;
@@ -7081,20 +6881,20 @@ function fieldPairUpperBound(scan, list, maxBoost, maxAverageLength) {
7081
6881
  return best;
7082
6882
  }
7083
6883
  function samePairEntryScore(scan, entry, internalId) {
7084
- const { fields, columns } = scan;
7085
- const fieldIndex = columns.fieldNameIndices[entry];
6884
+ const { fields, columns: columns2 } = scan;
6885
+ const fieldIndex = columns2.fieldNameIndices[entry];
7086
6886
  const averageLength = fields.averageLengths[fieldIndex];
7087
6887
  const fieldLength = fieldLengthOf(fields.lengthColumns, fieldIndex, internalId, averageLength);
7088
- 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);
7089
6889
  return bm25 * fields.boosts[fieldIndex];
7090
6890
  }
7091
6891
  function fieldPairEntryScore(scan, entry, internalId) {
7092
- const { fields, columns } = scan;
7093
- const fieldIndex = columns.fieldNameIndices[entry];
6892
+ const { fields, columns: columns2 } = scan;
6893
+ const fieldIndex = columns2.fieldNameIndices[entry];
7094
6894
  const averageLength = fields.averageLengths[fieldIndex];
7095
6895
  const fieldLength = fieldLengthOf(fields.lengthColumns, fieldIndex, internalId, averageLength);
7096
6896
  const bm25 = scan.scoresAreZero ? 0 : computeBM25WithIDF(
7097
- columns.termFrequencies[entry],
6897
+ columns2.termFrequencies[entry],
7098
6898
  scan.idf,
7099
6899
  fieldLength,
7100
6900
  averageLength,
@@ -7159,15 +6959,30 @@ function firstEntryOf(docIds, count, internalId) {
7159
6959
  }
7160
6960
  return low;
7161
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
+ }
7162
6973
  function samePairQueryOrderScore(scans, internalId) {
7163
6974
  let score = 0;
7164
6975
  for (const scan of scans) {
7165
6976
  const { docIds, deletedDocs, hasDeleted, count } = scan.columns;
7166
6977
  if (hasDeleted && deletedDocs.has(internalId)) continue;
7167
- for (let entry = firstEntryOf(docIds, count, internalId); entry < count && docIds[entry] === internalId; entry++) {
7168
- if (scan.fields.searchable[scan.columns.fieldNameIndices[entry]] !== 1) continue;
7169
- 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;
7170
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);
7171
6986
  }
7172
6987
  return score;
7173
6988
  }
@@ -7176,10 +6991,14 @@ function fieldPairQueryOrderScore(scans, internalId) {
7176
6991
  for (const scan of scans) {
7177
6992
  const { docIds, deletedDocs, hasDeleted, count } = scan.columns;
7178
6993
  if (hasDeleted && deletedDocs.has(internalId)) continue;
7179
- for (let entry = firstEntryOf(docIds, count, internalId); entry < count && docIds[entry] === internalId; entry++) {
7180
- if (scan.fields.searchable[scan.columns.fieldNameIndices[entry]] !== 1) continue;
7181
- 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;
7182
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);
7183
7002
  }
7184
7003
  return score;
7185
7004
  }
@@ -7317,7 +7136,8 @@ function singleTermTopK(request) {
7317
7136
  lengthColumns: fieldLengthColumns,
7318
7137
  k1s,
7319
7138
  bs,
7320
- boundPairs
7139
+ boundPairs,
7140
+ nameRanks
7321
7141
  } = request.fields;
7322
7142
  const onePair = boundPairs.length === 2;
7323
7143
  const onlyK1 = boundPairs[0];
@@ -7357,12 +7177,14 @@ function singleTermTopK(request) {
7357
7177
  }
7358
7178
  let score = 0;
7359
7179
  let scored2 = false;
7360
- while (entry < end && docIds[entry] === internalId) {
7361
- 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];
7362
7184
  if (fieldSearchable[fieldIndex] === 1) {
7363
7185
  const fieldLength = fieldLengthOf(fieldLengthColumns, fieldIndex, internalId, fieldAvgLengths[fieldIndex]);
7364
7186
  score += (scoresAreZero ? 0 : computeBM25WithIDF(
7365
- termFrequencies[entry],
7187
+ termFrequencies[row],
7366
7188
  idf,
7367
7189
  fieldLength,
7368
7190
  fieldAvgLengths[fieldIndex],
@@ -7371,7 +7193,6 @@ function singleTermTopK(request) {
7371
7193
  )) * fieldBoosts[fieldIndex];
7372
7194
  scored2 = true;
7373
7195
  }
7374
- entry++;
7375
7196
  }
7376
7197
  if (!scored2) continue;
7377
7198
  totalMatched++;
@@ -7411,6 +7232,10 @@ function singleTermTopK(request) {
7411
7232
  }
7412
7233
 
7413
7234
  // src/core/partition/search.ts
7235
+ var nativeKeywordSearch = null;
7236
+ function installNativeKeywordSearch(search) {
7237
+ nativeKeywordSearch = search;
7238
+ }
7414
7239
  function globalDocFreqFor(docFreqs, term, fallback) {
7415
7240
  return Object.hasOwn(docFreqs, term) ? docFreqs[term] : fallback;
7416
7241
  }
@@ -7437,15 +7262,11 @@ function searchFulltext(state, params) {
7437
7262
  const totalDocs = globalStats?.totalDocuments ?? state.stats.totalDocuments;
7438
7263
  const avgFieldLengths = globalStats?.averageFieldLengths ?? state.stats.averageFieldLengths;
7439
7264
  const scoresAreZero = totalDocs === 0;
7440
- if (state.scoreBuffer === null) state.scoreBuffer = createScoreBuffer(state.docStore.internalIdCapacity());
7441
- const scoreBuffer = state.scoreBuffer;
7442
- beginScoring(scoreBuffer, state.docStore.internalIdCapacity());
7443
- const components = collectComponents ? /* @__PURE__ */ new Map() : null;
7444
7265
  const useIntersection = termMatch === "all" && queryTokens.length > 1;
7445
7266
  const fieldNames = state.fieldNameTable.names;
7446
7267
  const resolver = state.docStore.resolver();
7447
7268
  const fieldScoring = loadFieldScoring(state, fields, boost, avgFieldLengths, bm25Params);
7448
- const { searchable, boosts, averageLengths, lengthColumns, k1s, bs, boundPairs } = fieldScoring;
7269
+ const { searchable, boosts, averageLengths, lengthColumns, k1s, bs, boundPairs, nameRanks } = fieldScoring;
7449
7270
  const onePair = boundPairs.length === 2;
7450
7271
  const onlyK1 = boundPairs[0];
7451
7272
  const onlyB = boundPairs[1];
@@ -7461,7 +7282,13 @@ function searchFulltext(state, params) {
7461
7282
  if (phraseMatches !== null && bitsetIsEmpty(phraseMatches.matched)) {
7462
7283
  return { scored: [], totalMatched: 0 };
7463
7284
  }
7285
+ const inTheCore = nativeKeywordSearch?.(state, params, phraseMatches);
7286
+ if (inTheCore) return inTheCore;
7464
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;
7465
7292
  function documentFrequency(token, list) {
7466
7293
  return globalStats ? globalDocFreqFor(globalStats.docFrequencies, token, list.docIdSet.size) : list.docIdSet.size;
7467
7294
  }
@@ -7470,25 +7297,35 @@ function searchFulltext(state, params) {
7470
7297
  for (let entry = 0; entry < rows.phrase.tokens.length; entry++) {
7471
7298
  idf += computeIDF(documentFrequency(rows.phrase.tokens[entry], rows.lists[entry]), totalDocs);
7472
7299
  }
7473
- for (let row = 0; row < rows.docIds.length; row++) {
7474
- const internalId = rows.docIds.values[row];
7475
- if (!bitsetHas(matched, internalId)) continue;
7476
- const fieldIndex = rows.fieldIndices.values[row];
7477
- const frequency = rows.frequencies.values[row];
7478
- const avgLen = averageLengths[fieldIndex];
7479
- const fieldLength = fieldLengthOf(lengthColumns, fieldIndex, internalId, avgLen);
7480
- const score = scoresAreZero ? 0 : computeBM25WithIDF(
7481
- frequency,
7482
- idf,
7483
- fieldLength,
7484
- avgLen,
7485
- onePair ? onlyK1 : k1s[fieldIndex],
7486
- 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
7487
7307
  );
7488
- addScore(scoreBuffer, internalId, score * boosts[fieldIndex]);
7489
- if (components !== null) {
7490
- recordComponents(components, internalId, fieldNames[fieldIndex], rows.phrase.key, frequency, fieldLength, idf);
7491
- }
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);
7492
7329
  }
7493
7330
  }
7494
7331
  const groupContext = {
@@ -7511,13 +7348,23 @@ function searchFulltext(state, params) {
7511
7348
  const docFreq = documentFrequency(token, postingList);
7512
7349
  return { token, docFreq, idf: computeIDF(docFreq, totalDocs), postingList };
7513
7350
  }
7514
- function scorePostings(match, onlyScored) {
7351
+ function scorePostings(match, only) {
7515
7352
  const { docIds, termFrequencies, fieldNameIndices, deletedDocs, hasDeleted, count } = postingColumns(
7516
7353
  match.postingList
7517
7354
  );
7518
- if (!onlyScored && !hasDeleted && filterBitset === void 0 && components === null) {
7519
- for (let pi = 0; pi < count; pi++) {
7520
- 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
+ }
7521
7368
  const fieldIndex = fieldNameIndices[pi];
7522
7369
  if (searchable[fieldIndex] === 0) continue;
7523
7370
  const avgLen = averageLengths[fieldIndex];
@@ -7534,11 +7381,19 @@ function searchFulltext(state, params) {
7534
7381
  }
7535
7382
  return;
7536
7383
  }
7537
- for (let pi = 0; pi < count; pi++) {
7538
- const internalId = docIds[pi];
7384
+ for (let at = 0; at < count; at++) {
7385
+ const internalId = docIds[at];
7539
7386
  if (hasDeleted && deletedDocs.has(internalId)) continue;
7540
7387
  if (filterBitset && !bitsetHas(filterBitset, internalId)) continue;
7541
- 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
+ }
7542
7397
  const fieldIndex = fieldNameIndices[pi];
7543
7398
  if (searchable[fieldIndex] === 0) continue;
7544
7399
  const termFrequency = termFrequencies[pi];
@@ -7566,10 +7421,10 @@ function searchFulltext(state, params) {
7566
7421
  }
7567
7422
  }
7568
7423
  }
7569
- function scoreGroup(group, onlyScored) {
7424
+ function scoreGroup(group, only) {
7570
7425
  if (group === null) return;
7571
7426
  for (const [internalId, contribution] of computeGroupContributions(groupContext, group, collectComponents)) {
7572
- if (onlyScored && !hasScore(scoreBuffer, internalId)) continue;
7427
+ if (only !== null && !bitsetHas(only, internalId)) continue;
7573
7428
  mergeGroupContribution(internalId, contribution);
7574
7429
  }
7575
7430
  }
@@ -7610,19 +7465,27 @@ function searchFulltext(state, params) {
7610
7465
  }
7611
7466
  resolved.push({ token: qt.token, matches, totalPostings, group: groupMatches });
7612
7467
  }
7613
- resolved.sort((a, b) => a.totalPostings - b.totalPostings);
7614
- for (let tokenIndex = 0; tokenIndex < resolved.length; tokenIndex++) {
7615
- const onlyScored = tokenIndex > 0;
7616
- for (const match of resolved[tokenIndex].matches) scorePostings(match, onlyScored);
7617
- 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);
7618
7481
  }
7619
7482
  } else {
7620
7483
  for (const qt of queryTokens) {
7621
7484
  const group = termGroupOf(termGroups, qt.token);
7622
7485
  for (const m of typoMatchesFor(state.invertedIdx, qt.token, group, exact, tolerance, prefixLength)) {
7623
- scorePostings(resolveMatch(m.token, m.postingList), false);
7486
+ scorePostings(resolveMatch(m.token, m.postingList), null);
7624
7487
  }
7625
- if (group !== void 0) scoreGroup(resolveGroupMatches(groupContext, group), false);
7488
+ if (group !== void 0) scoreGroup(resolveGroupMatches(groupContext, group), null);
7626
7489
  }
7627
7490
  }
7628
7491
  if (phraseMatches !== null) {
@@ -7748,7 +7611,7 @@ function lookupReadOnce(state, token) {
7748
7611
  }
7749
7612
  function encodeFieldLengths(state, remap, documentCount) {
7750
7613
  const names = [];
7751
- const columns = [];
7614
+ const columns2 = [];
7752
7615
  const totals = {};
7753
7616
  for (const fieldName of Object.keys(state.stats.totalFieldLengths)) {
7754
7617
  const column = state.docStore.fieldLengthColumn(fieldName);
@@ -7762,10 +7625,10 @@ function encodeFieldLengths(state, remap, documentCount) {
7762
7625
  total += column[internalId];
7763
7626
  }
7764
7627
  names.push(fieldName);
7765
- columns.push(packed);
7628
+ columns2.push(packed);
7766
7629
  totals[fieldName] = total;
7767
7630
  }
7768
- return { names, columns, totals };
7631
+ return { names, columns: columns2, totals };
7769
7632
  }
7770
7633
  function encodeSegmentState(state) {
7771
7634
  const { remap, docIds } = buildOrdinalRemap(state);
@@ -7908,7 +7771,7 @@ function mergePayloadFieldIndexes(target, payload, ordinalBase) {
7908
7771
  for (const entry of payload.geo) {
7909
7772
  let index = target.geoIndexes.get(entry.fieldPath);
7910
7773
  if (index === void 0) {
7911
- index = createGeoIndex();
7774
+ index = createLoadedGeoIndex();
7912
7775
  target.geoIndexes.set(entry.fieldPath, index);
7913
7776
  }
7914
7777
  for (let i = 0; i < entry.docIds.length; i++) {
@@ -8142,7 +8005,7 @@ function deserializePartition(state, data, clearFn, schema) {
8142
8005
  state.enumIndexes.set(path, idx);
8143
8006
  }
8144
8007
  for (const [path, entries] of Object.entries(data.fieldIndexes.geopoint)) {
8145
- const geoIdx = createGeoIndex();
8008
+ const geoIdx = createLoadedGeoIndex();
8146
8009
  const converted = entries.map((e) => ({
8147
8010
  lat: e.lat,
8148
8011
  lon: e.lon,
@@ -9474,22 +9337,22 @@ function createWriteLogRecorder() {
9474
9337
  const current = [null, null];
9475
9338
  return {
9476
9339
  open(owner) {
9477
- const log = { docIds: /* @__PURE__ */ new Set(), replaced: false };
9478
- current[owner] = log;
9340
+ const log2 = { docIds: /* @__PURE__ */ new Set(), replaced: false };
9341
+ current[owner] = log2;
9479
9342
  return {
9480
9343
  get partitionsReplaced() {
9481
- return log.replaced;
9344
+ return log2.replaced;
9482
9345
  },
9483
9346
  get pendingDocuments() {
9484
- return log.docIds.size;
9347
+ return log2.docIds.size;
9485
9348
  },
9486
9349
  takeWrittenDocIds() {
9487
- const taken = log.docIds;
9488
- log.docIds = /* @__PURE__ */ new Set();
9350
+ const taken = log2.docIds;
9351
+ log2.docIds = /* @__PURE__ */ new Set();
9489
9352
  return taken;
9490
9353
  },
9491
9354
  close() {
9492
- if (current[owner] === log) current[owner] = null;
9355
+ if (current[owner] === log2) current[owner] = null;
9493
9356
  }
9494
9357
  };
9495
9358
  },
@@ -9498,17 +9361,17 @@ function createWriteLogRecorder() {
9498
9361
  current[1]?.docIds.add(docId);
9499
9362
  },
9500
9363
  segmentWritten(segment) {
9501
- for (const log of current) {
9502
- if (log === null) continue;
9364
+ for (const log2 of current) {
9365
+ if (log2 === null) continue;
9503
9366
  for (const internalId of segment.docStore.allInternalIds()) {
9504
9367
  const docId = segment.docStore.getExternalId(internalId);
9505
- if (docId !== void 0) log.docIds.add(docId);
9368
+ if (docId !== void 0) log2.docIds.add(docId);
9506
9369
  }
9507
9370
  }
9508
9371
  },
9509
9372
  partitionsReplaced() {
9510
- for (const log of current) {
9511
- if (log !== null) log.replaced = true;
9373
+ for (const log2 of current) {
9374
+ if (log2 !== null) log2.replaced = true;
9512
9375
  }
9513
9376
  }
9514
9377
  };
@@ -10945,6 +10808,22 @@ async function runQueryAction(entry, action) {
10945
10808
  return { count: result.totalMatched };
10946
10809
  }
10947
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
+
10948
10827
  // src/core/partition/frozen/doc-table.ts
10949
10828
  function createFrozenDocTable(idTable, lengthColumns, documents, tombstones) {
10950
10829
  const capacity = idTable.count;
@@ -11780,17 +11659,17 @@ function createFrozenInvertedReader(table, views, counts) {
11780
11659
  // src/core/partition/frozen/live-counts.ts
11781
11660
  var UINT32_BYTES = 4;
11782
11661
  var FLOAT64_BYTES = 8;
11783
- function removalIndexBytes(columns, terms) {
11784
- const documentWords = 2 * (columns.documentCount + 1);
11785
- 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;
11786
11665
  }
11787
11666
  function processHasRoomFor(bytes) {
11788
11667
  const memory = readResidentMemory();
11789
11668
  if (memory === null) return true;
11790
11669
  return memory.residentBytes + bytes <= FROZEN_REMOVAL_INDEX_MAX_PROCESS_FRACTION * memory.limitBytes;
11791
11670
  }
11792
- function buildRemovalIndex(columns, table) {
11793
- const { documentCount, postingDocIds } = columns;
11671
+ function buildRemovalIndex(columns2, table) {
11672
+ const { documentCount, postingDocIds } = columns2;
11794
11673
  const starts = new Uint32Array(documentCount + 1);
11795
11674
  for (let row = 0; row < postingDocIds.length; row++) starts[postingDocIds[row] + 1]++;
11796
11675
  for (let ordinal = 0; ordinal < documentCount; ordinal++) starts[ordinal + 1] += starts[ordinal];
@@ -11809,10 +11688,10 @@ function buildRemovalIndex(columns, table) {
11809
11688
  occurrences: new Float64Array(table.size)
11810
11689
  };
11811
11690
  }
11812
- function tryBuildRemovalIndex(columns, table) {
11813
- if (!processHasRoomFor(removalIndexBytes(columns, table.size))) return null;
11691
+ function tryBuildRemovalIndex(columns2, table) {
11692
+ if (!processHasRoomFor(removalIndexBytes(columns2, table.size))) return null;
11814
11693
  try {
11815
- return buildRemovalIndex(columns, table);
11694
+ return buildRemovalIndex(columns2, table);
11816
11695
  } catch (error) {
11817
11696
  if (error instanceof RangeError) return null;
11818
11697
  throw error;
@@ -11828,8 +11707,8 @@ function slotOfRow(postingOffsets, slots, row) {
11828
11707
  }
11829
11708
  return low;
11830
11709
  }
11831
- function createFrozenLiveCounts(columns, table, tombstones, storedFrequencies) {
11832
- const { postingOffsets, postingDocIds, postingFrequencies } = columns;
11710
+ function createFrozenLiveCounts(columns2, table, tombstones, storedFrequencies) {
11711
+ const { postingOffsets, postingDocIds, postingFrequencies } = columns2;
11833
11712
  let index = null;
11834
11713
  let lengths = null;
11835
11714
  let frequencies = null;
@@ -11883,10 +11762,10 @@ function createFrozenLiveCounts(columns, table, tombstones, storedFrequencies) {
11883
11762
  }
11884
11763
  return {
11885
11764
  totalDocuments() {
11886
- return columns.documentCount - tombstones.size;
11765
+ return columns2.documentCount - tombstones.size;
11887
11766
  },
11888
11767
  totalFieldLengths() {
11889
- return lengths ?? columns.totalFieldLengths;
11768
+ return lengths ?? columns2.totalFieldLengths;
11890
11769
  },
11891
11770
  documentFrequency,
11892
11771
  removedOccurrences(sortedIndex) {
@@ -11907,15 +11786,15 @@ function createFrozenLiveCounts(columns, table, tombstones, storedFrequencies) {
11907
11786
  return frequencies;
11908
11787
  },
11909
11788
  subtractRemoved(ordinal) {
11910
- lengths ??= { ...columns.totalFieldLengths };
11911
- for (let field = 0; field < columns.fieldLengthNames.length; field++) {
11912
- 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];
11913
11792
  }
11914
11793
  if (index !== null) {
11915
11794
  countRemoval(index, ordinal);
11916
11795
  return;
11917
11796
  }
11918
- const built = tryBuildRemovalIndex(columns, table);
11797
+ const built = tryBuildRemovalIndex(columns2, table);
11919
11798
  if (built === null) return;
11920
11799
  for (const removed of tombstones.values()) countRemoval(built, removed);
11921
11800
  index = built;
@@ -12079,7 +11958,7 @@ function createFrozenSurfaceSlot(load, documents, tableOnDisk) {
12079
11958
  for (const spelling of spellings) target.subtract(spelling, 1);
12080
11959
  }
12081
11960
  }
12082
- function loaded3() {
11961
+ function loaded2() {
12083
11962
  if (registry === null) {
12084
11963
  const built = createSurfaceRegistry();
12085
11964
  const forms = load();
@@ -12098,10 +11977,10 @@ function createFrozenSurfaceSlot(load, documents, tableOnDisk) {
12098
11977
  return {
12099
11978
  heldBytes: () => table?.heldBytes() ?? 0,
12100
11979
  reader: {
12101
- candidatesForPrefix: (prefix) => table !== void 0 && waitingRemovals.length === 0 ? table.candidatesForPrefix(prefix) : loaded3().candidatesForPrefix(prefix),
12102
- stemChangedTotalFor: (token) => loaded3().stemChangedTotalFor(token),
12103
- size: () => loaded3().size(),
12104
- 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()
12105
11984
  },
12106
11985
  tableStaysOnDisk() {
12107
11986
  return registry === null && tableOnDisk !== void 0;
@@ -12113,20 +11992,20 @@ function createFrozenSurfaceSlot(load, documents, tableOnDisk) {
12113
11992
  waitingRemovals.push(ordinal);
12114
11993
  },
12115
11994
  holdsAny() {
12116
- return loaded3().size() > 0;
11995
+ return loaded2().size() > 0;
12117
11996
  },
12118
11997
  holds(spelling) {
12119
- return loaded3().holds(spelling);
11998
+ return loaded2().holds(spelling);
12120
11999
  },
12121
12000
  subtractSpellings(ordinal, spellings) {
12122
12001
  uncounted ??= new Uint8Array(documents.count);
12123
12002
  uncounted[ordinal] = 1;
12124
12003
  if (spellings.length === 0) return;
12125
- const target = loaded3();
12004
+ const target = loaded2();
12126
12005
  for (const spelling of spellings) target.subtract(spelling, 1);
12127
12006
  },
12128
12007
  addKeptForms(target, mergedOrdinals, analysis) {
12129
- const source = loaded3();
12008
+ const source = loaded2();
12130
12009
  if (analysis === null) {
12131
12010
  addForms(target, source.serialize());
12132
12011
  return;
@@ -12528,7 +12407,7 @@ function storedFrequenciesOf(source) {
12528
12407
  function buildGeoReaders(entries) {
12529
12408
  const readers = /* @__PURE__ */ new Map();
12530
12409
  for (const entry of entries) {
12531
- const index = createGeoIndex();
12410
+ const index = createLoadedGeoIndex();
12532
12411
  for (let i = 0; i < entry.docIds.length; i++) {
12533
12412
  index.insert(entry.docIds[i], entry.latitudes[i], entry.longitudes[i]);
12534
12413
  }
@@ -12584,6 +12463,7 @@ function assembleFrozenSegment(segmentId, source, documentSource, sharedSnapshot
12584
12463
  sharedSnapshot,
12585
12464
  paged: pagedParts?.access ?? null,
12586
12465
  arrays: source,
12466
+ tombstones,
12587
12467
  invertedIdx: createFrozenInvertedReader(source.tokenTable, postingViews, counts),
12588
12468
  docStore,
12589
12469
  stats: buildStatsView(counts),
@@ -13051,7 +12931,7 @@ function fieldIndexRemapOf(segment, fieldNames) {
13051
12931
  }
13052
12932
  function mergeFieldLengths(inputs, documentCount) {
13053
12933
  const names = [];
13054
- const columns = [];
12934
+ const columns2 = [];
13055
12935
  const totals = {};
13056
12936
  for (const input of inputs) {
13057
12937
  const arrays = input.segment.arrays;
@@ -13062,11 +12942,11 @@ function mergeFieldLengths(inputs, documentCount) {
13062
12942
  if (at < 0) {
13063
12943
  at = names.length;
13064
12944
  names.push(name);
13065
- columns.push(new Uint32Array(documentCount));
12945
+ columns2.push(new Uint32Array(documentCount));
13066
12946
  totals[name] = 0;
13067
12947
  }
13068
12948
  const source = arrays.fieldLengthColumns[f];
13069
- const column = columns[at];
12949
+ const column = columns2[at];
13070
12950
  for (let ordinal = 0; ordinal < source.length; ordinal++) {
13071
12951
  const target = remap[ordinal];
13072
12952
  if (target < 0) continue;
@@ -13075,7 +12955,7 @@ function mergeFieldLengths(inputs, documentCount) {
13075
12955
  }
13076
12956
  }
13077
12957
  }
13078
- return { fieldLengthNames: names, fieldLengthColumns: columns, totalFieldLengths: totals };
12958
+ return { fieldLengthNames: names, fieldLengthColumns: columns2, totalFieldLengths: totals };
13079
12959
  }
13080
12960
  function mergeSurfaceForms2(inputs, analysis) {
13081
12961
  const registry = createSurfaceRegistry();
@@ -13367,7 +13247,7 @@ function indexFilterValue(indexes, ordinal, fieldPath, fieldType, value) {
13367
13247
  for (const entry of fieldType === "enum" ? [value] : value) index.insert(ordinal, entry);
13368
13248
  } else if (fieldType === "geopoint") {
13369
13249
  const point = value;
13370
- indexOf(indexes.geoIndexes, fieldPath, createGeoIndex).insert(ordinal, point.lat, point.lon);
13250
+ indexOf(indexes.geoIndexes, fieldPath, createLoadedGeoIndex).insert(ordinal, point.lat, point.lon);
13371
13251
  }
13372
13252
  }
13373
13253
  function refuseRepeatedDocIds(documents) {
@@ -13518,7 +13398,7 @@ async function attachSegments(entry, action) {
13518
13398
  growPartitionsTo(entry.manager, segment.partitionId);
13519
13399
  const surfaceForms = segment.survivingSurfaceForms;
13520
13400
  const spellings = surfaceForms === void 0 ? void 0 : NO_REMOVED_SPELLINGS;
13521
- const frozen = isPagedSnapshot(segment.snapshot) ? (await import('./module-ZL5ZG6YB.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);
13522
13402
  for (const docId of segment.tombstonedDocIds ?? []) frozen.tombstoneDocument(docId, spellings);
13523
13403
  entry.manager.attachFrozenSegment(segment.partitionId, frozen);
13524
13404
  }
@@ -13573,7 +13453,7 @@ function runSegmentAction(entry, action) {
13573
13453
  case "attachSegments":
13574
13454
  return attachSegments(entry, action);
13575
13455
  case "adoptDiskSegments":
13576
- return import('./module-ZL5ZG6YB.mjs').then((code) => code.adoptSegmentsOnWorker(entry.manager, action));
13456
+ return import('./module-LBZPGOWH.mjs').then((code) => code.adoptSegmentsOnWorker(entry.manager, action));
13577
13457
  case "compactSegments": {
13578
13458
  const partition = requireComposite(entry, action.indexName, action.partitionId, "compact");
13579
13459
  return mergeFrozenSegments(
@@ -13607,47 +13487,6 @@ function runSegmentAction(entry, action) {
13607
13487
  }
13608
13488
  }
13609
13489
 
13610
- // src/workers/vector-code.ts
13611
- var VECTOR_TYPE_NAME = "vector";
13612
- var loaded2 = null;
13613
- var loading2 = null;
13614
- function loadedVectorCode() {
13615
- return loaded2;
13616
- }
13617
- function requireLoadedVectorCode() {
13618
- if (loaded2 === null) throw new Error("The engine reached vector code before it loaded that code");
13619
- return loaded2;
13620
- }
13621
- function loadVectorCode() {
13622
- if (loaded2 !== null) return Promise.resolve(loaded2);
13623
- if (loading2 === null) {
13624
- loading2 = import('./module-H5MVPSP2.mjs').then(
13625
- (code) => {
13626
- loaded2 = code;
13627
- return code;
13628
- },
13629
- (err) => {
13630
- loading2 = null;
13631
- throw err;
13632
- }
13633
- );
13634
- }
13635
- return loading2;
13636
- }
13637
- function mayDeclareVectorField(schema, depth) {
13638
- if (!isPlainObject(schema) || depth > MAX_NESTING_DEPTH + 1) return false;
13639
- for (const type of Object.values(schema)) {
13640
- if (typeof type === "string" ? type.includes(VECTOR_TYPE_NAME) : mayDeclareVectorField(type, depth + 1)) {
13641
- return true;
13642
- }
13643
- }
13644
- return false;
13645
- }
13646
- function loadVectorCodeFor(schema) {
13647
- if (loaded2 !== null || !mayDeclareVectorField(schema, 1)) return null;
13648
- return loadVectorCode();
13649
- }
13650
-
13651
13490
  // src/workers/vector-copies.ts
13652
13491
  function createHeldVectorCopies() {
13653
13492
  return { searchers: /* @__PURE__ */ new Map(), fields: /* @__PURE__ */ new Map(), builds: /* @__PURE__ */ new Map() };
@@ -13853,8 +13692,8 @@ function createDirectExecutor(options) {
13853
13692
  );
13854
13693
  }
13855
13694
  case "createIndex": {
13856
- const loading3 = loadVectorCodeFor(action.config.schema);
13857
- if (loading3 !== null) await loading3;
13695
+ const loading2 = loadSchemaCodeFor(action.config.schema);
13696
+ if (loading2 !== null) await loading2;
13858
13697
  const language = getLanguage(action.config.language ?? "english");
13859
13698
  const manager = addIndex(
13860
13699
  action.indexName,
@@ -14037,7 +13876,7 @@ var TEXT_REBUILD_SWITCH_BACKLOG_DOCUMENTS = 1e3;
14037
13876
  // src/partitioning/rewrite-spill-of.ts
14038
13877
  async function rewriteSpillOf(storage, manager, target) {
14039
13878
  if (storage === void 0 || (target?.config ?? manager.config).textStorage !== "disk") return null;
14040
- const { openRewriteSpill } = await import('./module-ZL5ZG6YB.mjs');
13879
+ const { openRewriteSpill } = await import('./module-LBZPGOWH.mjs');
14041
13880
  return openRewriteSpill(storage, manager, target);
14042
13881
  }
14043
13882
 
@@ -14127,16 +13966,16 @@ async function rebuildTextIndexes(manager, hooks, target) {
14127
13966
  const partialWordAnalysis = target === void 0 ? manager.partialWordAnalysis : target.partialWordAnalysis;
14128
13967
  const spill = await rewriteSpillOf(hooks.rewriteStorage?.(), manager, target);
14129
13968
  while (hooks.isCurrent()) {
14130
- const log = manager.openWriteLog();
13969
+ const log2 = manager.openWriteLog();
14131
13970
  let swapped = false;
14132
13971
  try {
14133
- swapped = await rebuildOnce({ manager, log, hooks, language, partialWordAnalysis, options, spill });
13972
+ swapped = await rebuildOnce({ manager, log: log2, hooks, language, partialWordAnalysis, options, spill });
14134
13973
  if (swapped) {
14135
13974
  hooks.onRewriteSpill?.(spill);
14136
13975
  return true;
14137
13976
  }
14138
13977
  } finally {
14139
- log.close();
13978
+ log2.close();
14140
13979
  if (!swapped) await spill?.abandon();
14141
13980
  }
14142
13981
  }
@@ -14640,12 +14479,12 @@ function recoveryFailure(metadata, err) {
14640
14479
  });
14641
14480
  }
14642
14481
  async function createIndexFromMetadata(deps, metadata, loadData) {
14643
- const loadingVectorCode = loadData ? loadVectorCodeFor(metadata.schema) : null;
14644
- if (loadingVectorCode !== null) await loadingVectorCode;
14482
+ const loadingSchemaCode = loadData ? loadSchemaCodeFor(metadata.schema) : null;
14483
+ if (loadingSchemaCode !== null) await loadingSchemaCode;
14645
14484
  const existing = deps.indexRegistry.get(metadata.indexName);
14646
14485
  if (existing !== void 0) {
14647
14486
  if ((metadata.analysisGeneration ?? 0) > existing.analysisGeneration) {
14648
- const { adoptSavedAnalysis } = await import('./analysis-change-6BPDPH6K.mjs');
14487
+ const { adoptSavedAnalysis } = await import('./analysis-change-LT5QBQ3H.mjs');
14649
14488
  adoptSavedAnalysis(deps.executor.getManager(metadata.indexName), existing, metadata);
14650
14489
  }
14651
14490
  if (loadData && deps.executor.getManager(metadata.indexName) === void 0) {
@@ -16015,10 +15854,10 @@ async function replicateToWorkers(state, action) {
16015
15854
  }
16016
15855
  if (!copiesWillReceive(state, action.indexName)) return;
16017
15856
  const detached = detachCallerDocuments(state, action);
16018
- const loading3 = state.copyLoadBuffers.get(action.indexName);
16019
- if (loading3 !== void 0) {
15857
+ const loading2 = state.copyLoadBuffers.get(action.indexName);
15858
+ if (loading2 !== void 0) {
16020
15859
  queueForCopies(state, detached);
16021
- if (loading3.length % LOAD_BUFFER_YIELD_INTERVAL === 0) await yieldToEventLoop2();
15860
+ if (loading2.length % LOAD_BUFFER_YIELD_INTERVAL === 0) await yieldToEventLoop2();
16022
15861
  return;
16023
15862
  }
16024
15863
  const queue = state.replicationQueues.get(action.indexName);
@@ -16029,9 +15868,9 @@ async function replicateToWorkers(state, action) {
16029
15868
  }
16030
15869
  function queueForCopies(state, action) {
16031
15870
  if (!("indexName" in action)) return;
16032
- const loading3 = state.copyLoadBuffers.get(action.indexName);
16033
- if (loading3 !== void 0) {
16034
- loading3.push(action);
15871
+ const loading2 = state.copyLoadBuffers.get(action.indexName);
15872
+ if (loading2 !== void 0) {
15873
+ loading2.push(action);
16035
15874
  return;
16036
15875
  }
16037
15876
  if (state.workerPool === null || !state.scaledOutIndexes.has(action.indexName)) return;
@@ -17218,10 +17057,10 @@ function createWorkerOrchestrator(config, executor, indexRegistry, callbacks, ve
17218
17057
  stopRequestThreads: () => stopRequestThreads(state),
17219
17058
  desyncIndex: (indexName) => {
17220
17059
  state.desyncedIndexes.add(indexName);
17221
- const loading3 = state.copyTransitions.get(indexName);
17060
+ const loading2 = state.copyTransitions.get(indexName);
17222
17061
  const wasScaledOut = state.scaledOutIndexes.delete(indexName);
17223
17062
  if (wasScaledOut) withdrawCopies(indexName);
17224
- return wasScaledOut || loading3 !== void 0 && loading3.kind !== "drop";
17063
+ return wasScaledOut || loading2 !== void 0 && loading2.kind !== "drop";
17225
17064
  },
17226
17065
  async releaseIndexCopies(indexName) {
17227
17066
  const hold = state.copyReleaseHolds.get(indexName);
@@ -17281,7 +17120,7 @@ async function createEngineCore(config, hooks, capacityScope = "index") {
17281
17120
  if (config?.lifecycle !== void 0 && durabilityTier === null) {
17282
17121
  throw new NarsilError(ErrorCodes.CONFIG_INVALID, "Index lifecycle settings require durability");
17283
17122
  }
17284
- const durabilityWiring = durabilityTier === null ? null : await import('./durability-wiring-KO565FZC.mjs');
17123
+ const durabilityWiring = durabilityTier === null ? null : await import('./durability-wiring-34OYO32E.mjs');
17285
17124
  const filesystemDurability = durabilityTier?.kind === "wal";
17286
17125
  const executor = createDirectExecutor({
17287
17126
  vectorWorkerCopies: vectorCopyPolicy,
@@ -17467,7 +17306,7 @@ async function createEngineCore(config, hooks, capacityScope = "index") {
17467
17306
  requireManager,
17468
17307
  resumeChange: async (indexName) => {
17469
17308
  if ((indexRegistry.get(indexName)?.pendingAnalysis ?? null) === null) return;
17470
- await (await import('./analysis-change-entry-JLL42PH6.mjs')).resumeChangeOf(engineCore, indexName);
17309
+ await (await import('./analysis-change-entry-SCVWK6OU.mjs')).resumeChangeOf(engineCore, indexName);
17471
17310
  },
17472
17311
  onClose: hooks?.onIndexClose,
17473
17312
  onOpen: (indexName) => {
@@ -17555,7 +17394,7 @@ async function startEngineCore(core, config) {
17555
17394
  checkHeapAfterRecovery(core);
17556
17395
  }
17557
17396
  if (core.invalidation) await core.invalidation.start();
17558
- if (core.durability) await (await import('./analysis-change-entry-JLL42PH6.mjs')).resumeEveryChange(core);
17397
+ if (core.durability) await (await import('./analysis-change-entry-SCVWK6OU.mjs')).resumeEveryChange(core);
17559
17398
  if (config?.lifecycle === void 0) await core.analysisRebuild.reviewStaleIndexes();
17560
17399
  } catch (err) {
17561
17400
  await core.durability?.manager.shutdown().catch(() => void 0);
@@ -17602,6 +17441,874 @@ async function shutdownEngine(core) {
17602
17441
  indexRegistry.clear();
17603
17442
  }
17604
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
+
17605
18312
  // src/engine/startup-checks.ts
17606
18313
  var announcedMissingWorkerEntry = false;
17607
18314
  function withoutWorkers(config, reason) {
@@ -17614,6 +18321,7 @@ function withoutWorkers(config, reason) {
17614
18321
  return { ...config, workers: { ...config?.workers, enabled: false } };
17615
18322
  }
17616
18323
  async function resolveRunnableConfig(config) {
18324
+ requireSearchBackendSettings();
17617
18325
  if (!(config?.workers?.enabled ?? workersEnabledByDefault())) return config;
17618
18326
  const runtime = detectRuntime();
17619
18327
  if (!runtime.supportsWorkerThreads && !runtime.supportsWebWorkers) return config;
@@ -17858,8 +18566,8 @@ async function announceIndexDropped(core, name, config) {
17858
18566
  }
17859
18567
  async function createEngineIndex(core, config, name, requestedConfig, creation = {}) {
17860
18568
  const { indexUuid, adapterBinding = "required", appliesCreationLimits = false } = creation;
17861
- const loadingVectorCode = loadVectorCodeFor(requestedConfig.schema);
17862
- if (loadingVectorCode !== null) await loadingVectorCode;
18569
+ const loadingSchemaCode = loadSchemaCodeFor(requestedConfig.schema);
18570
+ if (loadingSchemaCode !== null) await loadingSchemaCode;
17863
18571
  core.guardShutdown();
17864
18572
  validateIndexName(name);
17865
18573
  if (core.indexRegistry.has(name)) {
@@ -17970,7 +18678,7 @@ async function dropEngineIndex(core, name) {
17970
18678
  const entry = core.requireIndex(name);
17971
18679
  const changeRecorded = () => entry.pendingAnalysis !== null || entry.durableAnalysis !== null;
17972
18680
  const abandonChange = async () => {
17973
- await (await import('./analysis-change-entry-JLL42PH6.mjs')).abandonChangeOf(core, name);
18681
+ await (await import('./analysis-change-entry-SCVWK6OU.mjs')).abandonChangeOf(core, name);
17974
18682
  };
17975
18683
  if (changeRecorded()) await abandonChange();
17976
18684
  await core.indexState.drop(name, async () => {
@@ -19843,7 +20551,7 @@ function portabilityOperations(core, config, engine) {
19843
20551
  const { restoresInFlight } = core;
19844
20552
  const previous = restoresInFlight.get(indexName) ?? Promise.resolve();
19845
20553
  const restored = previous.then(async () => {
19846
- const { runRestore } = await import('./restore-queue-HSYP2AEC.mjs');
20554
+ const { runRestore } = await import('./restore-queue-ZZX54AH7.mjs');
19847
20555
  await runRestore(core, restoreHost, indexName, data, engine());
19848
20556
  });
19849
20557
  const settled2 = restored.then(
@@ -19874,7 +20582,7 @@ function portabilityOperations(core, config, engine) {
19874
20582
  return {
19875
20583
  snapshot(indexName, options) {
19876
20584
  return withOpenIndex2(indexName, async () => {
19877
- const { createSnapshot } = await import('./snapshot-EZYB6SLF.mjs');
20585
+ const { createSnapshot } = await import('./snapshot-REYVIN3X.mjs');
19878
20586
  return createSnapshot(snapshotDepsOf(indexName), options?.queryHistory === true ? core : null);
19879
20587
  });
19880
20588
  },
@@ -19887,8 +20595,8 @@ function portabilityOperations(core, config, engine) {
19887
20595
  exportDocuments(indexName) {
19888
20596
  return withOpenIndex2(indexName, async () => {
19889
20597
  const [{ checkpointForArchive }, { documentExportStream }] = await Promise.all([
19890
- import('./snapshot-EZYB6SLF.mjs'),
19891
- import('./write-JUESXHDL.mjs')
20598
+ import('./snapshot-REYVIN3X.mjs'),
20599
+ import('./write-FQAYCZF5.mjs')
19892
20600
  ]);
19893
20601
  const header = indexConfigurationOf(core.requireIndex(indexName));
19894
20602
  return documentExportStream(header, await checkpointForArchive(snapshotDepsOf(indexName)));
@@ -19896,7 +20604,7 @@ function portabilityOperations(core, config, engine) {
19896
20604
  },
19897
20605
  importDocumentExport(indexName, data) {
19898
20606
  core.guardShutdown();
19899
- const imported = import('./import-YVZA4V4V.mjs').then(
20607
+ const imported = import('./import-H6AQREWI.mjs').then(
19900
20608
  ({ readDocumentExport }) => readDocumentExport(engine(), indexName, data)
19901
20609
  );
19902
20610
  return emitWriteEventAfter(core, indexName, imported);
@@ -19922,9 +20630,9 @@ function flush(stream) {
19922
20630
  }
19923
20631
  function ensureCapacity(stream, extra) {
19924
20632
  if (stream.length + extra <= stream.bytes.length) return;
19925
- const grown = new Uint8Array(Math.max(stream.bytes.length * 2, stream.length + extra));
19926
- grown.set(stream.bytes.subarray(0, stream.length));
19927
- 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;
19928
20636
  }
19929
20637
  function writeByte(stream, value) {
19930
20638
  ensureCapacity(stream, 1);
@@ -20018,14 +20726,14 @@ function writeValue(stream, value) {
20018
20726
  }
20019
20727
  return;
20020
20728
  }
20021
- const record = value;
20022
- const keys = Object.keys(record).sort(compareCodePoints);
20729
+ const record2 = value;
20730
+ const keys = Object.keys(record2).sort(compareCodePoints);
20023
20731
  writeByte(stream, MAP_TAG);
20024
20732
  writeUint32(stream, keys.length);
20025
20733
  for (const key of keys) {
20026
20734
  writeByte(stream, STRING_TAG);
20027
20735
  writeString(stream, key);
20028
- writeValue(stream, record[key] ?? null);
20736
+ writeValue(stream, record2[key] ?? null);
20029
20737
  }
20030
20738
  }
20031
20739
  function boundVectorOf(vector) {
@@ -20047,9 +20755,9 @@ function boundRerankOf(rerank) {
20047
20755
  }
20048
20756
  return present;
20049
20757
  }
20050
- function presentMembersOf(record) {
20758
+ function presentMembersOf(record2) {
20051
20759
  const present = {};
20052
- for (const [key, value] of Object.entries(record)) {
20760
+ for (const [key, value] of Object.entries(record2)) {
20053
20761
  if (value !== void 0) present[key] = value;
20054
20762
  }
20055
20763
  return present;
@@ -21917,7 +22625,7 @@ function createNarsilFromCore(core, config) {
21917
22625
  const entry = requireIndex(indexName);
21918
22626
  await withOpenIndexWrite(indexName, async () => {
21919
22627
  if (entry.pendingAnalysis === null) return core.analysisRebuild.rebuild(indexName);
21920
- return (await import('./analysis-change-6BPDPH6K.mjs')).resumeAnalysisChange(core, indexName);
22628
+ return (await import('./analysis-change-LT5QBQ3H.mjs')).resumeAnalysisChange(core, indexName);
21921
22629
  });
21922
22630
  },
21923
22631
  async changeAnalysis(indexName, change) {
@@ -21925,7 +22633,7 @@ function createNarsilFromCore(core, config) {
21925
22633
  requireIndex(indexName);
21926
22634
  const changed = withOpenIndex2(
21927
22635
  indexName,
21928
- async () => (await import('./analysis-change-6BPDPH6K.mjs')).changeIndexAnalysis(core, indexName, change)
22636
+ async () => (await import('./analysis-change-LT5QBQ3H.mjs')).changeIndexAnalysis(core, indexName, change)
21929
22637
  );
21930
22638
  await emitWriteEventAfter(core, indexName, changed);
21931
22639
  },
@@ -21960,7 +22668,7 @@ function createNarsilFromCore(core, config) {
21960
22668
  const rebalanced = withOpenIndex2(
21961
22669
  indexName,
21962
22670
  () => withRenewedSyncEpoch(core, indexName, async () => {
21963
- const { executeRebalance } = await import('./analysis-change-6BPDPH6K.mjs');
22671
+ const { executeRebalance } = await import('./analysis-change-LT5QBQ3H.mjs');
21964
22672
  const running = executeRebalance(requireManager(indexName), indexName, targetPartitionCount, rebalanceCtx);
21965
22673
  releaseWrites();
21966
22674
  await running;
@@ -22045,8 +22753,8 @@ function createNarsilFromCore(core, config) {
22045
22753
  guardShutdown();
22046
22754
  requireIndex(indexName);
22047
22755
  const manager = executor.getManager(indexName);
22048
- const vectorCode = loadedVectorCode();
22049
- return manager === void 0 || vectorCode === null ? [] : vectorCode.getVectorMaintenanceStatus(manager);
22756
+ const vectorCode2 = loadedVectorCode();
22757
+ return manager === void 0 || vectorCode2 === null ? [] : vectorCode2.getVectorMaintenanceStatus(manager);
22050
22758
  },
22051
22759
  on(event, handler) {
22052
22760
  const key = event;
@@ -22084,7 +22792,7 @@ async function createNarsil(config) {
22084
22792
  await startEngineCore(core, runnableConfig);
22085
22793
  const engine = createNarsilFromCore(core, runnableConfig);
22086
22794
  if (runnableConfig?.querySuggestions !== void 0 || core.durability !== null) {
22087
- await (await import('./engine-hooks-MVRRHH6B.mjs')).startQuerySuggestions(core, engine, runnableConfig);
22795
+ await (await import('./engine-hooks-M7JV46NH.mjs')).startQuerySuggestions(core, engine, runnableConfig);
22088
22796
  }
22089
22797
  return engine;
22090
22798
  }
@@ -22092,4 +22800,4 @@ async function createNarsil(config) {
22092
22800
  // src/index.ts
22093
22801
  var VERSION = "0.1.0";
22094
22802
 
22095
- 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, loadVectorCodeFor, 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 };
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 };