@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.
- package/NOTICE +45 -0
- package/dist/{analysis-change-3TFIHT5E.mjs → analysis-change-5BQOQ4BF.mjs} +25 -18
- package/dist/{react-native/chunks/analysis-change-entry-JLL42PH6.mjs → analysis-change-entry-TXX6JSMX.mjs} +1 -1
- package/dist/browser/{analysis-change-TC36BU47.mjs → analysis-change-435CUEPZ.mjs} +8 -7
- package/dist/{analysis-change-entry-KA6JAO4X.mjs → browser/analysis-change-entry-HZXKPPGV.mjs} +1 -1
- package/dist/browser/{chunk-A5KUEGDY.mjs → chunk-2CFI5VVV.mjs} +2 -2
- package/dist/browser/{chunk-BXM5XOCA.mjs → chunk-2TI4SSUP.mjs} +2 -2
- package/dist/browser/{chunk-CJSYBQ4J.mjs → chunk-3SSRJMFN.mjs} +1 -1
- package/dist/browser/{chunk-SMEQ36NT.mjs → chunk-3V7DNNZL.mjs} +458 -622
- package/dist/browser/{chunk-RRO3EV4C.mjs → chunk-4NGKC4H4.mjs} +7 -7
- package/dist/browser/{chunk-ABCXENU5.mjs → chunk-6LWDPLTB.mjs} +1 -1
- package/dist/browser/{chunk-FNIFPFB7.mjs → chunk-7U3WVJUP.mjs} +2 -2
- package/dist/browser/{chunk-KKAMCABR.mjs → chunk-BHFQATSC.mjs} +1 -1
- package/dist/browser/{chunk-IKDKX5VQ.mjs → chunk-CRE3G7F3.mjs} +3 -3
- package/dist/browser/{chunk-56W3HQVJ.mjs → chunk-EA63E3D2.mjs} +4 -4
- package/dist/browser/{chunk-K5AXJBLL.mjs → chunk-IZXVW2ZJ.mjs} +3 -3
- package/dist/browser/{chunk-RND5CLX3.mjs → chunk-K4Q6KX3R.mjs} +16 -16
- package/dist/browser/{chunk-XY4VVBBO.mjs → chunk-KZWSX6BH.mjs} +2 -2
- package/dist/browser/{chunk-3UIEB4QF.mjs → chunk-MGI4BCXC.mjs} +2 -2
- package/dist/browser/chunk-MOG4OVDK.mjs +51 -0
- package/dist/browser/{chunk-RQBUNZQW.mjs → chunk-NQAME3RK.mjs} +2 -2
- package/dist/browser/{chunk-LFIWRCEA.mjs → chunk-NXQG7DRA.mjs} +29 -6
- package/dist/browser/{chunk-JVBP5EYO.mjs → chunk-SSTPBZZX.mjs} +7 -7
- package/dist/browser/{chunk-JIJXMI42.mjs → chunk-STOWQFT3.mjs} +1 -1
- package/dist/browser/{chunk-26A5JFT2.mjs → chunk-TK63WFXK.mjs} +2 -1
- package/dist/browser/{chunk-4EWUGZYZ.mjs → chunk-U4YDIBUT.mjs} +2 -2
- package/dist/browser/{chunk-K4GCSZLI.mjs → chunk-VLJQW4J6.mjs} +2985 -2985
- package/dist/browser/{chunk-SUDNZKPL.mjs → chunk-WI4MR75E.mjs} +1 -1
- package/dist/browser/{chunk-5TCXK5SB.mjs → chunk-WN464PTL.mjs} +1 -1
- package/dist/browser/{cold-module-NEUGHUPA.mjs → cold-module-2EHCIV4K.mjs} +15 -14
- package/dist/browser/{durability-wiring-CVGPRO6D.mjs → durability-wiring-A7BVG2DW.mjs} +20 -19
- package/dist/browser/{engine-hooks-YXMPHZKZ.mjs → engine-hooks-E4UD67JD.mjs} +7 -6
- package/dist/browser/geo-index-HHWGMNIS.mjs +1386 -0
- package/dist/browser/{import-OM6QAW45.mjs → import-DXYB6756.mjs} +8 -7
- package/dist/browser/{module-E33X4AOK.mjs → module-NIYMEA5R.mjs} +11 -10
- package/dist/browser/{module-3HNFCBJ5.mjs → module-TCT66FWA.mjs} +6 -6
- package/dist/browser/{phrase-module-ZXXU7S3B.mjs → phrase-module-HAT3TLZN.mjs} +1 -1
- package/dist/browser/{restore-hooks-IF2ZROUP.mjs → restore-hooks-YPN4ZFCY.mjs} +10 -9
- package/dist/browser/{restore-queue-ZBS7CJA6.mjs → restore-queue-G3RQGL3Y.mjs} +3 -3
- package/dist/browser/{retention-ASWUHAYI.mjs → retention-ZWVMNC3Q.mjs} +9 -8
- package/dist/browser/{snapshot-PN7ZW6Q4.mjs → snapshot-VEQNIE6C.mjs} +24 -23
- package/dist/browser/{start-ZIRB7MQ2.mjs → start-BM442C6R.mjs} +11 -10
- package/dist/browser/{write-HMDYCTV2.mjs → write-2EVMZWDE.mjs} +12 -11
- package/dist/{chunk-2MANFZJ3.mjs → chunk-25KDNIZZ.mjs} +1 -1
- package/dist/{chunk-3HHQLEEQ.mjs → chunk-2UV4QBHW.mjs} +7 -7
- package/dist/{chunk-BY6ZDGYS.mjs → chunk-3HYC4JRF.mjs} +1 -1
- package/dist/{chunk-HW5TNXBO.mjs → chunk-46KY2PJD.mjs} +7 -6
- package/dist/{chunk-SY3EWKQY.mjs → chunk-4KKXNJM6.mjs} +1 -1
- package/dist/{chunk-VQEUR6T6.mjs → chunk-5VV4R6P7.mjs} +3040 -3040
- package/dist/chunk-6HTGOXIK.mjs +875 -0
- package/dist/{chunk-RSVULW4Q.mjs → chunk-6I6AYAXS.mjs} +4 -4
- package/dist/chunk-7GFE3PEY.mjs +40 -0
- package/dist/{chunk-3R4UZWQG.mjs → chunk-7LXHHCXZ.mjs} +15 -15
- package/dist/{chunk-JUKYYXSP.mjs → chunk-7V5IUP2T.mjs} +1 -31
- package/dist/{chunk-4BYWRYPM.mjs → chunk-A4L7YTKX.mjs} +52 -89
- package/dist/{chunk-WQRN64Q6.mjs → chunk-BU4SAIC4.mjs} +1 -1
- package/dist/{chunk-5FVU47TB.mjs → chunk-BWZ3P4MU.mjs} +3 -3
- package/dist/{chunk-LC3FDWTX.mjs → chunk-CITFCZKF.mjs} +3 -2
- package/dist/{chunk-PCRA7HTI.mjs → chunk-CSLGFPFQ.mjs} +1 -1
- package/dist/{chunk-VHBNF4MA.mjs → chunk-DP5C7YFQ.mjs} +2 -2
- package/dist/{chunk-3HB3PEC6.mjs → chunk-DWEPMFJE.mjs} +5 -5
- package/dist/{chunk-KMUNHGBQ.mjs → chunk-EFBDHH5P.mjs} +29 -28
- package/dist/{chunk-DCNKVEDB.mjs → chunk-FAKFUDZZ.mjs} +5 -6
- package/dist/chunk-FB6463IN.mjs +1499 -0
- package/dist/{chunk-KFLK5NA2.mjs → chunk-FCJ553HS.mjs} +1 -1
- package/dist/{chunk-SG3JBNHY.mjs → chunk-FJKKCV4D.mjs} +1 -1
- package/dist/{chunk-H6VIGE62.mjs → chunk-FNGAM5B7.mjs} +10 -9
- package/dist/{chunk-VGF7CFRP.mjs → chunk-FRBFVQFN.mjs} +5 -4
- package/dist/{chunk-QH3YIQP4.mjs → chunk-FYOVBEMM.mjs} +2 -2
- package/dist/chunk-G6HRSGOU.mjs +74 -0
- package/dist/{chunk-DUOLGBTE.mjs → chunk-HFPMMRQT.mjs} +3 -3
- package/dist/{chunk-ZHCUZZE5.mjs → chunk-HHBUCIUY.mjs} +1 -1
- package/dist/{chunk-ZTW5WTGG.mjs → chunk-I2KPOLOZ.mjs} +3 -3
- package/dist/{chunk-L7ZD4L3K.mjs → chunk-I53G4JAU.mjs} +7 -6
- package/dist/{chunk-YEDIDCR7.mjs → chunk-I5B7RXU7.mjs} +91 -22
- package/dist/{react-native/chunks/chunk-KWRW5U65.mjs → chunk-J4IJTTEX.mjs} +1 -1
- package/dist/{chunk-S2EQU2GE.mjs → chunk-JDJBQLRO.mjs} +9 -9
- package/dist/{chunk-KPIV4RUC.mjs → chunk-JWRUUCWD.mjs} +2 -2
- package/dist/{chunk-KBKEXQZA.mjs → chunk-K5QFDYST.mjs} +1 -1
- package/dist/{chunk-DIBHI6W5.mjs → chunk-KF4EXSM4.mjs} +2 -2
- package/dist/{chunk-Q7G3BV3Y.mjs → chunk-KKQC526K.mjs} +19 -11
- package/dist/{chunk-4KRC2APY.mjs → chunk-L6V6BST3.mjs} +6 -19
- package/dist/{chunk-U4BS74YN.mjs → chunk-MQOJIO5B.mjs} +1 -1
- package/dist/chunk-ORN5BLL7.mjs +11 -0
- package/dist/{chunk-ZAUJFLEN.mjs → chunk-P5ZI2P2W.mjs} +122 -1697
- package/dist/{chunk-AILVAOLX.mjs → chunk-PWC4VB3Q.mjs} +2 -2
- package/dist/{chunk-J4IWBIVY.mjs → chunk-QOW2JPUI.mjs} +5 -5
- package/dist/{chunk-PHQNACDT.mjs → chunk-RDXO6JST.mjs} +2 -2
- package/dist/chunk-RLOES5SX.mjs +31 -0
- package/dist/{chunk-6L3XJXGU.mjs → chunk-SA5LOGO3.mjs} +1 -1
- package/dist/chunk-SQJWAIF4.mjs +12 -0
- package/dist/{react-native/chunks/chunk-PPEPTUVV.mjs → chunk-TBC3XUL2.mjs} +29 -6
- package/dist/chunk-TDIK6NTV.mjs +10 -0
- package/dist/{chunk-MT2NRTA6.mjs → chunk-TGS5UXBE.mjs} +3 -3
- package/dist/{chunk-KBDBPVLN.mjs → chunk-TZ3355VS.mjs} +1 -1
- package/dist/{chunk-Q622CTMC.mjs → chunk-TZTRKM33.mjs} +1 -1
- package/dist/{react-native/chunks/chunk-JV6VQY2S.mjs → chunk-U55XJEIG.mjs} +2 -1
- package/dist/{chunk-Z2BE2MAM.mjs → chunk-VTTRFF2C.mjs} +28 -15
- package/dist/{chunk-KXCVQWOR.mjs → chunk-WX4LAO6M.mjs} +3 -3
- package/dist/{chunk-BDRIVYOK.mjs → chunk-XAXKV65G.mjs} +1 -1
- package/dist/{chunk-UZRZKNNZ.mjs → chunk-XXHN7J46.mjs} +1 -1
- package/dist/{chunk-H4KHPLHJ.mjs → chunk-YTWZVGCB.mjs} +1 -1
- package/dist/{chunk-QUJHMPTP.mjs → chunk-Z2KAFCRT.mjs} +2 -2
- package/dist/{chunk-SMVH6JBE.mjs → chunk-ZKP7G7TV.mjs} +1 -1
- package/dist/{cold-module-7XXCEGTZ.mjs → cold-module-6MO2XJF2.mjs} +29 -23
- package/dist/direct-executor-FTMYY3TI.mjs +34 -0
- package/dist/distribution/coordinator/etcd.mjs +2 -2
- package/dist/distribution/coordinator/in-memory.mjs +2 -2
- package/dist/distribution.mjs +57 -51
- package/dist/{durability-wiring-NCKUC5EO.mjs → durability-wiring-VIF5MOSY.mjs} +41 -34
- package/dist/{engine-hooks-DHCMOADY.mjs → engine-hooks-EGUGNZYE.mjs} +24 -17
- package/dist/geo-index-MRH5JMIR.mjs +1387 -0
- package/dist/{import-NBFXFCSG.mjs → import-XKDPJQDP.mjs} +24 -17
- package/dist/index.browser.mjs +6 -5
- package/dist/index.d.ts +127 -2
- package/dist/index.mjs +23 -16
- package/dist/index.react-native.mjs +12 -10
- package/dist/invalidation/filesystem.mjs +2 -2
- package/dist/{long-query-thread-J4DVRM4A.mjs → long-query-thread-YA4IAYSY.mjs} +25 -20
- package/dist/{module-DWKPBSMN.mjs → module-FQ4JWNQJ.mjs} +26 -19
- package/dist/{module-UN76TF7I.mjs → module-N55W4Q5C.mjs} +9 -9
- package/dist/{paged-partition-archive-DPNWVSK2.mjs → paged-partition-archive-PXW5XAYU.mjs} +32 -26
- package/dist/partial-words.mjs +8 -6
- package/dist/pattern.mjs +4 -3
- package/dist/persistence/durability/checkpoint-worker.mjs +30 -21
- package/dist/{phrase-module-ZI4WSQVH.mjs → phrase-module-XW5MKWP5.mjs} +3 -2
- package/dist/query-suggestions/merge-worker.mjs +25 -18
- package/dist/query-suggestions.browser.mjs +12 -11
- package/dist/query-suggestions.mjs +34 -27
- package/dist/react-native/chunks/{analysis-change-6BPDPH6K.mjs → analysis-change-LT5QBQ3H.mjs} +13 -11
- package/dist/{browser/analysis-change-entry-4MH3CZXH.mjs → react-native/chunks/analysis-change-entry-SCVWK6OU.mjs} +1 -1
- package/dist/react-native/chunks/{chunk-7PXRWYUU.mjs → chunk-2PRHILX3.mjs} +53 -19
- package/dist/react-native/chunks/{chunk-C3PTWYKT.mjs → chunk-3JWDECAZ.mjs} +4 -4
- package/dist/{chunk-R6A773WK.mjs → react-native/chunks/chunk-3WI35N75.mjs} +1 -1
- package/dist/react-native/chunks/{chunk-CUH5F57W.mjs → chunk-4JYO3JD2.mjs} +2 -2
- package/dist/react-native/chunks/{chunk-3JIBF3XT.mjs → chunk-DNXOMPAQ.mjs} +1 -1
- package/dist/react-native/chunks/chunk-DXRSEWA2.mjs +12 -0
- package/dist/{chunk-YTJCGKM4.mjs → react-native/chunks/chunk-EJ33LCHV.mjs} +29 -6
- package/dist/react-native/chunks/{chunk-EIOYM5TO.mjs → chunk-ENLMYKSX.mjs} +3024 -3054
- package/dist/react-native/chunks/chunk-FHPW7P2O.mjs +40 -0
- package/dist/{chunk-4UMZ7KQL.mjs → react-native/chunks/chunk-FTZHMRD2.mjs} +2 -1
- package/dist/react-native/chunks/{chunk-OL3WDV53.mjs → chunk-G43IPIDG.mjs} +3 -3
- package/dist/react-native/chunks/{chunk-4Y53T4YE.mjs → chunk-GXX3DQXP.mjs} +5 -19
- package/dist/react-native/chunks/{chunk-GIZTJXYW.mjs → chunk-KV46CT4D.mjs} +2 -2
- package/dist/react-native/chunks/{chunk-HUOYZJ3Q.mjs → chunk-MIP4SOR6.mjs} +1419 -711
- package/dist/react-native/chunks/{chunk-ALOIBXWN.mjs → chunk-MUWD2H2S.mjs} +2 -2
- package/dist/react-native/chunks/{chunk-4LCEN2IU.mjs → chunk-NB3LP33V.mjs} +2 -2
- package/dist/react-native/chunks/{chunk-VXGE4ZXL.mjs → chunk-PDRWWPKV.mjs} +17 -17
- package/dist/react-native/chunks/{chunk-N2WUOWLL.mjs → chunk-POPDAGH6.mjs} +7 -7
- package/dist/react-native/chunks/{chunk-GJFXPHXI.mjs → chunk-QUKQNI3H.mjs} +3 -3
- package/dist/react-native/chunks/{chunk-KTTAU63H.mjs → chunk-SK2PWYDH.mjs} +2 -2
- package/dist/react-native/chunks/{chunk-7GRCBBME.mjs → chunk-TP6KCKER.mjs} +2 -2
- package/dist/react-native/chunks/{chunk-KJIG57UD.mjs → chunk-UQ4OAXKU.mjs} +7 -7
- package/dist/react-native/chunks/{chunk-PEHS2UO3.mjs → chunk-VWUDIOT6.mjs} +3 -3
- package/dist/react-native/chunks/{chunk-JLIIWJUV.mjs → chunk-YZW4CHM6.mjs} +50 -11
- package/dist/react-native/chunks/{chunk-QJXTNPLQ.mjs → chunk-ZLWVW734.mjs} +1 -1
- package/dist/react-native/chunks/{chunk-TYIRMPD3.mjs → chunk-ZXZFN7FI.mjs} +1 -1
- package/dist/react-native/chunks/{cold-module-5PHF6DZR.mjs → cold-module-KVZYUGRY.mjs} +19 -17
- package/dist/react-native/chunks/{durability-wiring-KO565FZC.mjs → durability-wiring-34OYO32E.mjs} +27 -25
- package/dist/react-native/chunks/{engine-hooks-MVRRHH6B.mjs → engine-hooks-M7JV46NH.mjs} +13 -11
- package/dist/react-native/chunks/geo-index-PX3BIHAH.mjs +1387 -0
- package/dist/react-native/chunks/{import-YVZA4V4V.mjs → import-H6AQREWI.mjs} +14 -12
- package/dist/react-native/chunks/{module-ZL5ZG6YB.mjs → module-LBZPGOWH.mjs} +15 -13
- package/dist/react-native/chunks/{module-H5MVPSP2.mjs → module-TTEVPRCW.mjs} +8 -8
- package/dist/react-native/chunks/{phrase-module-RTVKEWJT.mjs → phrase-module-QK22HSQ2.mjs} +1 -1
- package/dist/react-native/chunks/{restore-hooks-SILFPU6B.mjs → restore-hooks-IBGIY3DR.mjs} +17 -15
- package/dist/react-native/chunks/{restore-queue-HSYP2AEC.mjs → restore-queue-ZZX54AH7.mjs} +3 -3
- package/dist/react-native/chunks/{retention-7I7UAWYK.mjs → retention-EW4TTDFB.mjs} +18 -16
- package/dist/react-native/chunks/{snapshot-EZYB6SLF.mjs → snapshot-REYVIN3X.mjs} +31 -29
- package/dist/react-native/chunks/{start-SHVZ72I5.mjs → start-BQK6KN3R.mjs} +18 -16
- package/dist/react-native/chunks/{write-JUESXHDL.mjs → write-FQAYCZF5.mjs} +16 -14
- package/dist/react-native/partial-words.mjs +7 -6
- package/dist/react-native/pattern.mjs +1 -1
- package/dist/react-native/query-suggestions.mjs +19 -17
- package/dist/react-native/sync.mjs +7 -7
- package/dist/react-native/synonyms.mjs +92 -24
- package/dist/{restore-hooks-HZ3ILAMO.mjs → restore-hooks-CDERDEF4.mjs} +28 -21
- package/dist/{restore-queue-JVGENGGE.mjs → restore-queue-7NNSTROA.mjs} +3 -3
- package/dist/{retention-HROPV2QU.mjs → retention-QSVBBNRM.mjs} +28 -21
- package/dist/server.mjs +45 -39
- package/dist/{snapshot-4HS2G2UM.mjs → snapshot-RH4NSKIZ.mjs} +44 -38
- package/dist/{start-UTWHGH42.mjs → start-MCKCOGIW.mjs} +31 -24
- package/dist/sync/filesystem.mjs +3 -3
- package/dist/sync.browser.mjs +5 -5
- package/dist/sync.mjs +5 -5
- package/dist/synonyms.mjs +7 -6
- package/dist/{thread-6MOXY2KD.mjs → thread-O4SBJJJS.mjs} +24 -19
- package/dist/vector/search-worker.mjs +6 -6
- package/dist/workers/entry.mjs +17 -6
- package/dist/{write-GTTWWRRG.mjs → write-3FK7NG3Y.mjs} +26 -19
- package/package.json +15 -8
- package/dist/chunk-DJHHF2L5.mjs +0 -17
- package/dist/chunk-HNVVEQP7.mjs +0 -44
- package/dist/direct-executor-G5TK7NLA.mjs +0 -29
- package/dist/browser/{chunk-4WCVMOU3.mjs → chunk-XAWNZ4G2.mjs} +10 -10
|
@@ -1,18 +1,20 @@
|
|
|
1
|
-
import { PATTERN_EXPRESSION_OPERATORS, PATTERN_TEST_OPERATORS, PATTERN_ELEMENT_OPERATORS, requireTextRangeField, isFiniteNumber, invalid, requireFieldKind, kindOfValue, requireListLength, isObjectRecord, GEO_UNIT_METRES, patternSearchModule, DEFAULT_PATTERN_WORK_CAP, MAX_FILTER_DEPTH, MAX_FILTER_TESTS, TYPO_CLAIM_SLOTS_PER_WORD, FILTER_OPERAND_COPY_DEPTH, PATTERN_WORK_FLUSH_UNITS, MATCHER_STATE_BUDGET_BYTES } from './chunk-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { PATTERN_EXPRESSION_OPERATORS, PATTERN_TEST_OPERATORS, PATTERN_ELEMENT_OPERATORS, requireTextRangeField, isFiniteNumber, invalid, requireFieldKind, kindOfValue, requireListLength, isObjectRecord, GEO_UNIT_METRES, patternSearchModule, DEFAULT_PATTERN_WORK_CAP, MAX_FILTER_DEPTH, MAX_FILTER_TESTS, TYPO_CLAIM_SLOTS_PER_WORD, FILTER_OPERAND_COPY_DEPTH, PATTERN_WORK_FLUSH_UNITS, MATCHER_STATE_BUDGET_BYTES } from './chunk-CITFCZKF.mjs';
|
|
2
|
+
import { isLatitude, isLongitude, expandTermPrefix, suggestDisplayTerms, getNestedValue, validateDocument, validateDocumentStrict, textFieldsChanged, getFlatSchema, tokenizeOptions, partialWordSearchModule, getOrCreateFieldNameIndex, partitionDocumentFrequency } from './chunk-L6V6BST3.mjs';
|
|
3
|
+
import { MAX_LATITUDE_DEGREES, MAX_LONGITUDE_DEGREES, MIN_POLYGON_POINTS } from './chunk-SQJWAIF4.mjs';
|
|
4
4
|
import { MAX_SORT_FIELDS, MAX_SORT_FIELD_NAME_LENGTH, MAX_CURSOR_LENGTH, MAX_CURSOR_ANCHOR_CODE_POINTS, RESULT_WINDOW, DEFAULT_FUZZY_PREFIX_LENGTH, DEFAULT_PAGE_SIZE, PREFIX_MAX_EXPANSIONS } from './chunk-FQBFZAWG.mjs';
|
|
5
|
-
import { partialFieldsOf, schemaFieldsOf, flattenSchema } from './chunk-
|
|
5
|
+
import { partialFieldsOf, schemaFieldsOf, flattenSchema } from './chunk-BU4SAIC4.mjs';
|
|
6
6
|
import { fuzzyPrefixOf, boundedLevenshtein, fuzzyTermMatches } from './chunk-GES7U2PM.mjs';
|
|
7
7
|
import { parsedTypeOf, isStringValuedBase, withSortableOption, isWordIndexedBase, isWordIndexedFieldType, isListBase } from './chunk-I54T6CQP.mjs';
|
|
8
|
-
import {
|
|
9
|
-
import { TARGET_BLOCK_ENTRIES, SCORE_BUFFER_INITIAL_TOUCHED_CAPACITY, PRUNING_REJECTION_SLACK, SORT_COLUMN_MINIMUM_REBUILD_THRESHOLD, SORT_COLUMN_REBUILD_FRACTION_SHIFT } from './chunk-4UMZ7KQL.mjs';
|
|
8
|
+
import { PENDING_REMOVAL_MERGE_FLOOR, PENDING_REMOVAL_MERGE_DIVISOR, searchFulltext, analyseQueryPhrases, requireLoadedPhraseCode, MAX_TERM_FREQUENCY, createLoadedGeoIndex, partialFieldMarks, termGroupOf, typoMatchesFor, POSTING_LIST_COMPACTION_THRESHOLD, postingColumns, ARRAY_POSITION_GAP } from './chunk-FB6463IN.mjs';
|
|
10
9
|
import { PROCESS_LIMIT_REFRESH_INTERVAL_MS } from './chunk-ZXNQEW43.mjs';
|
|
10
|
+
import { bitsetHas, createBitSet, bitsetSet, bitsetIsEmpty, bitsetOrInto, bitsetAndNotInto, bitsetAndInto, bitsetFromSet } from './chunk-7V5IUP2T.mjs';
|
|
11
11
|
import { isGeopointOrVectorType, PROTOTYPE_POLLUTION_KEYS } from './chunk-L5ORED7V.mjs';
|
|
12
|
+
import { tokenize, visitTokens } from './chunk-A4L7YTKX.mjs';
|
|
13
|
+
import { SORT_COLUMN_MINIMUM_REBUILD_THRESHOLD, SORT_COLUMN_REBUILD_FRACTION_SHIFT } from './chunk-U55XJEIG.mjs';
|
|
12
14
|
import { turnIsSpent, yieldTurn, createDocIdMap } from './chunk-LQG5G2LY.mjs';
|
|
13
15
|
import { NarsilError, ErrorCodes } from './chunk-MP7ABPTD.mjs';
|
|
14
|
-
import { singleFoldTable, appendFoldedCodePoint, sortModeOf, defaultSortMode, SORT_VALUE_MAX_CODE_POINTS, toReducedSortValue, readSortField, compareComparableKeys, toComparableSortValue, isSortMode, SORT_MODES, compareSortValues, compareComparableValues, truncateSortString } from './chunk-
|
|
15
|
-
import { compareCodePoints, exceedsCodePoints, codePointCount, holdsUnpairedSurrogate } from './chunk-
|
|
16
|
+
import { singleFoldTable, appendFoldedCodePoint, sortModeOf, defaultSortMode, SORT_VALUE_MAX_CODE_POINTS, toReducedSortValue, readSortField, compareComparableKeys, toComparableSortValue, isSortMode, SORT_MODES, compareSortValues, compareComparableValues, truncateSortString } from './chunk-J4IJTTEX.mjs';
|
|
17
|
+
import { compareCodePoints, exceedsCodePoints, codePointCount, holdsUnpairedSurrogate } from './chunk-TBC3XUL2.mjs';
|
|
16
18
|
import { totalmem, freemem } from 'os';
|
|
17
19
|
|
|
18
20
|
// src/core/partition/partial-words/platform.ts
|
|
@@ -169,17 +171,6 @@ function requirePatternSearch(fieldPath) {
|
|
|
169
171
|
);
|
|
170
172
|
}
|
|
171
173
|
|
|
172
|
-
// src/core/constants.ts
|
|
173
|
-
var POSTING_LIST_COMPACTION_THRESHOLD = 0.3;
|
|
174
|
-
var MAX_TERM_FREQUENCY = 65535;
|
|
175
|
-
var ARRAY_POSITION_GAP = 100;
|
|
176
|
-
var DEFAULT_BM25_K1 = 1.2;
|
|
177
|
-
var DEFAULT_BM25_B = 0.75;
|
|
178
|
-
var MAX_BM25_K1 = 1e3;
|
|
179
|
-
var MAX_BM25_B = 1;
|
|
180
|
-
var PENDING_REMOVAL_MERGE_FLOOR = 64;
|
|
181
|
-
var PENDING_REMOVAL_MERGE_DIVISOR = 256;
|
|
182
|
-
|
|
183
174
|
// src/core/partition/frozen/memory.ts
|
|
184
175
|
function frozenSegmentBytes(segment) {
|
|
185
176
|
if (segment.paged !== null) return segment.paged.heldBytes(segment);
|
|
@@ -205,6 +196,62 @@ function frozenSegmentBytes(segment) {
|
|
|
205
196
|
return bytes + segment.partialWords.bytes() + segment.removalBytes() + (segment.vectorOrdinalMaps?.bytes ?? 0);
|
|
206
197
|
}
|
|
207
198
|
|
|
199
|
+
// src/core/document-copy.ts
|
|
200
|
+
var NOT_PLAIN = /* @__PURE__ */ Symbol("not plain");
|
|
201
|
+
function firstVisit(value, state) {
|
|
202
|
+
if (state.first === void 0) {
|
|
203
|
+
state.first = value;
|
|
204
|
+
return true;
|
|
205
|
+
}
|
|
206
|
+
if (state.seen === void 0) state.seen = /* @__PURE__ */ new Set([state.first]);
|
|
207
|
+
if (state.seen.has(value)) return false;
|
|
208
|
+
state.seen.add(value);
|
|
209
|
+
return true;
|
|
210
|
+
}
|
|
211
|
+
function holdsIndexesOnly(source) {
|
|
212
|
+
const length = source.length;
|
|
213
|
+
if (length === 0) return Object.keys(source).length === 0;
|
|
214
|
+
const keys = Object.keys(source);
|
|
215
|
+
return keys.length === length && keys[length - 1] === String(length - 1);
|
|
216
|
+
}
|
|
217
|
+
function copyArray(source, state) {
|
|
218
|
+
if (!holdsIndexesOnly(source)) return NOT_PLAIN;
|
|
219
|
+
const copy = [];
|
|
220
|
+
for (let index = 0; index < source.length; index++) {
|
|
221
|
+
const value = copyValue(source[index], state);
|
|
222
|
+
if (value === NOT_PLAIN) return NOT_PLAIN;
|
|
223
|
+
copy.push(value);
|
|
224
|
+
}
|
|
225
|
+
return copy;
|
|
226
|
+
}
|
|
227
|
+
function copyRecord(source, state) {
|
|
228
|
+
const copy = {};
|
|
229
|
+
for (const key of Object.keys(source)) {
|
|
230
|
+
if (!Object.hasOwn(source, key)) continue;
|
|
231
|
+
const value = copyValue(source[key], state);
|
|
232
|
+
if (value === NOT_PLAIN) return NOT_PLAIN;
|
|
233
|
+
if (key === "__proto__") {
|
|
234
|
+
Object.defineProperty(copy, key, { value, enumerable: true, writable: true, configurable: true });
|
|
235
|
+
} else {
|
|
236
|
+
copy[key] = value;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
return copy;
|
|
240
|
+
}
|
|
241
|
+
function copyValue(value, state) {
|
|
242
|
+
if (typeof value === "function" || typeof value === "symbol") return NOT_PLAIN;
|
|
243
|
+
if (typeof value !== "object" || value === null) return value;
|
|
244
|
+
if (!firstVisit(value, state)) return NOT_PLAIN;
|
|
245
|
+
const prototype = Object.getPrototypeOf(value);
|
|
246
|
+
if (Array.isArray(value)) return prototype === Array.prototype ? copyArray(value, state) : NOT_PLAIN;
|
|
247
|
+
if (prototype !== Object.prototype && prototype !== null) return NOT_PLAIN;
|
|
248
|
+
return copyRecord(value, state);
|
|
249
|
+
}
|
|
250
|
+
function copyStoredValue(value) {
|
|
251
|
+
const copy = copyValue(value, { first: void 0, seen: void 0 });
|
|
252
|
+
return copy === NOT_PLAIN ? structuredClone(value) : copy;
|
|
253
|
+
}
|
|
254
|
+
|
|
208
255
|
// src/core/projection.ts
|
|
209
256
|
function requireFieldPathList(paths, option) {
|
|
210
257
|
if (paths === void 0) return;
|
|
@@ -291,8 +338,8 @@ function omitPath(source, path) {
|
|
|
291
338
|
}
|
|
292
339
|
function cloneExcept(value, path, exclude) {
|
|
293
340
|
const reachesDeeper = exclude.some((excluded) => excluded.length > path.length && covers(path, excluded));
|
|
294
|
-
if (!reachesDeeper) return
|
|
295
|
-
if (typeof value !== "object" || value === null || Array.isArray(value)) return
|
|
341
|
+
if (!reachesDeeper) return copyStoredValue(value);
|
|
342
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return copyStoredValue(value);
|
|
296
343
|
const source = value;
|
|
297
344
|
const kept = {};
|
|
298
345
|
for (const key of Object.keys(source)) {
|
|
@@ -331,7 +378,7 @@ function projectionKeepsField(projection, fieldPath) {
|
|
|
331
378
|
return !projection.exclude.some((excluded) => covers(excluded, path));
|
|
332
379
|
}
|
|
333
380
|
function cloneProjected(document, projection) {
|
|
334
|
-
if (projection === void 0 || projection.kind === "full") return
|
|
381
|
+
if (projection === void 0 || projection.kind === "full") return copyStoredValue(document);
|
|
335
382
|
if (projection.kind === "none") return {};
|
|
336
383
|
if (projection.include === null) return cloneExcept(document, [], projection.exclude);
|
|
337
384
|
return projectIncludedPaths(projection.include, projection.exclude, (path) => readProjectedPath(document, path));
|
|
@@ -1173,7 +1220,7 @@ var LivePostings = class {
|
|
|
1173
1220
|
terms = new TermColumns(TERM_TABLE_START_CAPACITY);
|
|
1174
1221
|
pool = new PostingPool(POSTING_POOL_START_ENTRIES);
|
|
1175
1222
|
positions = new PositionPool(POSITION_POOL_START_VALUES);
|
|
1176
|
-
retired = new
|
|
1223
|
+
retired = new Uint32Array(RETIRED_DOCUMENTS_START_CAPACITY >>> 5);
|
|
1177
1224
|
batchMode = false;
|
|
1178
1225
|
dirty = /* @__PURE__ */ new Set();
|
|
1179
1226
|
cachedViews = /* @__PURE__ */ new Map();
|
|
@@ -1260,7 +1307,7 @@ var LivePostings = class {
|
|
|
1260
1307
|
this.repackIfSparse();
|
|
1261
1308
|
}
|
|
1262
1309
|
isRetired(internalId) {
|
|
1263
|
-
return
|
|
1310
|
+
return bitsetHas(this.retired, internalId);
|
|
1264
1311
|
}
|
|
1265
1312
|
beginBatch() {
|
|
1266
1313
|
this.batchMode = true;
|
|
@@ -1284,7 +1331,7 @@ var LivePostings = class {
|
|
|
1284
1331
|
this.pool = new PostingPool(POSTING_POOL_START_ENTRIES);
|
|
1285
1332
|
this.pool.epoch = epoch;
|
|
1286
1333
|
this.positions = new PositionPool(POSITION_POOL_START_VALUES);
|
|
1287
|
-
this.retired = new
|
|
1334
|
+
this.retired = new Uint32Array(RETIRED_DOCUMENTS_START_CAPACITY >>> 5);
|
|
1288
1335
|
this.dirty.clear();
|
|
1289
1336
|
this.cachedViews.clear();
|
|
1290
1337
|
this.compactedSlack = 0;
|
|
@@ -1293,12 +1340,13 @@ var LivePostings = class {
|
|
|
1293
1340
|
return this.terms.byteLength() + this.pool.byteLength() + this.positions.values.byteLength + this.retired.byteLength;
|
|
1294
1341
|
}
|
|
1295
1342
|
retire(internalId) {
|
|
1296
|
-
|
|
1297
|
-
|
|
1343
|
+
const word = internalId >>> 5;
|
|
1344
|
+
if (word >= this.retired.length) {
|
|
1345
|
+
const grown = new Uint32Array(Math.max(word + 1, this.retired.length * 2));
|
|
1298
1346
|
grown.set(this.retired);
|
|
1299
1347
|
this.retired = grown;
|
|
1300
1348
|
}
|
|
1301
|
-
this.retired
|
|
1349
|
+
bitsetSet(this.retired, internalId);
|
|
1302
1350
|
}
|
|
1303
1351
|
purgeRetired() {
|
|
1304
1352
|
const terms = this.terms;
|
|
@@ -1310,7 +1358,7 @@ var LivePostings = class {
|
|
|
1310
1358
|
compact(ordinal) {
|
|
1311
1359
|
if (this.terms.deadDocuments[ordinal] === 0) return;
|
|
1312
1360
|
const retired = this.retired;
|
|
1313
|
-
this.filterEntries(ordinal, (id) =>
|
|
1361
|
+
this.filterEntries(ordinal, (id) => bitsetHas(retired, id));
|
|
1314
1362
|
this.terms.deadDocuments[ordinal] = 0;
|
|
1315
1363
|
}
|
|
1316
1364
|
filterEntries(ordinal, drop) {
|
|
@@ -1463,6 +1511,7 @@ function createInvertedIndex(fieldNameTable) {
|
|
|
1463
1511
|
return entries;
|
|
1464
1512
|
}
|
|
1465
1513
|
return {
|
|
1514
|
+
livePostings: postings,
|
|
1466
1515
|
insert(token, internalId, termFrequency, fieldNameIndex, positions) {
|
|
1467
1516
|
postings.insert(token, internalId, termFrequency, fieldNameIndex, positions);
|
|
1468
1517
|
},
|
|
@@ -1968,422 +2017,6 @@ function patternIndexOf(indexes, fieldPath) {
|
|
|
1968
2017
|
return index;
|
|
1969
2018
|
}
|
|
1970
2019
|
|
|
1971
|
-
// src/geo/cells.ts
|
|
1972
|
-
var AXIS_CELLS = 2 ** LOCATION_CODE_BITS_PER_AXIS;
|
|
1973
|
-
function axisCell(value, lowest, span) {
|
|
1974
|
-
const cell = Math.floor((value - lowest) / span * AXIS_CELLS);
|
|
1975
|
-
if (!(cell > 0)) return 0;
|
|
1976
|
-
return cell >= AXIS_CELLS ? AXIS_CELLS - 1 : cell;
|
|
1977
|
-
}
|
|
1978
|
-
function latitudeCell(lat) {
|
|
1979
|
-
return axisCell(lat, -MAX_LATITUDE_DEGREES, 2 * MAX_LATITUDE_DEGREES);
|
|
1980
|
-
}
|
|
1981
|
-
function longitudeCell(lon) {
|
|
1982
|
-
return axisCell(lon, -MAX_LONGITUDE_DEGREES, FULL_TURN_DEGREES);
|
|
1983
|
-
}
|
|
1984
|
-
function interleave(row, column, bits) {
|
|
1985
|
-
let code = 0;
|
|
1986
|
-
for (let bit = bits - 1; bit >= 0; bit--) code = code * 4 + (row >>> bit & 1) * 2 + (column >>> bit & 1);
|
|
1987
|
-
return code;
|
|
1988
|
-
}
|
|
1989
|
-
function locationCode(lat, lon) {
|
|
1990
|
-
return interleave(latitudeCell(lat), longitudeCell(lon), LOCATION_CODE_BITS_PER_AXIS);
|
|
1991
|
-
}
|
|
1992
|
-
function appendBoxRanges(box, out) {
|
|
1993
|
-
const south = latitudeCell(box.south);
|
|
1994
|
-
const north = latitudeCell(box.north);
|
|
1995
|
-
const west = longitudeCell(box.west);
|
|
1996
|
-
const east = longitudeCell(box.east);
|
|
1997
|
-
let level = LOCATION_CODE_BITS_PER_AXIS;
|
|
1998
|
-
while (level > 0) {
|
|
1999
|
-
const shift2 = LOCATION_CODE_BITS_PER_AXIS - level;
|
|
2000
|
-
const rows = (north >>> shift2) - (south >>> shift2) + 1;
|
|
2001
|
-
const columns = (east >>> shift2) - (west >>> shift2) + 1;
|
|
2002
|
-
if (rows * columns <= MAX_COVERING_CELLS) break;
|
|
2003
|
-
level--;
|
|
2004
|
-
}
|
|
2005
|
-
const shift = LOCATION_CODE_BITS_PER_AXIS - level;
|
|
2006
|
-
const codesPerCell = 4 ** shift;
|
|
2007
|
-
for (let row = south >>> shift; row <= north >>> shift; row++) {
|
|
2008
|
-
for (let column = west >>> shift; column <= east >>> shift; column++) {
|
|
2009
|
-
const from = interleave(row, column, level) * codesPerCell;
|
|
2010
|
-
out.push({ from, to: from + codesPerCell });
|
|
2011
|
-
}
|
|
2012
|
-
}
|
|
2013
|
-
}
|
|
2014
|
-
function coveringRanges(boxes) {
|
|
2015
|
-
const ranges = [];
|
|
2016
|
-
for (const box of boxes) appendBoxRanges(box, ranges);
|
|
2017
|
-
ranges.sort((left, right) => left.from - right.from);
|
|
2018
|
-
const merged = [];
|
|
2019
|
-
for (const range of ranges) {
|
|
2020
|
-
const last = merged[merged.length - 1];
|
|
2021
|
-
if (last !== void 0 && range.from <= last.to) {
|
|
2022
|
-
if (range.to > last.to) last.to = range.to;
|
|
2023
|
-
} else {
|
|
2024
|
-
merged.push({ from: range.from, to: range.to });
|
|
2025
|
-
}
|
|
2026
|
-
}
|
|
2027
|
-
return merged;
|
|
2028
|
-
}
|
|
2029
|
-
function longitudeBoxes(south, north, west, east) {
|
|
2030
|
-
if (east - west >= FULL_TURN_DEGREES) {
|
|
2031
|
-
return [{ south, north, west: -MAX_LONGITUDE_DEGREES, east: MAX_LONGITUDE_DEGREES }];
|
|
2032
|
-
}
|
|
2033
|
-
if (west < -MAX_LONGITUDE_DEGREES) {
|
|
2034
|
-
return [
|
|
2035
|
-
{ south, north, west: west + FULL_TURN_DEGREES, east: MAX_LONGITUDE_DEGREES },
|
|
2036
|
-
{ south, north, west: -MAX_LONGITUDE_DEGREES, east }
|
|
2037
|
-
];
|
|
2038
|
-
}
|
|
2039
|
-
if (east > MAX_LONGITUDE_DEGREES) {
|
|
2040
|
-
return [
|
|
2041
|
-
{ south, north, west, east: MAX_LONGITUDE_DEGREES },
|
|
2042
|
-
{ south, north, west: -MAX_LONGITUDE_DEGREES, east: east - FULL_TURN_DEGREES }
|
|
2043
|
-
];
|
|
2044
|
-
}
|
|
2045
|
-
return [{ south, north, west, east }];
|
|
2046
|
-
}
|
|
2047
|
-
function radiusBoxes(lat, lon, distanceMeters) {
|
|
2048
|
-
const angle = distanceMeters / EARTH_RADIUS_METERS * RADIUS_BOX_MARGIN_RATIO + RADIUS_BOX_MARGIN_RADIANS;
|
|
2049
|
-
const angleDegrees = angle / DEG_TO_RAD;
|
|
2050
|
-
const south = lat - angleDegrees;
|
|
2051
|
-
const north = lat + angleDegrees;
|
|
2052
|
-
if (angle >= Math.PI || south <= -MAX_LATITUDE_DEGREES || north >= MAX_LATITUDE_DEGREES) {
|
|
2053
|
-
return [
|
|
2054
|
-
{
|
|
2055
|
-
south: Math.max(south, -MAX_LATITUDE_DEGREES),
|
|
2056
|
-
north: Math.min(north, MAX_LATITUDE_DEGREES),
|
|
2057
|
-
west: -MAX_LONGITUDE_DEGREES,
|
|
2058
|
-
east: MAX_LONGITUDE_DEGREES
|
|
2059
|
-
}
|
|
2060
|
-
];
|
|
2061
|
-
}
|
|
2062
|
-
const spread = Math.asin(Math.sin(angle) / Math.cos(lat * DEG_TO_RAD)) / DEG_TO_RAD;
|
|
2063
|
-
return longitudeBoxes(south, north, lon - spread, lon + spread);
|
|
2064
|
-
}
|
|
2065
|
-
|
|
2066
|
-
// src/geo/haversine.ts
|
|
2067
|
-
function haversineDistance(lat1, lon1, lat2, lon2) {
|
|
2068
|
-
const phi1 = lat1 * DEG_TO_RAD;
|
|
2069
|
-
const phi2 = lat2 * DEG_TO_RAD;
|
|
2070
|
-
const deltaPhi = (lat2 - lat1) * DEG_TO_RAD;
|
|
2071
|
-
const deltaLambda = (lon2 - lon1) * DEG_TO_RAD;
|
|
2072
|
-
const halfDeltaPhi = Math.sin(deltaPhi / 2);
|
|
2073
|
-
const halfDeltaLambda = Math.sin(deltaLambda / 2);
|
|
2074
|
-
const a = halfDeltaPhi * halfDeltaPhi + Math.cos(phi1) * Math.cos(phi2) * halfDeltaLambda * halfDeltaLambda;
|
|
2075
|
-
const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
|
|
2076
|
-
return EARTH_RADIUS_METERS * c;
|
|
2077
|
-
}
|
|
2078
|
-
|
|
2079
|
-
// src/geo/edge-tree.ts
|
|
2080
|
-
function buildLongitudeEdgeTree(lons) {
|
|
2081
|
-
const n = lons.length;
|
|
2082
|
-
const edges = [];
|
|
2083
|
-
for (let i = 0; i < n; i++) {
|
|
2084
|
-
if (lons[i] !== lons[i === 0 ? n - 1 : i - 1]) edges.push(i);
|
|
2085
|
-
}
|
|
2086
|
-
const lowOf = (i) => Math.min(lons[i], lons[i === 0 ? n - 1 : i - 1]);
|
|
2087
|
-
edges.sort((left, right) => lowOf(left) - lowOf(right));
|
|
2088
|
-
const count = edges.length;
|
|
2089
|
-
const tree = {
|
|
2090
|
-
from: new Int32Array(count),
|
|
2091
|
-
to: new Int32Array(count),
|
|
2092
|
-
low: new Float64Array(count),
|
|
2093
|
-
high: new Float64Array(count),
|
|
2094
|
-
subtreeHigh: new Float64Array(count)
|
|
2095
|
-
};
|
|
2096
|
-
edges.forEach((i, at) => {
|
|
2097
|
-
const j = i === 0 ? n - 1 : i - 1;
|
|
2098
|
-
tree.from[at] = i;
|
|
2099
|
-
tree.to[at] = j;
|
|
2100
|
-
tree.low[at] = Math.min(lons[i], lons[j]);
|
|
2101
|
-
tree.high[at] = Math.max(lons[i], lons[j]);
|
|
2102
|
-
});
|
|
2103
|
-
const fillSubtreeHigh = (start, end) => {
|
|
2104
|
-
if (start >= end) return Number.NEGATIVE_INFINITY;
|
|
2105
|
-
const mid = start + end >>> 1;
|
|
2106
|
-
const highest = Math.max(tree.high[mid], fillSubtreeHigh(start, mid), fillSubtreeHigh(mid + 1, end));
|
|
2107
|
-
tree.subtreeHigh[mid] = highest;
|
|
2108
|
-
return highest;
|
|
2109
|
-
};
|
|
2110
|
-
fillSubtreeHigh(0, count);
|
|
2111
|
-
return tree;
|
|
2112
|
-
}
|
|
2113
|
-
function forEachEdgeSpanning(tree, lon, visit) {
|
|
2114
|
-
const walk = (start, end) => {
|
|
2115
|
-
if (start >= end) return;
|
|
2116
|
-
const mid = start + end >>> 1;
|
|
2117
|
-
if (tree.subtreeHigh[mid] <= lon) return;
|
|
2118
|
-
walk(start, mid);
|
|
2119
|
-
if (tree.low[mid] > lon) return;
|
|
2120
|
-
if (lon < tree.high[mid]) visit(tree.from[mid], tree.to[mid]);
|
|
2121
|
-
walk(mid + 1, end);
|
|
2122
|
-
};
|
|
2123
|
-
walk(0, tree.from.length);
|
|
2124
|
-
}
|
|
2125
|
-
|
|
2126
|
-
// src/geo/polygon.ts
|
|
2127
|
-
function requirePolygonRing(points) {
|
|
2128
|
-
if (!Array.isArray(points) || points.length < MIN_POLYGON_POINTS) {
|
|
2129
|
-
throw new NarsilError(
|
|
2130
|
-
ErrorCodes.SEARCH_INVALID_FILTER,
|
|
2131
|
-
`A polygon encloses an area only with at least ${MIN_POLYGON_POINTS} points`,
|
|
2132
|
-
{ points: Array.isArray(points) ? points.length : typeof points, minimum: MIN_POLYGON_POINTS }
|
|
2133
|
-
);
|
|
2134
|
-
}
|
|
2135
|
-
points.forEach((point, position) => {
|
|
2136
|
-
const { lat, lon } = point ?? {};
|
|
2137
|
-
if (typeof lat !== "number" || !Number.isFinite(lat) || typeof lon !== "number" || !Number.isFinite(lon)) {
|
|
2138
|
-
throw new NarsilError(
|
|
2139
|
-
ErrorCodes.SEARCH_INVALID_FILTER,
|
|
2140
|
-
`A polygon point carries a finite "lat" and "lon", and the point at position ${position} does not`,
|
|
2141
|
-
{ position }
|
|
2142
|
-
);
|
|
2143
|
-
}
|
|
2144
|
-
if (isLatitude(lat) && isLongitude(lon)) return;
|
|
2145
|
-
throw new NarsilError(
|
|
2146
|
-
ErrorCodes.SEARCH_INVALID_FILTER,
|
|
2147
|
-
`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}`,
|
|
2148
|
-
{ position, lat, lon }
|
|
2149
|
-
);
|
|
2150
|
-
});
|
|
2151
|
-
}
|
|
2152
|
-
function signedArea(polygon) {
|
|
2153
|
-
let area = 0;
|
|
2154
|
-
for (let i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {
|
|
2155
|
-
area += polygon[j].lon * polygon[i].lat - polygon[i].lon * polygon[j].lat;
|
|
2156
|
-
}
|
|
2157
|
-
return area;
|
|
2158
|
-
}
|
|
2159
|
-
function crossesAntimeridian(polygon) {
|
|
2160
|
-
let west = Number.POSITIVE_INFINITY;
|
|
2161
|
-
let east = Number.NEGATIVE_INFINITY;
|
|
2162
|
-
for (const point of polygon) {
|
|
2163
|
-
if (point.lon < west) west = point.lon;
|
|
2164
|
-
if (point.lon > east) east = point.lon;
|
|
2165
|
-
}
|
|
2166
|
-
return east - west >= ANTIMERIDIAN_SPAN_DEGREES && signedArea(polygon) < 0;
|
|
2167
|
-
}
|
|
2168
|
-
function eastward(lon) {
|
|
2169
|
-
return lon < 0 ? lon + FULL_TURN_DEGREES : lon;
|
|
2170
|
-
}
|
|
2171
|
-
function polygonContainment(polygon) {
|
|
2172
|
-
const n = polygon.length;
|
|
2173
|
-
if (n < MIN_POLYGON_POINTS) return () => false;
|
|
2174
|
-
const unwrap = crossesAntimeridian(polygon);
|
|
2175
|
-
const lats = new Float64Array(n);
|
|
2176
|
-
const lons = new Float64Array(n);
|
|
2177
|
-
for (let i = 0; i < n; i++) {
|
|
2178
|
-
lats[i] = polygon[i].lat;
|
|
2179
|
-
lons[i] = unwrap ? eastward(polygon[i].lon) : polygon[i].lon;
|
|
2180
|
-
}
|
|
2181
|
-
const edges = buildLongitudeEdgeTree(lons);
|
|
2182
|
-
return (lat, rawLon) => {
|
|
2183
|
-
const lon = unwrap ? eastward(rawLon) : rawLon;
|
|
2184
|
-
let inside = false;
|
|
2185
|
-
forEachEdgeSpanning(edges, lon, (i, j) => {
|
|
2186
|
-
const intersectLat = lats[i] + (lats[j] - lats[i]) / (lons[j] - lons[i]) * (lon - lons[i]);
|
|
2187
|
-
if (lat < intersectLat) inside = !inside;
|
|
2188
|
-
});
|
|
2189
|
-
return inside;
|
|
2190
|
-
};
|
|
2191
|
-
}
|
|
2192
|
-
function polygonBoxes(polygon) {
|
|
2193
|
-
if (polygon.length < MIN_POLYGON_POINTS) return [];
|
|
2194
|
-
const unwrap = crossesAntimeridian(polygon);
|
|
2195
|
-
let south = Number.POSITIVE_INFINITY;
|
|
2196
|
-
let north = Number.NEGATIVE_INFINITY;
|
|
2197
|
-
let west = Number.POSITIVE_INFINITY;
|
|
2198
|
-
let east = Number.NEGATIVE_INFINITY;
|
|
2199
|
-
for (const point of polygon) {
|
|
2200
|
-
const lon = unwrap ? eastward(point.lon) : point.lon;
|
|
2201
|
-
south = Math.min(south, point.lat);
|
|
2202
|
-
north = Math.max(north, point.lat);
|
|
2203
|
-
west = Math.min(west, lon);
|
|
2204
|
-
east = Math.max(east, lon);
|
|
2205
|
-
}
|
|
2206
|
-
if (west >= MAX_LONGITUDE_DEGREES)
|
|
2207
|
-
return longitudeBoxes(south, north, west - FULL_TURN_DEGREES, east - FULL_TURN_DEGREES);
|
|
2208
|
-
return longitudeBoxes(south, north, west, east);
|
|
2209
|
-
}
|
|
2210
|
-
|
|
2211
|
-
// src/geo/vincenty.ts
|
|
2212
|
-
var WGS84_A = 6378137;
|
|
2213
|
-
var WGS84_F = 1 / 298.257223563;
|
|
2214
|
-
var WGS84_B = WGS84_A * (1 - WGS84_F);
|
|
2215
|
-
function vincentyDistance(lat1, lon1, lat2, lon2) {
|
|
2216
|
-
const phi1 = lat1 * DEG_TO_RAD;
|
|
2217
|
-
const phi2 = lat2 * DEG_TO_RAD;
|
|
2218
|
-
const L = (lon2 - lon1) * DEG_TO_RAD;
|
|
2219
|
-
const U1 = Math.atan((1 - WGS84_F) * Math.tan(phi1));
|
|
2220
|
-
const U2 = Math.atan((1 - WGS84_F) * Math.tan(phi2));
|
|
2221
|
-
const sinU1 = Math.sin(U1);
|
|
2222
|
-
const cosU1 = Math.cos(U1);
|
|
2223
|
-
const sinU2 = Math.sin(U2);
|
|
2224
|
-
const cosU2 = Math.cos(U2);
|
|
2225
|
-
let lambda = L;
|
|
2226
|
-
let prevLambda;
|
|
2227
|
-
let sinSigma = 0;
|
|
2228
|
-
let cosSigma = 0;
|
|
2229
|
-
let sigma = 0;
|
|
2230
|
-
let sinAlpha = 0;
|
|
2231
|
-
let cos2Alpha = 0;
|
|
2232
|
-
let cos2SigmaM = 0;
|
|
2233
|
-
let iterations = VINCENTY_MAX_ITERATIONS;
|
|
2234
|
-
do {
|
|
2235
|
-
const sinLambda = Math.sin(lambda);
|
|
2236
|
-
const cosLambda = Math.cos(lambda);
|
|
2237
|
-
const term1 = cosU2 * sinLambda;
|
|
2238
|
-
const term2 = cosU1 * sinU2 - sinU1 * cosU2 * cosLambda;
|
|
2239
|
-
sinSigma = Math.sqrt(term1 * term1 + term2 * term2);
|
|
2240
|
-
if (sinSigma === 0) return 0;
|
|
2241
|
-
cosSigma = sinU1 * sinU2 + cosU1 * cosU2 * cosLambda;
|
|
2242
|
-
sigma = Math.atan2(sinSigma, cosSigma);
|
|
2243
|
-
sinAlpha = cosU1 * cosU2 * sinLambda / sinSigma;
|
|
2244
|
-
cos2Alpha = 1 - sinAlpha * sinAlpha;
|
|
2245
|
-
cos2SigmaM = cos2Alpha === 0 ? 0 : cosSigma - 2 * sinU1 * sinU2 / cos2Alpha;
|
|
2246
|
-
const C = WGS84_F / 16 * cos2Alpha * (4 + WGS84_F * (4 - 3 * cos2Alpha));
|
|
2247
|
-
prevLambda = lambda;
|
|
2248
|
-
lambda = L + (1 - C) * WGS84_F * sinAlpha * (sigma + C * sinSigma * (cos2SigmaM + C * cosSigma * (-1 + 2 * cos2SigmaM * cos2SigmaM)));
|
|
2249
|
-
} while (Math.abs(lambda - prevLambda) > VINCENTY_CONVERGENCE_THRESHOLD && --iterations > 0);
|
|
2250
|
-
if (iterations === 0) {
|
|
2251
|
-
return haversineDistance(lat1, lon1, lat2, lon2);
|
|
2252
|
-
}
|
|
2253
|
-
const uSq = cos2Alpha * (WGS84_A * WGS84_A - WGS84_B * WGS84_B) / (WGS84_B * WGS84_B);
|
|
2254
|
-
const A = 1 + uSq / 16384 * (4096 + uSq * (-768 + uSq * (320 - 175 * uSq)));
|
|
2255
|
-
const B = uSq / 1024 * (256 + uSq * (-128 + uSq * (74 - 47 * uSq)));
|
|
2256
|
-
const deltaSigma = B * sinSigma * (cos2SigmaM + B / 4 * (cosSigma * (-1 + 2 * cos2SigmaM * cos2SigmaM) - B / 6 * cos2SigmaM * (-3 + 4 * sinSigma * sinSigma) * (-3 + 4 * cos2SigmaM * cos2SigmaM)));
|
|
2257
|
-
return WGS84_B * A * (sigma - deltaSigma);
|
|
2258
|
-
}
|
|
2259
|
-
|
|
2260
|
-
// src/geo/geo-index.ts
|
|
2261
|
-
var REMOVED_DOC_ID = -1;
|
|
2262
|
-
function firstAtOrAfter(entries, code) {
|
|
2263
|
-
let lo = 0;
|
|
2264
|
-
let hi = entries.length;
|
|
2265
|
-
while (lo < hi) {
|
|
2266
|
-
const mid = lo + hi >>> 1;
|
|
2267
|
-
if (entries[mid].code < code) lo = mid + 1;
|
|
2268
|
-
else hi = mid;
|
|
2269
|
-
}
|
|
2270
|
-
return lo;
|
|
2271
|
-
}
|
|
2272
|
-
function dropRemoved(entries) {
|
|
2273
|
-
let write = 0;
|
|
2274
|
-
for (let read = 0; read < entries.length; read++) {
|
|
2275
|
-
if (entries[read].docId !== REMOVED_DOC_ID) entries[write++] = entries[read];
|
|
2276
|
-
}
|
|
2277
|
-
entries.length = write;
|
|
2278
|
-
}
|
|
2279
|
-
function mergeSortedPending(entries, pending) {
|
|
2280
|
-
pending.sort((left2, right2) => left2.code - right2.code || left2.docId - right2.docId);
|
|
2281
|
-
const mainLength = entries.length;
|
|
2282
|
-
for (const entry of pending) entries.push(entry);
|
|
2283
|
-
let left = mainLength - 1;
|
|
2284
|
-
let right = pending.length - 1;
|
|
2285
|
-
let write = entries.length - 1;
|
|
2286
|
-
while (right >= 0) {
|
|
2287
|
-
const later = left >= 0 ? entries[left] : void 0;
|
|
2288
|
-
const next = pending[right];
|
|
2289
|
-
if (later !== void 0 && (later.code > next.code || later.code === next.code && later.docId > next.docId)) {
|
|
2290
|
-
entries[write--] = later;
|
|
2291
|
-
left--;
|
|
2292
|
-
} else {
|
|
2293
|
-
entries[write--] = next;
|
|
2294
|
-
right--;
|
|
2295
|
-
}
|
|
2296
|
-
}
|
|
2297
|
-
}
|
|
2298
|
-
function createGeoIndex() {
|
|
2299
|
-
let entries = [];
|
|
2300
|
-
let pending = [];
|
|
2301
|
-
const byDocument = /* @__PURE__ */ new Map();
|
|
2302
|
-
let removedCount = 0;
|
|
2303
|
-
function ensureSorted() {
|
|
2304
|
-
if (removedCount > 0) {
|
|
2305
|
-
dropRemoved(entries);
|
|
2306
|
-
dropRemoved(pending);
|
|
2307
|
-
removedCount = 0;
|
|
2308
|
-
}
|
|
2309
|
-
if (pending.length === 0) return;
|
|
2310
|
-
if (entries.length === 0) {
|
|
2311
|
-
pending.sort((left, right) => left.code - right.code || left.docId - right.docId);
|
|
2312
|
-
entries = pending;
|
|
2313
|
-
} else {
|
|
2314
|
-
mergeSortedPending(entries, pending);
|
|
2315
|
-
}
|
|
2316
|
-
pending = [];
|
|
2317
|
-
}
|
|
2318
|
-
function removeEntry(entry) {
|
|
2319
|
-
byDocument.delete(entry.docId);
|
|
2320
|
-
entry.docId = REMOVED_DOC_ID;
|
|
2321
|
-
removedCount++;
|
|
2322
|
-
const held = entries.length + pending.length;
|
|
2323
|
-
if (removedCount >= Math.max(PENDING_REMOVAL_MERGE_FLOOR, held / PENDING_REMOVAL_MERGE_DIVISOR)) ensureSorted();
|
|
2324
|
-
}
|
|
2325
|
-
function matching(boxes, passes, inside) {
|
|
2326
|
-
ensureSorted();
|
|
2327
|
-
const within = /* @__PURE__ */ new Set();
|
|
2328
|
-
for (const range of coveringRanges(boxes)) {
|
|
2329
|
-
for (let at = firstAtOrAfter(entries, range.from); at < entries.length && entries[at].code < range.to; at++) {
|
|
2330
|
-
if (passes(entries[at])) within.add(entries[at].docId);
|
|
2331
|
-
}
|
|
2332
|
-
}
|
|
2333
|
-
if (inside) return within;
|
|
2334
|
-
const outside = /* @__PURE__ */ new Set();
|
|
2335
|
-
for (const entry of entries) {
|
|
2336
|
-
if (!within.has(entry.docId)) outside.add(entry.docId);
|
|
2337
|
-
}
|
|
2338
|
-
return outside;
|
|
2339
|
-
}
|
|
2340
|
-
const index = {
|
|
2341
|
-
insert(internalId, lat, lon) {
|
|
2342
|
-
const existing = byDocument.get(internalId);
|
|
2343
|
-
if (existing !== void 0) removeEntry(existing);
|
|
2344
|
-
const entry = { lat, lon, docId: internalId, code: locationCode(lat, lon) };
|
|
2345
|
-
pending.push(entry);
|
|
2346
|
-
byDocument.set(internalId, entry);
|
|
2347
|
-
},
|
|
2348
|
-
remove(internalId) {
|
|
2349
|
-
const existing = byDocument.get(internalId);
|
|
2350
|
-
if (existing !== void 0) removeEntry(existing);
|
|
2351
|
-
},
|
|
2352
|
-
radiusQuery(lat, lon, distanceMeters, inside, highPrecision) {
|
|
2353
|
-
const distanceFn = highPrecision ? vincentyDistance : haversineDistance;
|
|
2354
|
-
return matching(
|
|
2355
|
-
radiusBoxes(lat, lon, distanceMeters),
|
|
2356
|
-
(entry) => distanceFn(lat, lon, entry.lat, entry.lon) <= distanceMeters,
|
|
2357
|
-
inside
|
|
2358
|
-
);
|
|
2359
|
-
},
|
|
2360
|
-
polygonQuery(points, inside) {
|
|
2361
|
-
const contains = polygonContainment(points);
|
|
2362
|
-
return matching(polygonBoxes(points), (entry) => contains(entry.lat, entry.lon), inside);
|
|
2363
|
-
},
|
|
2364
|
-
documentsBitset(capacity) {
|
|
2365
|
-
const bits = createBitSet(capacity);
|
|
2366
|
-
for (const docId of byDocument.keys()) bitsetSet(bits, docId);
|
|
2367
|
-
return bits;
|
|
2368
|
-
},
|
|
2369
|
-
clear() {
|
|
2370
|
-
entries = [];
|
|
2371
|
-
pending = [];
|
|
2372
|
-
byDocument.clear();
|
|
2373
|
-
removedCount = 0;
|
|
2374
|
-
},
|
|
2375
|
-
serialize() {
|
|
2376
|
-
ensureSorted();
|
|
2377
|
-
return entries.map((entry) => ({ lat: entry.lat, lon: entry.lon, docId: entry.docId }));
|
|
2378
|
-
},
|
|
2379
|
-
deserialize(data) {
|
|
2380
|
-
index.clear();
|
|
2381
|
-
for (const entry of data) index.insert(entry.docId, entry.lat, entry.lon);
|
|
2382
|
-
}
|
|
2383
|
-
};
|
|
2384
|
-
return index;
|
|
2385
|
-
}
|
|
2386
|
-
|
|
2387
2020
|
// src/core/field-index/boolean.ts
|
|
2388
2021
|
function createBooleanIndex() {
|
|
2389
2022
|
const trueDocs = /* @__PURE__ */ new Set();
|
|
@@ -2465,7 +2098,7 @@ function reversedUnits(value) {
|
|
|
2465
2098
|
for (let at = value.length - 1; at >= 0; at--) reversed += value[at];
|
|
2466
2099
|
return reversed;
|
|
2467
2100
|
}
|
|
2468
|
-
function
|
|
2101
|
+
function firstAtOrAfter(sorted, key) {
|
|
2469
2102
|
let lo = 0;
|
|
2470
2103
|
let hi = sorted.length;
|
|
2471
2104
|
while (lo < hi) {
|
|
@@ -2523,7 +2156,7 @@ var ValueAffixes = class {
|
|
|
2523
2156
|
}
|
|
2524
2157
|
matching(column, start) {
|
|
2525
2158
|
const found = [];
|
|
2526
|
-
for (let at =
|
|
2159
|
+
for (let at = firstAtOrAfter(column.keys, start); at < column.keys.length; at++) {
|
|
2527
2160
|
if (!column.keys[at].startsWith(start)) break;
|
|
2528
2161
|
found.push(column.values[at]);
|
|
2529
2162
|
}
|
|
@@ -2761,7 +2394,7 @@ function removeFromPending(pending, marked, byDocument) {
|
|
|
2761
2394
|
}
|
|
2762
2395
|
pending.length = write;
|
|
2763
2396
|
}
|
|
2764
|
-
function
|
|
2397
|
+
function mergeSortedPending(entries, pending) {
|
|
2765
2398
|
pending.sort((a, b) => a.value - b.value);
|
|
2766
2399
|
const mainLength = entries.length;
|
|
2767
2400
|
for (const entry of pending) entries.push(entry);
|
|
@@ -2797,7 +2430,7 @@ function createNumericIndex() {
|
|
|
2797
2430
|
pending.sort((a, b) => a.value - b.value);
|
|
2798
2431
|
entries = pending;
|
|
2799
2432
|
} else {
|
|
2800
|
-
|
|
2433
|
+
mergeSortedPending(entries, pending);
|
|
2801
2434
|
}
|
|
2802
2435
|
pending = [];
|
|
2803
2436
|
}
|
|
@@ -2985,7 +2618,7 @@ function ensureFieldIndex(state, fieldPath, base) {
|
|
|
2985
2618
|
} else if ((base === "enum" || base === "enum[]") && !state.enumIndexes.has(fieldPath)) {
|
|
2986
2619
|
state.enumIndexes.set(fieldPath, createEnumIndex());
|
|
2987
2620
|
} else if (base === "geopoint" && !state.geoIndexes.has(fieldPath)) {
|
|
2988
|
-
state.geoIndexes.set(fieldPath,
|
|
2621
|
+
state.geoIndexes.set(fieldPath, createLoadedGeoIndex());
|
|
2989
2622
|
}
|
|
2990
2623
|
}
|
|
2991
2624
|
function getOrCreateNumericIndex(state, fieldPath) {
|
|
@@ -3568,6 +3201,33 @@ var FIELD_FILTER_OPERATORS = [
|
|
|
3568
3201
|
"polygon"
|
|
3569
3202
|
];
|
|
3570
3203
|
|
|
3204
|
+
// src/geo/polygon-ring.ts
|
|
3205
|
+
function requirePolygonRing(points) {
|
|
3206
|
+
if (!Array.isArray(points) || points.length < MIN_POLYGON_POINTS) {
|
|
3207
|
+
throw new NarsilError(
|
|
3208
|
+
ErrorCodes.SEARCH_INVALID_FILTER,
|
|
3209
|
+
`A polygon encloses an area only with at least ${MIN_POLYGON_POINTS} points`,
|
|
3210
|
+
{ points: Array.isArray(points) ? points.length : typeof points, minimum: MIN_POLYGON_POINTS }
|
|
3211
|
+
);
|
|
3212
|
+
}
|
|
3213
|
+
points.forEach((point, position) => {
|
|
3214
|
+
const { lat, lon } = point ?? {};
|
|
3215
|
+
if (typeof lat !== "number" || !Number.isFinite(lat) || typeof lon !== "number" || !Number.isFinite(lon)) {
|
|
3216
|
+
throw new NarsilError(
|
|
3217
|
+
ErrorCodes.SEARCH_INVALID_FILTER,
|
|
3218
|
+
`A polygon point carries a finite "lat" and "lon", and the point at position ${position} does not`,
|
|
3219
|
+
{ position }
|
|
3220
|
+
);
|
|
3221
|
+
}
|
|
3222
|
+
if (isLatitude(lat) && isLongitude(lon)) return;
|
|
3223
|
+
throw new NarsilError(
|
|
3224
|
+
ErrorCodes.SEARCH_INVALID_FILTER,
|
|
3225
|
+
`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}`,
|
|
3226
|
+
{ position, lat, lon }
|
|
3227
|
+
);
|
|
3228
|
+
});
|
|
3229
|
+
}
|
|
3230
|
+
|
|
3571
3231
|
// src/filters/operands/geo.ts
|
|
3572
3232
|
function requireFlag(fieldPath, operator, flag, value) {
|
|
3573
3233
|
if (value === void 0 || typeof value === "boolean") return;
|
|
@@ -4705,17 +4365,21 @@ function presentBitsetOf(state, fieldPath, type, capacity) {
|
|
|
4705
4365
|
if (base === "number") present = state.numericIndexes.get(fieldPath)?.getAllDocIdsBitset(capacity);
|
|
4706
4366
|
else if (base === "boolean") present = state.booleanIndexes.get(fieldPath)?.getAllDocIdsBitset(capacity);
|
|
4707
4367
|
else if (base === "enum") present = state.enumIndexes.get(fieldPath)?.getAllDocIdsBitset(capacity);
|
|
4708
|
-
else if (base === "geopoint") present = state
|
|
4368
|
+
else if (base === "geopoint") present = geoDocumentsBitset(state, fieldPath, capacity);
|
|
4709
4369
|
else if (base !== void 0 && keepsValueSize(base)) {
|
|
4710
4370
|
present = state.sizeIndexes.get(fieldPath)?.getAllDocIdsBitset(capacity);
|
|
4711
4371
|
}
|
|
4712
4372
|
return present ?? createBitSet(capacity);
|
|
4713
4373
|
}
|
|
4714
|
-
function
|
|
4374
|
+
function bitsetOfDocuments(internalIds, capacity) {
|
|
4715
4375
|
const bits = createBitSet(capacity);
|
|
4716
|
-
for (const internalId of
|
|
4376
|
+
for (const internalId of internalIds) bitsetSet(bits, internalId);
|
|
4717
4377
|
return bits;
|
|
4718
4378
|
}
|
|
4379
|
+
function geoDocumentsBitset(state, fieldPath, capacity) {
|
|
4380
|
+
const geoIndex = state.geoIndexes.get(fieldPath);
|
|
4381
|
+
return geoIndex === void 0 ? void 0 : bitsetOfDocuments(geoIndex.documentIds(), capacity);
|
|
4382
|
+
}
|
|
4719
4383
|
function buildFilterContext(state, schema, meter) {
|
|
4720
4384
|
const flat = getFlatSchema(state, schema);
|
|
4721
4385
|
const capacity = state.docStore.internalIdCapacity();
|
|
@@ -4767,7 +4431,7 @@ function buildFilterContext(state, schema, meter) {
|
|
|
4767
4431
|
},
|
|
4768
4432
|
capacity,
|
|
4769
4433
|
get allDocIdsBitset() {
|
|
4770
|
-
cachedAllDocIdsBitset ??=
|
|
4434
|
+
cachedAllDocIdsBitset ??= bitsetOfDocuments(state.docStore.allInternalIds(), capacity);
|
|
4771
4435
|
return cachedAllDocIdsBitset;
|
|
4772
4436
|
}
|
|
4773
4437
|
};
|
|
@@ -4824,356 +4488,6 @@ function partitionFilterMatches(state, filters, schema, meter) {
|
|
|
4824
4488
|
};
|
|
4825
4489
|
}
|
|
4826
4490
|
|
|
4827
|
-
// src/search/quotes.ts
|
|
4828
|
-
var QUOTE_CHARACTER = /["“”„]/;
|
|
4829
|
-
function holdsQuoteCharacter(term) {
|
|
4830
|
-
return QUOTE_CHARACTER.test(term);
|
|
4831
|
-
}
|
|
4832
|
-
function holdsQuotedText(term) {
|
|
4833
|
-
if (!QUOTE_CHARACTER.test(term)) return false;
|
|
4834
|
-
const parts = term.split(QUOTE_CHARACTER);
|
|
4835
|
-
for (let index = 1; index < parts.length; index += 2) {
|
|
4836
|
-
if (parts[index].trim().length > 0) return true;
|
|
4837
|
-
}
|
|
4838
|
-
return false;
|
|
4839
|
-
}
|
|
4840
|
-
|
|
4841
|
-
// src/search/phrase-code.ts
|
|
4842
|
-
var loaded = null;
|
|
4843
|
-
var loading = null;
|
|
4844
|
-
function requireLoadedPhraseCode() {
|
|
4845
|
-
if (loaded === null) {
|
|
4846
|
-
throw new NarsilError(ErrorCodes.SEARCH_PHRASE_NOT_READY, "The phrase code has not loaded. Try the query again");
|
|
4847
|
-
}
|
|
4848
|
-
return loaded;
|
|
4849
|
-
}
|
|
4850
|
-
function loadPhraseCode() {
|
|
4851
|
-
if (loading === null) {
|
|
4852
|
-
loading = import('./phrase-module-ZI4WSQVH.mjs').then(
|
|
4853
|
-
(code) => {
|
|
4854
|
-
loaded = code;
|
|
4855
|
-
return code;
|
|
4856
|
-
},
|
|
4857
|
-
(err) => {
|
|
4858
|
-
loading = null;
|
|
4859
|
-
throw new NarsilError(
|
|
4860
|
-
ErrorCodes.SEARCH_PHRASE_NOT_READY,
|
|
4861
|
-
"The phrase code failed to load. Remove the quotes, or try again once it can load",
|
|
4862
|
-
{ cause: err instanceof Error ? err.message : String(err) }
|
|
4863
|
-
);
|
|
4864
|
-
}
|
|
4865
|
-
);
|
|
4866
|
-
}
|
|
4867
|
-
return loading;
|
|
4868
|
-
}
|
|
4869
|
-
function loadPhraseCodeFor(term) {
|
|
4870
|
-
if (loaded !== null || term === void 0 || !holdsQuoteCharacter(term)) return null;
|
|
4871
|
-
return loadPhraseCode();
|
|
4872
|
-
}
|
|
4873
|
-
function analyseQueryPhrases(term, language, analysis) {
|
|
4874
|
-
if (!holdsQuoteCharacter(term)) return null;
|
|
4875
|
-
return requireLoadedPhraseCode().analyseQueryPhrases(
|
|
4876
|
-
term.split(QUOTE_CHARACTER),
|
|
4877
|
-
(text) => tokenize(text, language, {
|
|
4878
|
-
stem: true,
|
|
4879
|
-
removeStopWords: true,
|
|
4880
|
-
customTokenizer: analysis.customTokenizer,
|
|
4881
|
-
stopWordOverride: analysis.stopWords
|
|
4882
|
-
}).tokens
|
|
4883
|
-
);
|
|
4884
|
-
}
|
|
4885
|
-
|
|
4886
|
-
// src/core/scorer.ts
|
|
4887
|
-
function computeIDF(docFrequency, totalDocs) {
|
|
4888
|
-
if (totalDocs === 0) return 0;
|
|
4889
|
-
return Math.log((totalDocs - docFrequency + 0.5) / (docFrequency + 0.5) + 1);
|
|
4890
|
-
}
|
|
4891
|
-
function pairKeepsBoundSound(k1, b) {
|
|
4892
|
-
return k1 >= 0 && k1 <= MAX_BM25_K1 && b >= 0 && b <= MAX_BM25_B;
|
|
4893
|
-
}
|
|
4894
|
-
function bm25PruningSound(params) {
|
|
4895
|
-
const k1 = params?.k1 ?? DEFAULT_BM25_K1;
|
|
4896
|
-
const b = params?.b ?? DEFAULT_BM25_B;
|
|
4897
|
-
if (!pairKeepsBoundSound(k1, b)) return false;
|
|
4898
|
-
const fields = params?.fields;
|
|
4899
|
-
if (fields === void 0) return true;
|
|
4900
|
-
for (const name of Object.keys(fields)) {
|
|
4901
|
-
if (!pairKeepsBoundSound(fields[name].k1 ?? k1, fields[name].b ?? b)) return false;
|
|
4902
|
-
}
|
|
4903
|
-
return true;
|
|
4904
|
-
}
|
|
4905
|
-
function bm25SetsValue(params) {
|
|
4906
|
-
if (typeof params !== "object" || params === null) return params !== void 0;
|
|
4907
|
-
if (params.k1 !== void 0 || params.b !== void 0) return true;
|
|
4908
|
-
const fields = params.fields;
|
|
4909
|
-
if (fields === void 0) return false;
|
|
4910
|
-
if (typeof fields !== "object" || fields === null) return true;
|
|
4911
|
-
for (const name of Object.keys(fields)) {
|
|
4912
|
-
const pair = fields[name];
|
|
4913
|
-
if (typeof pair !== "object" || pair === null) return true;
|
|
4914
|
-
if (pair.k1 !== void 0 || pair.b !== void 0) return true;
|
|
4915
|
-
}
|
|
4916
|
-
return false;
|
|
4917
|
-
}
|
|
4918
|
-
function ownField(fields, name) {
|
|
4919
|
-
return fields !== void 0 && Object.hasOwn(fields, name) ? fields[name] : void 0;
|
|
4920
|
-
}
|
|
4921
|
-
function mergeBM25Levels(search, index) {
|
|
4922
|
-
if (search === void 0 || !bm25SetsValue(search)) return index;
|
|
4923
|
-
const k1 = search.k1 ?? index?.k1;
|
|
4924
|
-
const b = search.b ?? index?.b;
|
|
4925
|
-
const merged = {
|
|
4926
|
-
...k1 !== void 0 ? { k1 } : {},
|
|
4927
|
-
...b !== void 0 ? { b } : {}
|
|
4928
|
-
};
|
|
4929
|
-
const names = [...Object.keys(search.fields ?? {}), ...Object.keys(index?.fields ?? {})];
|
|
4930
|
-
if (names.length === 0) return merged;
|
|
4931
|
-
const fields = /* @__PURE__ */ Object.create(null);
|
|
4932
|
-
for (const name of names) {
|
|
4933
|
-
const fromSearch = ownField(search.fields, name);
|
|
4934
|
-
const fromIndex = ownField(index?.fields, name);
|
|
4935
|
-
const fieldK1 = fromSearch?.k1 ?? search.k1 ?? fromIndex?.k1;
|
|
4936
|
-
const fieldB = fromSearch?.b ?? search.b ?? fromIndex?.b;
|
|
4937
|
-
fields[name] = {
|
|
4938
|
-
...fieldK1 !== void 0 ? { k1: fieldK1 } : {},
|
|
4939
|
-
...fieldB !== void 0 ? { b: fieldB } : {}
|
|
4940
|
-
};
|
|
4941
|
-
}
|
|
4942
|
-
merged.fields = fields;
|
|
4943
|
-
return merged;
|
|
4944
|
-
}
|
|
4945
|
-
function computeBM25WithIDF(termFrequency, idf, fieldLength, avgFieldLength, k1, b) {
|
|
4946
|
-
if (avgFieldLength === 0) return 0;
|
|
4947
|
-
const numerator = termFrequency * (k1 + 1);
|
|
4948
|
-
const denominator = termFrequency + k1 * (1 - b + b * fieldLength / avgFieldLength);
|
|
4949
|
-
if (denominator === 0) return 0;
|
|
4950
|
-
return idf * (numerator / denominator);
|
|
4951
|
-
}
|
|
4952
|
-
|
|
4953
|
-
// src/core/partition/field-scoring.ts
|
|
4954
|
-
var NO_FIELD_VALUES = new Float64Array(0);
|
|
4955
|
-
function differentPairsOf(searchable, k1s, bs) {
|
|
4956
|
-
const pairs = [];
|
|
4957
|
-
for (let fieldIndex = 0; fieldIndex < searchable.length; fieldIndex++) {
|
|
4958
|
-
if (searchable[fieldIndex] !== 1) continue;
|
|
4959
|
-
let seen = false;
|
|
4960
|
-
for (let at = 0; at < pairs.length && !seen; at += 2) {
|
|
4961
|
-
seen = pairs[at] === k1s[fieldIndex] && pairs[at + 1] === bs[fieldIndex];
|
|
4962
|
-
}
|
|
4963
|
-
if (!seen) pairs.push(k1s[fieldIndex], bs[fieldIndex]);
|
|
4964
|
-
}
|
|
4965
|
-
return pairs;
|
|
4966
|
-
}
|
|
4967
|
-
function loadFieldScoring(state, fields, boost, averageFieldLengths, bm25) {
|
|
4968
|
-
const fieldNames = state.fieldNameTable.names;
|
|
4969
|
-
const fieldCount = fieldNames.length;
|
|
4970
|
-
const k1 = bm25?.k1 ?? DEFAULT_BM25_K1;
|
|
4971
|
-
const b = bm25?.b ?? DEFAULT_BM25_B;
|
|
4972
|
-
const perField = bm25?.fields;
|
|
4973
|
-
const scoring = {
|
|
4974
|
-
searchable: new Uint8Array(fieldCount),
|
|
4975
|
-
boosts: new Float64Array(fieldCount),
|
|
4976
|
-
averageLengths: new Float64Array(fieldCount),
|
|
4977
|
-
lengthColumns: new Array(fieldCount).fill(null),
|
|
4978
|
-
k1s: perField === void 0 ? NO_FIELD_VALUES : new Float64Array(fieldCount),
|
|
4979
|
-
bs: perField === void 0 ? NO_FIELD_VALUES : new Float64Array(fieldCount),
|
|
4980
|
-
boundPairs: [k1, b]
|
|
4981
|
-
};
|
|
4982
|
-
for (let fieldIndex = 0; fieldIndex < fieldCount; fieldIndex++) {
|
|
4983
|
-
const fieldName = fieldNames[fieldIndex];
|
|
4984
|
-
scoring.searchable[fieldIndex] = fields === void 0 || fields.includes(fieldName) ? 1 : 0;
|
|
4985
|
-
scoring.boosts[fieldIndex] = boost?.[fieldName] ?? 1;
|
|
4986
|
-
scoring.averageLengths[fieldIndex] = averageFieldLengths[fieldName] ?? 1;
|
|
4987
|
-
scoring.lengthColumns[fieldIndex] = state.docStore.fieldLengthColumn(fieldName);
|
|
4988
|
-
if (perField !== void 0) {
|
|
4989
|
-
const fieldPair = Object.hasOwn(perField, fieldName) ? perField[fieldName] : void 0;
|
|
4990
|
-
scoring.k1s[fieldIndex] = fieldPair?.k1 ?? k1;
|
|
4991
|
-
scoring.bs[fieldIndex] = fieldPair?.b ?? b;
|
|
4992
|
-
}
|
|
4993
|
-
}
|
|
4994
|
-
if (perField !== void 0) scoring.boundPairs = differentPairsOf(scoring.searchable, scoring.k1s, scoring.bs);
|
|
4995
|
-
return scoring;
|
|
4996
|
-
}
|
|
4997
|
-
function fieldLengthOf(columns, fieldIndex, internalId, averageLength) {
|
|
4998
|
-
const column = fieldIndex < columns.length ? columns[fieldIndex] : null;
|
|
4999
|
-
if (column === null || internalId >= column.length) return averageLength;
|
|
5000
|
-
const stored = column[internalId];
|
|
5001
|
-
return stored > 0 ? stored : averageLength;
|
|
5002
|
-
}
|
|
5003
|
-
function bestSearchable(searchable, values) {
|
|
5004
|
-
let best = 0;
|
|
5005
|
-
for (let index = 0; index < searchable.length; index++) {
|
|
5006
|
-
if (searchable[index] === 1 && values[index] > best) best = values[index];
|
|
5007
|
-
}
|
|
5008
|
-
return best;
|
|
5009
|
-
}
|
|
5010
|
-
function blockEntryBound(fields, maxTermFrequency, idf, minFieldLength, maxAverageLength) {
|
|
5011
|
-
const pairs = fields.boundPairs;
|
|
5012
|
-
let best = 0;
|
|
5013
|
-
for (let at = 0; at < pairs.length; at += 2) {
|
|
5014
|
-
const bound = computeBM25WithIDF(maxTermFrequency, idf, minFieldLength, maxAverageLength, pairs[at], pairs[at + 1]);
|
|
5015
|
-
if (bound > best) best = bound;
|
|
5016
|
-
}
|
|
5017
|
-
return best;
|
|
5018
|
-
}
|
|
5019
|
-
|
|
5020
|
-
// src/core/partition/posting-columns.ts
|
|
5021
|
-
function postingColumns(list) {
|
|
5022
|
-
const deletedDocs = list.deletedDocs;
|
|
5023
|
-
return {
|
|
5024
|
-
docIds: list.docIds,
|
|
5025
|
-
termFrequencies: list.termFrequencies,
|
|
5026
|
-
fieldNameIndices: list.fieldNameIndices,
|
|
5027
|
-
deletedDocs,
|
|
5028
|
-
hasDeleted: deletedDocs.size > 0,
|
|
5029
|
-
count: list.length
|
|
5030
|
-
};
|
|
5031
|
-
}
|
|
5032
|
-
|
|
5033
|
-
// src/core/partition/scoring.ts
|
|
5034
|
-
var EMPTY_COMPONENTS = Object.freeze({});
|
|
5035
|
-
function recordComponents(components, internalId, fieldName, token, termFrequency, fieldLength, idf) {
|
|
5036
|
-
const existing = components.get(internalId);
|
|
5037
|
-
if (existing) {
|
|
5038
|
-
existing.termFrequencies[`${fieldName}:${token}`] = termFrequency;
|
|
5039
|
-
existing.fieldLengths[fieldName] = fieldLength;
|
|
5040
|
-
existing.idf[token] = idf;
|
|
5041
|
-
return;
|
|
5042
|
-
}
|
|
5043
|
-
components.set(internalId, {
|
|
5044
|
-
termFrequencies: { [`${fieldName}:${token}`]: termFrequency },
|
|
5045
|
-
fieldLengths: { [fieldName]: fieldLength },
|
|
5046
|
-
idf: { [token]: idf }
|
|
5047
|
-
});
|
|
5048
|
-
}
|
|
5049
|
-
function mergeGroupComponents(components, internalId, contribution) {
|
|
5050
|
-
const existing = components.get(internalId);
|
|
5051
|
-
if (existing) {
|
|
5052
|
-
Object.assign(existing.termFrequencies, contribution.termFrequencies);
|
|
5053
|
-
Object.assign(existing.fieldLengths, contribution.fieldLengths);
|
|
5054
|
-
existing.idf[contribution.token] = contribution.idf;
|
|
5055
|
-
return;
|
|
5056
|
-
}
|
|
5057
|
-
components.set(internalId, {
|
|
5058
|
-
termFrequencies: contribution.termFrequencies,
|
|
5059
|
-
fieldLengths: contribution.fieldLengths,
|
|
5060
|
-
idf: { [contribution.token]: contribution.idf }
|
|
5061
|
-
});
|
|
5062
|
-
}
|
|
5063
|
-
|
|
5064
|
-
// src/core/partition/group-scoring.ts
|
|
5065
|
-
function partialFieldMarks(fieldNames, partialFields) {
|
|
5066
|
-
const marks = new Uint8Array(fieldNames.length);
|
|
5067
|
-
if (partialFields === void 0 || partialFields.length === 0) return marks;
|
|
5068
|
-
for (let fieldIndex = 0; fieldIndex < fieldNames.length; fieldIndex++) {
|
|
5069
|
-
if (partialFields.includes(fieldNames[fieldIndex])) marks[fieldIndex] = 1;
|
|
5070
|
-
}
|
|
5071
|
-
return marks;
|
|
5072
|
-
}
|
|
5073
|
-
function termGroupOf(groups, token) {
|
|
5074
|
-
if (groups === void 0) return void 0;
|
|
5075
|
-
for (const group of groups) {
|
|
5076
|
-
if (group.token === token) return group;
|
|
5077
|
-
}
|
|
5078
|
-
return void 0;
|
|
5079
|
-
}
|
|
5080
|
-
function typoMatchesFor(index, token, group, exact, tolerance, prefixLength) {
|
|
5081
|
-
if (group !== void 0) {
|
|
5082
|
-
if (!group.typoMatches || exact || tolerance === 0) return [];
|
|
5083
|
-
return index.fuzzyLookup(token, tolerance, prefixLength).filter((match) => match.token !== token && group.synonyms?.has(match.token) !== true);
|
|
5084
|
-
}
|
|
5085
|
-
if (!exact) return index.fuzzyLookup(token, tolerance, prefixLength);
|
|
5086
|
-
const postingList = index.lookup(token);
|
|
5087
|
-
return postingList ? [{ token, postingList }] : [];
|
|
5088
|
-
}
|
|
5089
|
-
function resolveGroupMatches(context, group) {
|
|
5090
|
-
const frequencyOf = (token) => context.globalFrequency(token) ?? context.index.documentFrequency(token);
|
|
5091
|
-
const lookup = (token) => context.index.lookup(token);
|
|
5092
|
-
const synonyms = group.synonyms;
|
|
5093
|
-
let groupDocumentFrequency = synonyms?.documentFrequency(frequencyOf) ?? 0;
|
|
5094
|
-
const found = [];
|
|
5095
|
-
for (const member of group.members) {
|
|
5096
|
-
const documents = frequencyOf(member.token);
|
|
5097
|
-
if (documents > groupDocumentFrequency) groupDocumentFrequency = documents;
|
|
5098
|
-
const postingList = synonyms !== void 0 && member.token === group.token ? synonyms.postings(lookup, member.token) : lookup(member.token);
|
|
5099
|
-
if (postingList === void 0) continue;
|
|
5100
|
-
found.push({ token: member.token, factor: member.factor, partialFactor: member.partialFactor, postingList });
|
|
5101
|
-
}
|
|
5102
|
-
if (found.length === 0) return [];
|
|
5103
|
-
const idf = computeIDF(groupDocumentFrequency, context.totalDocs);
|
|
5104
|
-
return found.map((entry) => ({ ...entry, idf }));
|
|
5105
|
-
}
|
|
5106
|
-
function groupPostingCount(matches) {
|
|
5107
|
-
let total = 0;
|
|
5108
|
-
for (const match of matches) total += match.postingList.length;
|
|
5109
|
-
return total;
|
|
5110
|
-
}
|
|
5111
|
-
function computeGroupContributions(context, matches, collect) {
|
|
5112
|
-
const { fields, fieldNames, filterBitset, partialMarks } = context;
|
|
5113
|
-
const scoresAreZero = context.totalDocs === 0;
|
|
5114
|
-
const onePair = fields.boundPairs.length === 2;
|
|
5115
|
-
const best = /* @__PURE__ */ new Map();
|
|
5116
|
-
for (const match of matches) {
|
|
5117
|
-
const perTerm = /* @__PURE__ */ new Map();
|
|
5118
|
-
const { docIds, termFrequencies, fieldNameIndices, deletedDocs, hasDeleted, count } = postingColumns(
|
|
5119
|
-
match.postingList
|
|
5120
|
-
);
|
|
5121
|
-
for (let pi = 0; pi < count; pi++) {
|
|
5122
|
-
const internalId = docIds[pi];
|
|
5123
|
-
if (hasDeleted && deletedDocs.has(internalId)) continue;
|
|
5124
|
-
if (filterBitset && !bitsetHas(filterBitset, internalId)) continue;
|
|
5125
|
-
const fieldIndex = fieldNameIndices[pi];
|
|
5126
|
-
if (fields.searchable[fieldIndex] === 0) continue;
|
|
5127
|
-
const factor = partialMarks[fieldIndex] === 1 ? match.partialFactor : match.factor;
|
|
5128
|
-
if (factor === 0) continue;
|
|
5129
|
-
const fieldName = fieldNames[fieldIndex];
|
|
5130
|
-
const termFrequency = termFrequencies[pi];
|
|
5131
|
-
const fieldBoost = fields.boosts[fieldIndex];
|
|
5132
|
-
const avgLen = fields.averageLengths[fieldIndex];
|
|
5133
|
-
const actualFieldLength = fieldLengthOf(fields.lengthColumns, fieldIndex, internalId, avgLen);
|
|
5134
|
-
const termScore = (scoresAreZero ? 0 : computeBM25WithIDF(
|
|
5135
|
-
termFrequency,
|
|
5136
|
-
match.idf,
|
|
5137
|
-
actualFieldLength,
|
|
5138
|
-
avgLen,
|
|
5139
|
-
onePair ? fields.boundPairs[0] : fields.k1s[fieldIndex],
|
|
5140
|
-
onePair ? fields.boundPairs[1] : fields.bs[fieldIndex]
|
|
5141
|
-
)) * fieldBoost * factor;
|
|
5142
|
-
const existing = perTerm.get(internalId);
|
|
5143
|
-
if (existing) {
|
|
5144
|
-
existing.score += termScore;
|
|
5145
|
-
if (collect) {
|
|
5146
|
-
existing.termFrequencies[`${fieldName}:${match.token}`] = termFrequency;
|
|
5147
|
-
existing.fieldLengths[fieldName] = actualFieldLength;
|
|
5148
|
-
}
|
|
5149
|
-
} else if (collect) {
|
|
5150
|
-
perTerm.set(internalId, {
|
|
5151
|
-
score: termScore,
|
|
5152
|
-
token: match.token,
|
|
5153
|
-
idf: match.idf,
|
|
5154
|
-
termFrequencies: { [`${fieldName}:${match.token}`]: termFrequency },
|
|
5155
|
-
fieldLengths: { [fieldName]: actualFieldLength }
|
|
5156
|
-
});
|
|
5157
|
-
} else {
|
|
5158
|
-
perTerm.set(internalId, {
|
|
5159
|
-
score: termScore,
|
|
5160
|
-
token: match.token,
|
|
5161
|
-
idf: match.idf,
|
|
5162
|
-
termFrequencies: EMPTY_COMPONENTS,
|
|
5163
|
-
fieldLengths: EMPTY_COMPONENTS
|
|
5164
|
-
});
|
|
5165
|
-
}
|
|
5166
|
-
}
|
|
5167
|
-
for (const [internalId, contribution] of perTerm) {
|
|
5168
|
-
const current = best.get(internalId);
|
|
5169
|
-
if (!current || contribution.score > current.score) {
|
|
5170
|
-
best.set(internalId, contribution);
|
|
5171
|
-
}
|
|
5172
|
-
}
|
|
5173
|
-
}
|
|
5174
|
-
return best;
|
|
5175
|
-
}
|
|
5176
|
-
|
|
5177
4491
|
// src/core/partition/matches.ts
|
|
5178
4492
|
function markPostingList(matched, list, markedFields, filterBitset) {
|
|
5179
4493
|
const { docIds, fieldNameIndices, deletedDocs, hasDeleted, count } = postingColumns(list);
|
|
@@ -5399,7 +4713,7 @@ function mergeFieldIndexes(target, source, idMapping) {
|
|
|
5399
4713
|
for (const [fieldPath, index] of source.geoIndexes) {
|
|
5400
4714
|
let targetIndex = target.geoIndexes.get(fieldPath);
|
|
5401
4715
|
if (targetIndex === void 0) {
|
|
5402
|
-
targetIndex =
|
|
4716
|
+
targetIndex = createLoadedGeoIndex();
|
|
5403
4717
|
target.geoIndexes.set(fieldPath, targetIndex);
|
|
5404
4718
|
}
|
|
5405
4719
|
for (const entry of index.serialize()) {
|
|
@@ -5427,895 +4741,6 @@ function mergeSegmentState(target, source) {
|
|
|
5427
4741
|
target.scoreBuffer = null;
|
|
5428
4742
|
}
|
|
5429
4743
|
|
|
5430
|
-
// src/core/partition/block-bounds.ts
|
|
5431
|
-
var ABSENT_FIELD_LENGTH_BOUND = 0;
|
|
5432
|
-
var boundsByList = /* @__PURE__ */ new WeakMap();
|
|
5433
|
-
function fieldLengthBound(columns, fieldIndex, internalId) {
|
|
5434
|
-
const column = fieldIndex < columns.length ? columns[fieldIndex] : null;
|
|
5435
|
-
if (column === null || internalId >= column.length) return ABSENT_FIELD_LENGTH_BOUND;
|
|
5436
|
-
const stored = column[internalId];
|
|
5437
|
-
return stored > 0 ? stored : ABSENT_FIELD_LENGTH_BOUND;
|
|
5438
|
-
}
|
|
5439
|
-
function entriesCovered(bounds) {
|
|
5440
|
-
return bounds.blockCount === 0 ? 0 : bounds.entryEnd[bounds.blockCount - 1];
|
|
5441
|
-
}
|
|
5442
|
-
function scanPostingBlocks(list, columns, previous, keepBlocks) {
|
|
5443
|
-
const { docIds, termFrequencies, fieldNameIndices, length } = list;
|
|
5444
|
-
const startEntry = previous !== null && keepBlocks > 0 ? previous.entryEnd[keepBlocks - 1] : 0;
|
|
5445
|
-
const capacity = keepBlocks + Math.ceil((length - startEntry) / TARGET_BLOCK_ENTRIES) + 1;
|
|
5446
|
-
const entryEnd = new Int32Array(capacity);
|
|
5447
|
-
const maxTermFrequency = new Int32Array(capacity);
|
|
5448
|
-
const minFieldLength = new Float64Array(capacity);
|
|
5449
|
-
const maxEntriesPerDocument = new Int32Array(capacity);
|
|
5450
|
-
const documentCount = new Int32Array(capacity);
|
|
5451
|
-
if (previous !== null && keepBlocks > 0) {
|
|
5452
|
-
entryEnd.set(previous.entryEnd.subarray(0, keepBlocks));
|
|
5453
|
-
maxTermFrequency.set(previous.maxTermFrequency.subarray(0, keepBlocks));
|
|
5454
|
-
minFieldLength.set(previous.minFieldLength.subarray(0, keepBlocks));
|
|
5455
|
-
maxEntriesPerDocument.set(previous.maxEntriesPerDocument.subarray(0, keepBlocks));
|
|
5456
|
-
documentCount.set(previous.documentCount.subarray(0, keepBlocks));
|
|
5457
|
-
}
|
|
5458
|
-
const deleted = list.deletedDocs;
|
|
5459
|
-
const hasDeleted = deleted.size > 0;
|
|
5460
|
-
let blockIndex = keepBlocks;
|
|
5461
|
-
let blockStart = startEntry;
|
|
5462
|
-
let blockMaxTf = 0;
|
|
5463
|
-
let blockMinLen = Number.POSITIVE_INFINITY;
|
|
5464
|
-
let blockMaxRun = 0;
|
|
5465
|
-
let blockDocs = 0;
|
|
5466
|
-
let entry = startEntry;
|
|
5467
|
-
while (entry < length) {
|
|
5468
|
-
const docId = docIds[entry];
|
|
5469
|
-
const tombstoned = hasDeleted && deleted.has(docId);
|
|
5470
|
-
let run = 0;
|
|
5471
|
-
while (entry + run < length && docIds[entry + run] === docId) {
|
|
5472
|
-
if (!tombstoned) {
|
|
5473
|
-
const position = entry + run;
|
|
5474
|
-
const termFrequency = termFrequencies[position];
|
|
5475
|
-
if (termFrequency > blockMaxTf) blockMaxTf = termFrequency;
|
|
5476
|
-
const fieldLength = fieldLengthBound(columns, fieldNameIndices[position], docId);
|
|
5477
|
-
if (fieldLength < blockMinLen) blockMinLen = fieldLength;
|
|
5478
|
-
}
|
|
5479
|
-
run++;
|
|
5480
|
-
}
|
|
5481
|
-
if (!tombstoned) {
|
|
5482
|
-
if (run > blockMaxRun) blockMaxRun = run;
|
|
5483
|
-
blockDocs++;
|
|
5484
|
-
}
|
|
5485
|
-
entry += run;
|
|
5486
|
-
if (entry - blockStart >= TARGET_BLOCK_ENTRIES || entry === length) {
|
|
5487
|
-
entryEnd[blockIndex] = entry;
|
|
5488
|
-
maxTermFrequency[blockIndex] = blockMaxTf;
|
|
5489
|
-
minFieldLength[blockIndex] = blockMinLen === Number.POSITIVE_INFINITY ? ABSENT_FIELD_LENGTH_BOUND : blockMinLen;
|
|
5490
|
-
maxEntriesPerDocument[blockIndex] = blockMaxRun;
|
|
5491
|
-
documentCount[blockIndex] = blockDocs;
|
|
5492
|
-
blockIndex++;
|
|
5493
|
-
blockStart = entry;
|
|
5494
|
-
blockMaxTf = 0;
|
|
5495
|
-
blockMinLen = Number.POSITIVE_INFINITY;
|
|
5496
|
-
blockMaxRun = 0;
|
|
5497
|
-
blockDocs = 0;
|
|
5498
|
-
}
|
|
5499
|
-
}
|
|
5500
|
-
return {
|
|
5501
|
-
structureRevision: list.structureRevision,
|
|
5502
|
-
blockCount: blockIndex,
|
|
5503
|
-
entryEnd,
|
|
5504
|
-
maxTermFrequency,
|
|
5505
|
-
minFieldLength,
|
|
5506
|
-
maxEntriesPerDocument,
|
|
5507
|
-
documentCount
|
|
5508
|
-
};
|
|
5509
|
-
}
|
|
5510
|
-
function blockBoundsFor(list, columns) {
|
|
5511
|
-
const existing = boundsByList.get(list);
|
|
5512
|
-
if (existing !== void 0 && existing.structureRevision === list.structureRevision) {
|
|
5513
|
-
const covered = entriesCovered(existing);
|
|
5514
|
-
if (covered === list.length) return existing;
|
|
5515
|
-
if (list.ordered && covered < list.length) {
|
|
5516
|
-
const extended = scanPostingBlocks(list, columns, existing, Math.max(0, existing.blockCount - 1));
|
|
5517
|
-
boundsByList.set(list, extended);
|
|
5518
|
-
return extended;
|
|
5519
|
-
}
|
|
5520
|
-
}
|
|
5521
|
-
const stored = list.storedBlockBounds?.() ?? null;
|
|
5522
|
-
const built = stored === null ? scanPostingBlocks(list, columns, null, 0) : { ...stored, structureRevision: list.structureRevision };
|
|
5523
|
-
boundsByList.set(list, built);
|
|
5524
|
-
return built;
|
|
5525
|
-
}
|
|
5526
|
-
|
|
5527
|
-
// src/core/partition/top-k-heap.ts
|
|
5528
|
-
function candidateWorse(a, b) {
|
|
5529
|
-
if (a.score !== b.score) return a.score < b.score;
|
|
5530
|
-
return compareCodePoints(a.externalId, b.externalId) > 0;
|
|
5531
|
-
}
|
|
5532
|
-
function buildMinHeap(heap) {
|
|
5533
|
-
for (let index = (heap.length >> 1) - 1; index >= 0; index--) {
|
|
5534
|
-
siftDown(heap, index);
|
|
5535
|
-
}
|
|
5536
|
-
}
|
|
5537
|
-
function siftDown(heap, start) {
|
|
5538
|
-
const len = heap.length;
|
|
5539
|
-
let current = start;
|
|
5540
|
-
for (; ; ) {
|
|
5541
|
-
let worst = current;
|
|
5542
|
-
const left = 2 * current + 1;
|
|
5543
|
-
const right = 2 * current + 2;
|
|
5544
|
-
if (left < len && candidateWorse(heap[left], heap[worst])) worst = left;
|
|
5545
|
-
if (right < len && candidateWorse(heap[right], heap[worst])) worst = right;
|
|
5546
|
-
if (worst === current) break;
|
|
5547
|
-
const held = heap[current];
|
|
5548
|
-
heap[current] = heap[worst];
|
|
5549
|
-
heap[worst] = held;
|
|
5550
|
-
current = worst;
|
|
5551
|
-
}
|
|
5552
|
-
}
|
|
5553
|
-
function sortSelection(heap) {
|
|
5554
|
-
heap.sort((a, b) => b.score - a.score || compareCodePoints(a.externalId, b.externalId));
|
|
5555
|
-
}
|
|
5556
|
-
|
|
5557
|
-
// src/core/partition/score-buffer.ts
|
|
5558
|
-
var MAX_GENERATION = 2147483647;
|
|
5559
|
-
function createScoreBuffer(capacity) {
|
|
5560
|
-
return {
|
|
5561
|
-
scores: new Float64Array(capacity),
|
|
5562
|
-
stamps: new Int32Array(capacity),
|
|
5563
|
-
touched: new Int32Array(Math.max(1, Math.min(capacity, SCORE_BUFFER_INITIAL_TOUCHED_CAPACITY))),
|
|
5564
|
-
touchedCount: 0,
|
|
5565
|
-
generation: 0
|
|
5566
|
-
};
|
|
5567
|
-
}
|
|
5568
|
-
function beginScoring(buffer, capacity) {
|
|
5569
|
-
if (buffer.scores.length < capacity) {
|
|
5570
|
-
buffer.scores = new Float64Array(capacity);
|
|
5571
|
-
buffer.stamps = new Int32Array(capacity);
|
|
5572
|
-
buffer.generation = 0;
|
|
5573
|
-
}
|
|
5574
|
-
if (buffer.generation >= MAX_GENERATION) {
|
|
5575
|
-
buffer.stamps.fill(0);
|
|
5576
|
-
buffer.generation = 0;
|
|
5577
|
-
}
|
|
5578
|
-
buffer.generation++;
|
|
5579
|
-
buffer.touchedCount = 0;
|
|
5580
|
-
}
|
|
5581
|
-
function appendTouched(buffer, internalId) {
|
|
5582
|
-
if (buffer.touchedCount === buffer.touched.length) {
|
|
5583
|
-
const grown = new Int32Array(buffer.touched.length * 2);
|
|
5584
|
-
grown.set(buffer.touched);
|
|
5585
|
-
buffer.touched = grown;
|
|
5586
|
-
}
|
|
5587
|
-
buffer.touched[buffer.touchedCount] = internalId;
|
|
5588
|
-
buffer.touchedCount++;
|
|
5589
|
-
}
|
|
5590
|
-
function addScore(buffer, internalId, termScore) {
|
|
5591
|
-
if (buffer.stamps[internalId] === buffer.generation) {
|
|
5592
|
-
buffer.scores[internalId] += termScore;
|
|
5593
|
-
return;
|
|
5594
|
-
}
|
|
5595
|
-
buffer.stamps[internalId] = buffer.generation;
|
|
5596
|
-
buffer.scores[internalId] = termScore;
|
|
5597
|
-
appendTouched(buffer, internalId);
|
|
5598
|
-
}
|
|
5599
|
-
function markCounted(buffer, internalId) {
|
|
5600
|
-
const countedStamp = -buffer.generation;
|
|
5601
|
-
const stamp = buffer.stamps[internalId];
|
|
5602
|
-
if (stamp === buffer.generation || stamp === countedStamp) return false;
|
|
5603
|
-
buffer.stamps[internalId] = countedStamp;
|
|
5604
|
-
return true;
|
|
5605
|
-
}
|
|
5606
|
-
function kthBestScore(buffer, selection, resolver) {
|
|
5607
|
-
const wanted = selection.length;
|
|
5608
|
-
const { touched, touchedCount, scores } = buffer;
|
|
5609
|
-
let size = 0;
|
|
5610
|
-
for (let index = 0; index < touchedCount; index++) {
|
|
5611
|
-
const internalId = touched[index];
|
|
5612
|
-
const score = scores[internalId];
|
|
5613
|
-
if (size === wanted && score <= selection[0]) continue;
|
|
5614
|
-
if (!resolver.isLive(internalId)) continue;
|
|
5615
|
-
let at = 0;
|
|
5616
|
-
if (size < wanted) {
|
|
5617
|
-
at = size++;
|
|
5618
|
-
while (at > 0) {
|
|
5619
|
-
const parent = at - 1 >> 1;
|
|
5620
|
-
if (selection[parent] <= score) break;
|
|
5621
|
-
selection[at] = selection[parent];
|
|
5622
|
-
at = parent;
|
|
5623
|
-
}
|
|
5624
|
-
} else {
|
|
5625
|
-
for (; ; ) {
|
|
5626
|
-
const left = 2 * at + 1;
|
|
5627
|
-
if (left >= size) break;
|
|
5628
|
-
const right = left + 1;
|
|
5629
|
-
const child = right < size && selection[right] < selection[left] ? right : left;
|
|
5630
|
-
if (selection[child] >= score) break;
|
|
5631
|
-
selection[at] = selection[child];
|
|
5632
|
-
at = child;
|
|
5633
|
-
}
|
|
5634
|
-
}
|
|
5635
|
-
selection[at] = score;
|
|
5636
|
-
}
|
|
5637
|
-
return wanted > 0 && size === wanted ? selection[0] : Number.NEGATIVE_INFINITY;
|
|
5638
|
-
}
|
|
5639
|
-
function hasScore(buffer, internalId) {
|
|
5640
|
-
return buffer.stamps[internalId] === buffer.generation;
|
|
5641
|
-
}
|
|
5642
|
-
function topKFromBuffer(buffer, k, resolver, components) {
|
|
5643
|
-
const wanted = Number.isFinite(k) ? Math.max(0, Math.floor(k)) : 0;
|
|
5644
|
-
if (wanted <= 0) return [];
|
|
5645
|
-
const heap = [];
|
|
5646
|
-
const { touched, touchedCount, scores } = buffer;
|
|
5647
|
-
let full = false;
|
|
5648
|
-
let threshold = 0;
|
|
5649
|
-
for (let index = 0; index < touchedCount; index++) {
|
|
5650
|
-
const internalId = touched[index];
|
|
5651
|
-
const score = scores[internalId];
|
|
5652
|
-
if (full && score < threshold) continue;
|
|
5653
|
-
const externalId = resolver.toExternal(internalId);
|
|
5654
|
-
if (externalId === void 0) continue;
|
|
5655
|
-
const candidate = { internalId, externalId, score };
|
|
5656
|
-
if (!full) {
|
|
5657
|
-
heap.push(candidate);
|
|
5658
|
-
if (heap.length === wanted) {
|
|
5659
|
-
buildMinHeap(heap);
|
|
5660
|
-
full = true;
|
|
5661
|
-
threshold = heap[0].score;
|
|
5662
|
-
}
|
|
5663
|
-
continue;
|
|
5664
|
-
}
|
|
5665
|
-
if (candidateWorse(heap[0], candidate)) {
|
|
5666
|
-
heap[0] = candidate;
|
|
5667
|
-
siftDown(heap, 0);
|
|
5668
|
-
threshold = heap[0].score;
|
|
5669
|
-
}
|
|
5670
|
-
}
|
|
5671
|
-
sortSelection(heap);
|
|
5672
|
-
const result = new Array(heap.length);
|
|
5673
|
-
for (let index = 0; index < heap.length; index++) {
|
|
5674
|
-
const entry = heap[index];
|
|
5675
|
-
const record = components?.get(entry.internalId);
|
|
5676
|
-
result[index] = {
|
|
5677
|
-
docId: entry.externalId,
|
|
5678
|
-
score: entry.score,
|
|
5679
|
-
termFrequencies: record?.termFrequencies ?? EMPTY_COMPONENTS,
|
|
5680
|
-
fieldLengths: record?.fieldLengths ?? EMPTY_COMPONENTS,
|
|
5681
|
-
idf: record?.idf ?? EMPTY_COMPONENTS
|
|
5682
|
-
};
|
|
5683
|
-
}
|
|
5684
|
-
return result;
|
|
5685
|
-
}
|
|
5686
|
-
|
|
5687
|
-
// src/core/partition/multi-term-topk.ts
|
|
5688
|
-
function prunableMultiTermLists(params, index) {
|
|
5689
|
-
if (params.queryTokens.length < 2) return null;
|
|
5690
|
-
if (params.termGroups !== void 0 && params.termGroups.length > 0) return null;
|
|
5691
|
-
if (params.exact !== true && (params.tolerance ?? 0) !== 0) return null;
|
|
5692
|
-
if (params.termMatch !== void 0 && params.termMatch !== "any") return null;
|
|
5693
|
-
if (params.collectComponents !== false) return null;
|
|
5694
|
-
if (params.collectMatchedSet !== void 0) return null;
|
|
5695
|
-
if (params.maxResults === void 0) return null;
|
|
5696
|
-
if (params.filterBitset !== void 0) return null;
|
|
5697
|
-
if (!bm25PruningSound(params.bm25Params)) return null;
|
|
5698
|
-
const terms = [];
|
|
5699
|
-
for (const queryToken of params.queryTokens) {
|
|
5700
|
-
const list = index.lookup(queryToken.token);
|
|
5701
|
-
if (list === void 0) continue;
|
|
5702
|
-
if (!list.ordered) return null;
|
|
5703
|
-
terms.push({ token: queryToken.token, list });
|
|
5704
|
-
}
|
|
5705
|
-
return terms;
|
|
5706
|
-
}
|
|
5707
|
-
function boostsKeepScoresNonNegative(fields) {
|
|
5708
|
-
for (let fieldIndex = 0; fieldIndex < fields.searchable.length; fieldIndex++) {
|
|
5709
|
-
if (fields.searchable[fieldIndex] !== 1) continue;
|
|
5710
|
-
const boost = fields.boosts[fieldIndex];
|
|
5711
|
-
if (!Number.isFinite(boost) || boost < 0) return false;
|
|
5712
|
-
}
|
|
5713
|
-
return true;
|
|
5714
|
-
}
|
|
5715
|
-
function samePairUpperBound(scan, list, maxBoost, maxAverageLength) {
|
|
5716
|
-
if (scan.scoresAreZero) return 0;
|
|
5717
|
-
const bounds = blockBoundsFor(list, scan.fields.lengthColumns);
|
|
5718
|
-
let best = 0;
|
|
5719
|
-
for (let block = 0; block < bounds.blockCount; block++) {
|
|
5720
|
-
const bestEntry = computeBM25WithIDF(
|
|
5721
|
-
bounds.maxTermFrequency[block],
|
|
5722
|
-
scan.idf,
|
|
5723
|
-
bounds.minFieldLength[block],
|
|
5724
|
-
maxAverageLength,
|
|
5725
|
-
scan.k1,
|
|
5726
|
-
scan.b
|
|
5727
|
-
);
|
|
5728
|
-
const blockBound = bestEntry * maxBoost * bounds.maxEntriesPerDocument[block];
|
|
5729
|
-
if (blockBound > best) best = blockBound;
|
|
5730
|
-
}
|
|
5731
|
-
return best;
|
|
5732
|
-
}
|
|
5733
|
-
function fieldPairUpperBound(scan, list, maxBoost, maxAverageLength) {
|
|
5734
|
-
if (scan.scoresAreZero) return 0;
|
|
5735
|
-
const bounds = blockBoundsFor(list, scan.fields.lengthColumns);
|
|
5736
|
-
let best = 0;
|
|
5737
|
-
for (let block = 0; block < bounds.blockCount; block++) {
|
|
5738
|
-
const bestEntry = blockEntryBound(
|
|
5739
|
-
scan.fields,
|
|
5740
|
-
bounds.maxTermFrequency[block],
|
|
5741
|
-
scan.idf,
|
|
5742
|
-
bounds.minFieldLength[block],
|
|
5743
|
-
maxAverageLength
|
|
5744
|
-
);
|
|
5745
|
-
const blockBound = bestEntry * maxBoost * bounds.maxEntriesPerDocument[block];
|
|
5746
|
-
if (blockBound > best) best = blockBound;
|
|
5747
|
-
}
|
|
5748
|
-
return best;
|
|
5749
|
-
}
|
|
5750
|
-
function samePairEntryScore(scan, entry, internalId) {
|
|
5751
|
-
const { fields, columns } = scan;
|
|
5752
|
-
const fieldIndex = columns.fieldNameIndices[entry];
|
|
5753
|
-
const averageLength = fields.averageLengths[fieldIndex];
|
|
5754
|
-
const fieldLength = fieldLengthOf(fields.lengthColumns, fieldIndex, internalId, averageLength);
|
|
5755
|
-
const bm25 = scan.scoresAreZero ? 0 : computeBM25WithIDF(columns.termFrequencies[entry], scan.idf, fieldLength, averageLength, scan.k1, scan.b);
|
|
5756
|
-
return bm25 * fields.boosts[fieldIndex];
|
|
5757
|
-
}
|
|
5758
|
-
function fieldPairEntryScore(scan, entry, internalId) {
|
|
5759
|
-
const { fields, columns } = scan;
|
|
5760
|
-
const fieldIndex = columns.fieldNameIndices[entry];
|
|
5761
|
-
const averageLength = fields.averageLengths[fieldIndex];
|
|
5762
|
-
const fieldLength = fieldLengthOf(fields.lengthColumns, fieldIndex, internalId, averageLength);
|
|
5763
|
-
const bm25 = scan.scoresAreZero ? 0 : computeBM25WithIDF(
|
|
5764
|
-
columns.termFrequencies[entry],
|
|
5765
|
-
scan.idf,
|
|
5766
|
-
fieldLength,
|
|
5767
|
-
averageLength,
|
|
5768
|
-
fields.k1s[fieldIndex],
|
|
5769
|
-
fields.bs[fieldIndex]
|
|
5770
|
-
);
|
|
5771
|
-
return bm25 * fields.boosts[fieldIndex];
|
|
5772
|
-
}
|
|
5773
|
-
function samePairScoreEveryDocument(scan, buffer) {
|
|
5774
|
-
const { docIds, fieldNameIndices, deletedDocs, hasDeleted, count } = scan.columns;
|
|
5775
|
-
const searchable = scan.fields.searchable;
|
|
5776
|
-
for (let entry = 0; entry < count; entry++) {
|
|
5777
|
-
const internalId = docIds[entry];
|
|
5778
|
-
if (hasDeleted && deletedDocs.has(internalId)) continue;
|
|
5779
|
-
if (searchable[fieldNameIndices[entry]] !== 1) continue;
|
|
5780
|
-
addScore(buffer, internalId, samePairEntryScore(scan, entry, internalId));
|
|
5781
|
-
}
|
|
5782
|
-
}
|
|
5783
|
-
function fieldPairScoreEveryDocument(scan, buffer) {
|
|
5784
|
-
const { docIds, fieldNameIndices, deletedDocs, hasDeleted, count } = scan.columns;
|
|
5785
|
-
const searchable = scan.fields.searchable;
|
|
5786
|
-
for (let entry = 0; entry < count; entry++) {
|
|
5787
|
-
const internalId = docIds[entry];
|
|
5788
|
-
if (hasDeleted && deletedDocs.has(internalId)) continue;
|
|
5789
|
-
if (searchable[fieldNameIndices[entry]] !== 1) continue;
|
|
5790
|
-
addScore(buffer, internalId, fieldPairEntryScore(scan, entry, internalId));
|
|
5791
|
-
}
|
|
5792
|
-
}
|
|
5793
|
-
function samePairScoreKnownDocuments(scan, buffer) {
|
|
5794
|
-
const { docIds, fieldNameIndices, deletedDocs, hasDeleted, count } = scan.columns;
|
|
5795
|
-
const searchable = scan.fields.searchable;
|
|
5796
|
-
let counted = 0;
|
|
5797
|
-
for (let entry = 0; entry < count; entry++) {
|
|
5798
|
-
const internalId = docIds[entry];
|
|
5799
|
-
if (hasDeleted && deletedDocs.has(internalId)) continue;
|
|
5800
|
-
if (searchable[fieldNameIndices[entry]] !== 1) continue;
|
|
5801
|
-
if (hasScore(buffer, internalId)) addScore(buffer, internalId, samePairEntryScore(scan, entry, internalId));
|
|
5802
|
-
else if (markCounted(buffer, internalId)) counted++;
|
|
5803
|
-
}
|
|
5804
|
-
return counted;
|
|
5805
|
-
}
|
|
5806
|
-
function fieldPairScoreKnownDocuments(scan, buffer) {
|
|
5807
|
-
const { docIds, fieldNameIndices, deletedDocs, hasDeleted, count } = scan.columns;
|
|
5808
|
-
const searchable = scan.fields.searchable;
|
|
5809
|
-
let counted = 0;
|
|
5810
|
-
for (let entry = 0; entry < count; entry++) {
|
|
5811
|
-
const internalId = docIds[entry];
|
|
5812
|
-
if (hasDeleted && deletedDocs.has(internalId)) continue;
|
|
5813
|
-
if (searchable[fieldNameIndices[entry]] !== 1) continue;
|
|
5814
|
-
if (hasScore(buffer, internalId)) addScore(buffer, internalId, fieldPairEntryScore(scan, entry, internalId));
|
|
5815
|
-
else if (markCounted(buffer, internalId)) counted++;
|
|
5816
|
-
}
|
|
5817
|
-
return counted;
|
|
5818
|
-
}
|
|
5819
|
-
function firstEntryOf(docIds, count, internalId) {
|
|
5820
|
-
let low = 0;
|
|
5821
|
-
let high = count;
|
|
5822
|
-
while (low < high) {
|
|
5823
|
-
const middle = low + high >>> 1;
|
|
5824
|
-
if (docIds[middle] < internalId) low = middle + 1;
|
|
5825
|
-
else high = middle;
|
|
5826
|
-
}
|
|
5827
|
-
return low;
|
|
5828
|
-
}
|
|
5829
|
-
function samePairQueryOrderScore(scans, internalId) {
|
|
5830
|
-
let score = 0;
|
|
5831
|
-
for (const scan of scans) {
|
|
5832
|
-
const { docIds, deletedDocs, hasDeleted, count } = scan.columns;
|
|
5833
|
-
if (hasDeleted && deletedDocs.has(internalId)) continue;
|
|
5834
|
-
for (let entry = firstEntryOf(docIds, count, internalId); entry < count && docIds[entry] === internalId; entry++) {
|
|
5835
|
-
if (scan.fields.searchable[scan.columns.fieldNameIndices[entry]] !== 1) continue;
|
|
5836
|
-
score += samePairEntryScore(scan, entry, internalId);
|
|
5837
|
-
}
|
|
5838
|
-
}
|
|
5839
|
-
return score;
|
|
5840
|
-
}
|
|
5841
|
-
function fieldPairQueryOrderScore(scans, internalId) {
|
|
5842
|
-
let score = 0;
|
|
5843
|
-
for (const scan of scans) {
|
|
5844
|
-
const { docIds, deletedDocs, hasDeleted, count } = scan.columns;
|
|
5845
|
-
if (hasDeleted && deletedDocs.has(internalId)) continue;
|
|
5846
|
-
for (let entry = firstEntryOf(docIds, count, internalId); entry < count && docIds[entry] === internalId; entry++) {
|
|
5847
|
-
if (scan.fields.searchable[scan.columns.fieldNameIndices[entry]] !== 1) continue;
|
|
5848
|
-
score += fieldPairEntryScore(scan, entry, internalId);
|
|
5849
|
-
}
|
|
5850
|
-
}
|
|
5851
|
-
return score;
|
|
5852
|
-
}
|
|
5853
|
-
var SAME_PAIR_SCORER = {
|
|
5854
|
-
upperBound: samePairUpperBound,
|
|
5855
|
-
scoreEveryDocument: samePairScoreEveryDocument,
|
|
5856
|
-
scoreKnownDocumentsAndCountTheRest: samePairScoreKnownDocuments,
|
|
5857
|
-
queryOrderScore: samePairQueryOrderScore
|
|
5858
|
-
};
|
|
5859
|
-
var FIELD_PAIR_SCORER = {
|
|
5860
|
-
upperBound: fieldPairUpperBound,
|
|
5861
|
-
scoreEveryDocument: fieldPairScoreEveryDocument,
|
|
5862
|
-
scoreKnownDocumentsAndCountTheRest: fieldPairScoreKnownDocuments,
|
|
5863
|
-
queryOrderScore: fieldPairQueryOrderScore
|
|
5864
|
-
};
|
|
5865
|
-
function pageFromBuffer(scorer, scans, buffer, selection, resolver) {
|
|
5866
|
-
const approximateKth = kthBestScore(buffer, selection, resolver);
|
|
5867
|
-
const gatherFrom = approximateKth - Math.abs(approximateKth) * PRUNING_REJECTION_SLACK;
|
|
5868
|
-
const heap = [];
|
|
5869
|
-
let full = false;
|
|
5870
|
-
let threshold = 0;
|
|
5871
|
-
const { touched, touchedCount, scores } = buffer;
|
|
5872
|
-
for (let index = 0; index < touchedCount; index++) {
|
|
5873
|
-
const internalId = touched[index];
|
|
5874
|
-
if (scores[internalId] < gatherFrom) continue;
|
|
5875
|
-
const externalId = resolver.toExternal(internalId);
|
|
5876
|
-
if (externalId === void 0) continue;
|
|
5877
|
-
const score = scorer.queryOrderScore(scans, internalId);
|
|
5878
|
-
if (full && score < threshold) continue;
|
|
5879
|
-
const candidate = { internalId, externalId, score };
|
|
5880
|
-
if (!full) {
|
|
5881
|
-
heap.push(candidate);
|
|
5882
|
-
if (heap.length === selection.length) {
|
|
5883
|
-
buildMinHeap(heap);
|
|
5884
|
-
full = true;
|
|
5885
|
-
threshold = heap[0].score;
|
|
5886
|
-
}
|
|
5887
|
-
} else if (candidateWorse(heap[0], candidate)) {
|
|
5888
|
-
heap[0] = candidate;
|
|
5889
|
-
siftDown(heap, 0);
|
|
5890
|
-
threshold = heap[0].score;
|
|
5891
|
-
}
|
|
5892
|
-
}
|
|
5893
|
-
sortSelection(heap);
|
|
5894
|
-
const scored = new Array(heap.length);
|
|
5895
|
-
for (let index = 0; index < heap.length; index++) {
|
|
5896
|
-
scored[index] = {
|
|
5897
|
-
docId: heap[index].externalId,
|
|
5898
|
-
score: heap[index].score,
|
|
5899
|
-
termFrequencies: EMPTY_COMPONENTS,
|
|
5900
|
-
fieldLengths: EMPTY_COMPONENTS,
|
|
5901
|
-
idf: EMPTY_COMPONENTS
|
|
5902
|
-
};
|
|
5903
|
-
}
|
|
5904
|
-
return scored;
|
|
5905
|
-
}
|
|
5906
|
-
function multiTermTopK(request) {
|
|
5907
|
-
const { terms, docFrequencies, totalDocs, limit, fields, resolver, buffer } = request;
|
|
5908
|
-
if (!boostsKeepScoresNonNegative(fields)) return null;
|
|
5909
|
-
const onePair = fields.boundPairs.length === 2;
|
|
5910
|
-
const scorer = onePair ? SAME_PAIR_SCORER : FIELD_PAIR_SCORER;
|
|
5911
|
-
const k1 = onePair ? fields.boundPairs[0] : 0;
|
|
5912
|
-
const b = onePair ? fields.boundPairs[1] : 0;
|
|
5913
|
-
const scans = new Array(terms.length);
|
|
5914
|
-
for (let term = 0; term < terms.length; term++) {
|
|
5915
|
-
const idf = computeIDF(docFrequencies[term], totalDocs);
|
|
5916
|
-
if (!(idf >= 0)) return null;
|
|
5917
|
-
scans[term] = {
|
|
5918
|
-
columns: postingColumns(terms[term].list),
|
|
5919
|
-
idf,
|
|
5920
|
-
scoresAreZero: totalDocs === 0,
|
|
5921
|
-
fields,
|
|
5922
|
-
k1,
|
|
5923
|
-
b
|
|
5924
|
-
};
|
|
5925
|
-
}
|
|
5926
|
-
const maxBoost = bestSearchable(fields.searchable, fields.boosts);
|
|
5927
|
-
const maxAverageLength = bestSearchable(fields.searchable, fields.averageLengths);
|
|
5928
|
-
const upperBounds = scans.map((scan, term) => scorer.upperBound(scan, terms[term].list, maxBoost, maxAverageLength));
|
|
5929
|
-
const order = scans.map((_, term) => term).sort((left, right) => upperBounds[right] - upperBounds[left]);
|
|
5930
|
-
const remainingBound = new Float64Array(order.length + 1);
|
|
5931
|
-
for (let position2 = order.length - 1; position2 >= 0; position2--) {
|
|
5932
|
-
remainingBound[position2] = remainingBound[position2 + 1] + upperBounds[order[position2]];
|
|
5933
|
-
}
|
|
5934
|
-
const wanted = Number.isFinite(limit) ? Math.max(0, Math.floor(limit)) : 0;
|
|
5935
|
-
const selection = new Float64Array(wanted);
|
|
5936
|
-
let position = wanted === 0 ? order.length : 0;
|
|
5937
|
-
for (; position < order.length; position++) {
|
|
5938
|
-
const remaining = remainingBound[position];
|
|
5939
|
-
if (position > 0 && buffer.touchedCount >= wanted && remaining < remainingBound[0] - remaining) {
|
|
5940
|
-
const threshold = kthBestScore(buffer, selection, resolver);
|
|
5941
|
-
if (remaining < threshold - threshold * PRUNING_REJECTION_SLACK) break;
|
|
5942
|
-
}
|
|
5943
|
-
scorer.scoreEveryDocument(scans[order[position]], buffer);
|
|
5944
|
-
}
|
|
5945
|
-
let countedOnly = 0;
|
|
5946
|
-
for (let rest = position; rest < order.length; rest++) {
|
|
5947
|
-
countedOnly += scorer.scoreKnownDocumentsAndCountTheRest(scans[order[rest]], buffer);
|
|
5948
|
-
}
|
|
5949
|
-
const totalMatched = buffer.touchedCount + countedOnly;
|
|
5950
|
-
if (wanted === 0) return { scored: [], totalMatched };
|
|
5951
|
-
return { scored: pageFromBuffer(scorer, scans, buffer, selection, resolver), totalMatched };
|
|
5952
|
-
}
|
|
5953
|
-
|
|
5954
|
-
// src/core/partition/single-term-topk.ts
|
|
5955
|
-
function fieldsCoverEvery(fields, fieldNames) {
|
|
5956
|
-
if (fields === void 0) return true;
|
|
5957
|
-
for (const name of fieldNames) {
|
|
5958
|
-
if (!fields.includes(name)) return false;
|
|
5959
|
-
}
|
|
5960
|
-
return true;
|
|
5961
|
-
}
|
|
5962
|
-
function prunableSingleTermList(params, index, fieldNames) {
|
|
5963
|
-
if (params.queryTokens.length !== 1) return null;
|
|
5964
|
-
if (params.termGroups !== void 0 && params.termGroups.length > 0) return null;
|
|
5965
|
-
if (params.exact !== true && (params.tolerance ?? 0) !== 0) return null;
|
|
5966
|
-
if (params.termMatch !== void 0 && params.termMatch !== "any") return null;
|
|
5967
|
-
if (params.collectComponents !== false) return null;
|
|
5968
|
-
if (params.collectMatchedSet !== void 0) return null;
|
|
5969
|
-
if (params.maxResults === void 0) return null;
|
|
5970
|
-
if (!fieldsCoverEvery(params.fields, fieldNames)) return null;
|
|
5971
|
-
if (params.filterBitset !== void 0) return null;
|
|
5972
|
-
if (!bm25PruningSound(params.bm25Params)) return null;
|
|
5973
|
-
const list = index.lookup(params.queryTokens[0].token);
|
|
5974
|
-
if (list === void 0) return null;
|
|
5975
|
-
if (!list.ordered) return null;
|
|
5976
|
-
return list;
|
|
5977
|
-
}
|
|
5978
|
-
function singleTermTopK(request) {
|
|
5979
|
-
const { list, docFrequency, totalDocs, limit, resolver } = request;
|
|
5980
|
-
const {
|
|
5981
|
-
searchable: fieldSearchable,
|
|
5982
|
-
boosts: fieldBoosts,
|
|
5983
|
-
averageLengths: fieldAvgLengths,
|
|
5984
|
-
lengthColumns: fieldLengthColumns,
|
|
5985
|
-
k1s,
|
|
5986
|
-
bs,
|
|
5987
|
-
boundPairs
|
|
5988
|
-
} = request.fields;
|
|
5989
|
-
const onePair = boundPairs.length === 2;
|
|
5990
|
-
const onlyK1 = boundPairs[0];
|
|
5991
|
-
const onlyB = boundPairs[1];
|
|
5992
|
-
const wanted = Number.isFinite(limit) ? Math.max(0, Math.floor(limit)) : 0;
|
|
5993
|
-
const { docIds, termFrequencies, fieldNameIndices, deletedDocs: deleted, hasDeleted } = postingColumns(list);
|
|
5994
|
-
const bounds = blockBoundsFor(list, fieldLengthColumns);
|
|
5995
|
-
const maxBoost = bestSearchable(fieldSearchable, fieldBoosts);
|
|
5996
|
-
const maxAverageLength = bestSearchable(fieldSearchable, fieldAvgLengths);
|
|
5997
|
-
const idf = computeIDF(docFrequency, totalDocs);
|
|
5998
|
-
const scoresAreZero = totalDocs === 0;
|
|
5999
|
-
const heap = [];
|
|
6000
|
-
let full = false;
|
|
6001
|
-
let threshold = 0;
|
|
6002
|
-
let totalMatched = 0;
|
|
6003
|
-
for (let block = 0; block < bounds.blockCount; block++) {
|
|
6004
|
-
const start = block === 0 ? 0 : bounds.entryEnd[block - 1];
|
|
6005
|
-
const end = bounds.entryEnd[block];
|
|
6006
|
-
if (full) {
|
|
6007
|
-
let bestEntry = 0;
|
|
6008
|
-
if (!scoresAreZero) {
|
|
6009
|
-
const blockMaxTf = bounds.maxTermFrequency[block];
|
|
6010
|
-
const blockMinLength = bounds.minFieldLength[block];
|
|
6011
|
-
bestEntry = onePair ? computeBM25WithIDF(blockMaxTf, idf, blockMinLength, maxAverageLength, onlyK1, onlyB) : blockEntryBound(request.fields, blockMaxTf, idf, blockMinLength, maxAverageLength);
|
|
6012
|
-
}
|
|
6013
|
-
if (bestEntry * maxBoost * bounds.maxEntriesPerDocument[block] < threshold) {
|
|
6014
|
-
totalMatched += bounds.documentCount[block];
|
|
6015
|
-
continue;
|
|
6016
|
-
}
|
|
6017
|
-
}
|
|
6018
|
-
let entry = start;
|
|
6019
|
-
while (entry < end) {
|
|
6020
|
-
const internalId = docIds[entry];
|
|
6021
|
-
if (hasDeleted && deleted.has(internalId)) {
|
|
6022
|
-
while (entry < end && docIds[entry] === internalId) entry++;
|
|
6023
|
-
continue;
|
|
6024
|
-
}
|
|
6025
|
-
let score = 0;
|
|
6026
|
-
let scored2 = false;
|
|
6027
|
-
while (entry < end && docIds[entry] === internalId) {
|
|
6028
|
-
const fieldIndex = fieldNameIndices[entry];
|
|
6029
|
-
if (fieldSearchable[fieldIndex] === 1) {
|
|
6030
|
-
const fieldLength = fieldLengthOf(fieldLengthColumns, fieldIndex, internalId, fieldAvgLengths[fieldIndex]);
|
|
6031
|
-
score += (scoresAreZero ? 0 : computeBM25WithIDF(
|
|
6032
|
-
termFrequencies[entry],
|
|
6033
|
-
idf,
|
|
6034
|
-
fieldLength,
|
|
6035
|
-
fieldAvgLengths[fieldIndex],
|
|
6036
|
-
onePair ? onlyK1 : k1s[fieldIndex],
|
|
6037
|
-
onePair ? onlyB : bs[fieldIndex]
|
|
6038
|
-
)) * fieldBoosts[fieldIndex];
|
|
6039
|
-
scored2 = true;
|
|
6040
|
-
}
|
|
6041
|
-
entry++;
|
|
6042
|
-
}
|
|
6043
|
-
if (!scored2) continue;
|
|
6044
|
-
totalMatched++;
|
|
6045
|
-
if (wanted === 0) continue;
|
|
6046
|
-
if (full && score < threshold) continue;
|
|
6047
|
-
const externalId = resolver.toExternal(internalId);
|
|
6048
|
-
if (externalId === void 0) continue;
|
|
6049
|
-
const candidate = { internalId, externalId, score };
|
|
6050
|
-
if (!full) {
|
|
6051
|
-
heap.push(candidate);
|
|
6052
|
-
if (heap.length === wanted) {
|
|
6053
|
-
buildMinHeap(heap);
|
|
6054
|
-
full = true;
|
|
6055
|
-
threshold = heap[0].score;
|
|
6056
|
-
}
|
|
6057
|
-
continue;
|
|
6058
|
-
}
|
|
6059
|
-
if (candidateWorse(heap[0], candidate)) {
|
|
6060
|
-
heap[0] = candidate;
|
|
6061
|
-
siftDown(heap, 0);
|
|
6062
|
-
threshold = heap[0].score;
|
|
6063
|
-
}
|
|
6064
|
-
}
|
|
6065
|
-
}
|
|
6066
|
-
sortSelection(heap);
|
|
6067
|
-
const scored = new Array(heap.length);
|
|
6068
|
-
for (let index = 0; index < heap.length; index++) {
|
|
6069
|
-
scored[index] = {
|
|
6070
|
-
docId: heap[index].externalId,
|
|
6071
|
-
score: heap[index].score,
|
|
6072
|
-
termFrequencies: EMPTY_COMPONENTS,
|
|
6073
|
-
fieldLengths: EMPTY_COMPONENTS,
|
|
6074
|
-
idf: EMPTY_COMPONENTS
|
|
6075
|
-
};
|
|
6076
|
-
}
|
|
6077
|
-
return { scored, totalMatched };
|
|
6078
|
-
}
|
|
6079
|
-
|
|
6080
|
-
// src/core/partition/search.ts
|
|
6081
|
-
function globalDocFreqFor(docFreqs, term, fallback) {
|
|
6082
|
-
return Object.hasOwn(docFreqs, term) ? docFreqs[term] : fallback;
|
|
6083
|
-
}
|
|
6084
|
-
function searchFulltext(state, params) {
|
|
6085
|
-
const {
|
|
6086
|
-
queryTokens,
|
|
6087
|
-
termGroups,
|
|
6088
|
-
partialFields,
|
|
6089
|
-
fields,
|
|
6090
|
-
boost,
|
|
6091
|
-
tolerance = 0,
|
|
6092
|
-
prefixLength = 2,
|
|
6093
|
-
exact = false,
|
|
6094
|
-
bm25Params,
|
|
6095
|
-
globalStats,
|
|
6096
|
-
maxResults,
|
|
6097
|
-
termMatch,
|
|
6098
|
-
phrases
|
|
6099
|
-
} = params;
|
|
6100
|
-
const collectComponents = params.collectComponents !== false;
|
|
6101
|
-
if (queryTokens.length === 0 && phrases === void 0) {
|
|
6102
|
-
return { scored: [], totalMatched: 0 };
|
|
6103
|
-
}
|
|
6104
|
-
const totalDocs = globalStats?.totalDocuments ?? state.stats.totalDocuments;
|
|
6105
|
-
const avgFieldLengths = globalStats?.averageFieldLengths ?? state.stats.averageFieldLengths;
|
|
6106
|
-
const scoresAreZero = totalDocs === 0;
|
|
6107
|
-
if (state.scoreBuffer === null) state.scoreBuffer = createScoreBuffer(state.docStore.internalIdCapacity());
|
|
6108
|
-
const scoreBuffer = state.scoreBuffer;
|
|
6109
|
-
beginScoring(scoreBuffer, state.docStore.internalIdCapacity());
|
|
6110
|
-
const components = collectComponents ? /* @__PURE__ */ new Map() : null;
|
|
6111
|
-
const useIntersection = termMatch === "all" && queryTokens.length > 1;
|
|
6112
|
-
const fieldNames = state.fieldNameTable.names;
|
|
6113
|
-
const resolver = state.docStore.resolver();
|
|
6114
|
-
const fieldScoring = loadFieldScoring(state, fields, boost, avgFieldLengths, bm25Params);
|
|
6115
|
-
const { searchable, boosts, averageLengths, lengthColumns, k1s, bs, boundPairs } = fieldScoring;
|
|
6116
|
-
const onePair = boundPairs.length === 2;
|
|
6117
|
-
const onlyK1 = boundPairs[0];
|
|
6118
|
-
const onlyB = boundPairs[1];
|
|
6119
|
-
const phraseMatches = phrases === void 0 ? null : requireLoadedPhraseCode().matchPhrases(
|
|
6120
|
-
state.invertedIdx,
|
|
6121
|
-
phrases,
|
|
6122
|
-
searchable,
|
|
6123
|
-
params.filterBitset,
|
|
6124
|
-
state.docStore.internalIdCapacity(),
|
|
6125
|
-
params.phraseWork,
|
|
6126
|
-
true
|
|
6127
|
-
);
|
|
6128
|
-
if (phraseMatches !== null && bitsetIsEmpty(phraseMatches.matched)) {
|
|
6129
|
-
return { scored: [], totalMatched: 0 };
|
|
6130
|
-
}
|
|
6131
|
-
const filterBitset = phraseMatches?.matched ?? params.filterBitset;
|
|
6132
|
-
function documentFrequency(token, list) {
|
|
6133
|
-
return globalStats ? globalDocFreqFor(globalStats.docFrequencies, token, list.docIdSet.size) : list.docIdSet.size;
|
|
6134
|
-
}
|
|
6135
|
-
function scorePhraseRows(rows, matched) {
|
|
6136
|
-
let idf = 0;
|
|
6137
|
-
for (let entry = 0; entry < rows.phrase.tokens.length; entry++) {
|
|
6138
|
-
idf += computeIDF(documentFrequency(rows.phrase.tokens[entry], rows.lists[entry]), totalDocs);
|
|
6139
|
-
}
|
|
6140
|
-
for (let row = 0; row < rows.docIds.length; row++) {
|
|
6141
|
-
const internalId = rows.docIds.values[row];
|
|
6142
|
-
if (!bitsetHas(matched, internalId)) continue;
|
|
6143
|
-
const fieldIndex = rows.fieldIndices.values[row];
|
|
6144
|
-
const frequency = rows.frequencies.values[row];
|
|
6145
|
-
const avgLen = averageLengths[fieldIndex];
|
|
6146
|
-
const fieldLength = fieldLengthOf(lengthColumns, fieldIndex, internalId, avgLen);
|
|
6147
|
-
const score = scoresAreZero ? 0 : computeBM25WithIDF(
|
|
6148
|
-
frequency,
|
|
6149
|
-
idf,
|
|
6150
|
-
fieldLength,
|
|
6151
|
-
avgLen,
|
|
6152
|
-
onePair ? onlyK1 : k1s[fieldIndex],
|
|
6153
|
-
onePair ? onlyB : bs[fieldIndex]
|
|
6154
|
-
);
|
|
6155
|
-
addScore(scoreBuffer, internalId, score * boosts[fieldIndex]);
|
|
6156
|
-
if (components !== null) {
|
|
6157
|
-
recordComponents(components, internalId, fieldNames[fieldIndex], rows.phrase.key, frequency, fieldLength, idf);
|
|
6158
|
-
}
|
|
6159
|
-
}
|
|
6160
|
-
}
|
|
6161
|
-
const groupContext = {
|
|
6162
|
-
index: state.invertedIdx,
|
|
6163
|
-
fields: fieldScoring,
|
|
6164
|
-
partialMarks: partialFieldMarks(fieldNames, partialFields),
|
|
6165
|
-
fieldNames,
|
|
6166
|
-
totalDocs,
|
|
6167
|
-
filterBitset,
|
|
6168
|
-
globalFrequency(token) {
|
|
6169
|
-
if (globalStats === void 0 || !Object.hasOwn(globalStats.docFrequencies, token)) return void 0;
|
|
6170
|
-
return globalStats.docFrequencies[token];
|
|
6171
|
-
}
|
|
6172
|
-
};
|
|
6173
|
-
function mergeGroupContribution(internalId, contribution) {
|
|
6174
|
-
addScore(scoreBuffer, internalId, contribution.score);
|
|
6175
|
-
if (components !== null) mergeGroupComponents(components, internalId, contribution);
|
|
6176
|
-
}
|
|
6177
|
-
function resolveMatch(token, postingList) {
|
|
6178
|
-
const docFreq = documentFrequency(token, postingList);
|
|
6179
|
-
return { token, docFreq, idf: computeIDF(docFreq, totalDocs), postingList };
|
|
6180
|
-
}
|
|
6181
|
-
function scorePostings(match, onlyScored) {
|
|
6182
|
-
const { docIds, termFrequencies, fieldNameIndices, deletedDocs, hasDeleted, count } = postingColumns(
|
|
6183
|
-
match.postingList
|
|
6184
|
-
);
|
|
6185
|
-
if (!onlyScored && !hasDeleted && filterBitset === void 0 && components === null) {
|
|
6186
|
-
for (let pi = 0; pi < count; pi++) {
|
|
6187
|
-
const internalId = docIds[pi];
|
|
6188
|
-
const fieldIndex = fieldNameIndices[pi];
|
|
6189
|
-
if (searchable[fieldIndex] === 0) continue;
|
|
6190
|
-
const avgLen = averageLengths[fieldIndex];
|
|
6191
|
-
const actualFieldLength = fieldLengthOf(lengthColumns, fieldIndex, internalId, avgLen);
|
|
6192
|
-
const termScore = scoresAreZero ? 0 : computeBM25WithIDF(
|
|
6193
|
-
termFrequencies[pi],
|
|
6194
|
-
match.idf,
|
|
6195
|
-
actualFieldLength,
|
|
6196
|
-
avgLen,
|
|
6197
|
-
onePair ? onlyK1 : k1s[fieldIndex],
|
|
6198
|
-
onePair ? onlyB : bs[fieldIndex]
|
|
6199
|
-
);
|
|
6200
|
-
addScore(scoreBuffer, internalId, termScore * boosts[fieldIndex]);
|
|
6201
|
-
}
|
|
6202
|
-
return;
|
|
6203
|
-
}
|
|
6204
|
-
for (let pi = 0; pi < count; pi++) {
|
|
6205
|
-
const internalId = docIds[pi];
|
|
6206
|
-
if (hasDeleted && deletedDocs.has(internalId)) continue;
|
|
6207
|
-
if (filterBitset && !bitsetHas(filterBitset, internalId)) continue;
|
|
6208
|
-
if (onlyScored && !hasScore(scoreBuffer, internalId)) continue;
|
|
6209
|
-
const fieldIndex = fieldNameIndices[pi];
|
|
6210
|
-
if (searchable[fieldIndex] === 0) continue;
|
|
6211
|
-
const termFrequency = termFrequencies[pi];
|
|
6212
|
-
const avgLen = averageLengths[fieldIndex];
|
|
6213
|
-
const actualFieldLength = fieldLengthOf(lengthColumns, fieldIndex, internalId, avgLen);
|
|
6214
|
-
const termScore = scoresAreZero ? 0 : computeBM25WithIDF(
|
|
6215
|
-
termFrequency,
|
|
6216
|
-
match.idf,
|
|
6217
|
-
actualFieldLength,
|
|
6218
|
-
avgLen,
|
|
6219
|
-
onePair ? onlyK1 : k1s[fieldIndex],
|
|
6220
|
-
onePair ? onlyB : bs[fieldIndex]
|
|
6221
|
-
);
|
|
6222
|
-
addScore(scoreBuffer, internalId, termScore * boosts[fieldIndex]);
|
|
6223
|
-
if (components !== null) {
|
|
6224
|
-
recordComponents(
|
|
6225
|
-
components,
|
|
6226
|
-
internalId,
|
|
6227
|
-
fieldNames[fieldIndex],
|
|
6228
|
-
match.token,
|
|
6229
|
-
termFrequency,
|
|
6230
|
-
actualFieldLength,
|
|
6231
|
-
match.idf
|
|
6232
|
-
);
|
|
6233
|
-
}
|
|
6234
|
-
}
|
|
6235
|
-
}
|
|
6236
|
-
function scoreGroup(group, onlyScored) {
|
|
6237
|
-
if (group === null) return;
|
|
6238
|
-
for (const [internalId, contribution] of computeGroupContributions(groupContext, group, collectComponents)) {
|
|
6239
|
-
if (onlyScored && !hasScore(scoreBuffer, internalId)) continue;
|
|
6240
|
-
mergeGroupContribution(internalId, contribution);
|
|
6241
|
-
}
|
|
6242
|
-
}
|
|
6243
|
-
const prunableList = phrases === void 0 ? prunableSingleTermList(params, state.invertedIdx, fieldNames) : null;
|
|
6244
|
-
if (prunableList !== null && maxResults !== void 0) {
|
|
6245
|
-
return singleTermTopK({
|
|
6246
|
-
list: prunableList,
|
|
6247
|
-
docFrequency: documentFrequency(queryTokens[0].token, prunableList),
|
|
6248
|
-
totalDocs,
|
|
6249
|
-
limit: maxResults,
|
|
6250
|
-
fields: fieldScoring,
|
|
6251
|
-
resolver
|
|
6252
|
-
});
|
|
6253
|
-
}
|
|
6254
|
-
const prunableLists = phrases === void 0 ? prunableMultiTermLists(params, state.invertedIdx) : null;
|
|
6255
|
-
if (prunableLists !== null && maxResults !== void 0) {
|
|
6256
|
-
const pruned = multiTermTopK({
|
|
6257
|
-
terms: prunableLists,
|
|
6258
|
-
docFrequencies: prunableLists.map((term) => documentFrequency(term.token, term.list)),
|
|
6259
|
-
totalDocs,
|
|
6260
|
-
limit: maxResults,
|
|
6261
|
-
fields: fieldScoring,
|
|
6262
|
-
resolver,
|
|
6263
|
-
buffer: scoreBuffer
|
|
6264
|
-
});
|
|
6265
|
-
if (pruned !== null) return pruned;
|
|
6266
|
-
}
|
|
6267
|
-
if (useIntersection) {
|
|
6268
|
-
const resolved = [];
|
|
6269
|
-
for (const qt of queryTokens) {
|
|
6270
|
-
const group = termGroupOf(termGroups, qt.token);
|
|
6271
|
-
const groupMatches = group === void 0 ? null : resolveGroupMatches(groupContext, group);
|
|
6272
|
-
let totalPostings = groupMatches === null ? 0 : groupPostingCount(groupMatches);
|
|
6273
|
-
const matches = [];
|
|
6274
|
-
for (const m of typoMatchesFor(state.invertedIdx, qt.token, group, exact, tolerance, prefixLength)) {
|
|
6275
|
-
totalPostings += m.postingList.length;
|
|
6276
|
-
matches.push(resolveMatch(m.token, m.postingList));
|
|
6277
|
-
}
|
|
6278
|
-
resolved.push({ token: qt.token, matches, totalPostings, group: groupMatches });
|
|
6279
|
-
}
|
|
6280
|
-
resolved.sort((a, b) => a.totalPostings - b.totalPostings);
|
|
6281
|
-
for (let tokenIndex = 0; tokenIndex < resolved.length; tokenIndex++) {
|
|
6282
|
-
const onlyScored = tokenIndex > 0;
|
|
6283
|
-
for (const match of resolved[tokenIndex].matches) scorePostings(match, onlyScored);
|
|
6284
|
-
scoreGroup(resolved[tokenIndex].group, onlyScored);
|
|
6285
|
-
}
|
|
6286
|
-
} else {
|
|
6287
|
-
for (const qt of queryTokens) {
|
|
6288
|
-
const group = termGroupOf(termGroups, qt.token);
|
|
6289
|
-
for (const m of typoMatchesFor(state.invertedIdx, qt.token, group, exact, tolerance, prefixLength)) {
|
|
6290
|
-
scorePostings(resolveMatch(m.token, m.postingList), false);
|
|
6291
|
-
}
|
|
6292
|
-
if (group !== void 0) scoreGroup(resolveGroupMatches(groupContext, group), false);
|
|
6293
|
-
}
|
|
6294
|
-
}
|
|
6295
|
-
if (phraseMatches !== null) {
|
|
6296
|
-
for (const rows of phraseMatches.rows) scorePhraseRows(rows, phraseMatches.matched);
|
|
6297
|
-
}
|
|
6298
|
-
const totalMatched = scoreBuffer.touchedCount;
|
|
6299
|
-
const k = maxResults === void 0 ? totalMatched : Math.max(0, Math.min(maxResults, totalMatched));
|
|
6300
|
-
const scored = topKFromBuffer(scoreBuffer, k, resolver, components);
|
|
6301
|
-
if (params.collectMatchedSet === void 0) {
|
|
6302
|
-
return { scored, totalMatched };
|
|
6303
|
-
}
|
|
6304
|
-
if (params.collectMatchedSet === "ordinals") {
|
|
6305
|
-
const matchedOrdinalBitset = createBitSet(state.docStore.internalIdCapacity());
|
|
6306
|
-
for (let index = 0; index < scoreBuffer.touchedCount; index++) {
|
|
6307
|
-
bitsetSet(matchedOrdinalBitset, scoreBuffer.touched[index]);
|
|
6308
|
-
}
|
|
6309
|
-
return { scored, totalMatched, matchedOrdinalBitset };
|
|
6310
|
-
}
|
|
6311
|
-
const matchedIds = [];
|
|
6312
|
-
for (let index = 0; index < scoreBuffer.touchedCount; index++) {
|
|
6313
|
-
const externalId = resolver.toExternal(scoreBuffer.touched[index]);
|
|
6314
|
-
if (externalId !== void 0) matchedIds.push(externalId);
|
|
6315
|
-
}
|
|
6316
|
-
return { scored, totalMatched, matchedIds };
|
|
6317
|
-
}
|
|
6318
|
-
|
|
6319
4744
|
// src/core/partition/segment-field-indexes.ts
|
|
6320
4745
|
function encodeNumericIndexes(indexes, remap) {
|
|
6321
4746
|
const encoded = [];
|
|
@@ -6575,7 +5000,7 @@ function mergePayloadFieldIndexes(target, payload, ordinalBase) {
|
|
|
6575
5000
|
for (const entry of payload.geo) {
|
|
6576
5001
|
let index = target.geoIndexes.get(entry.fieldPath);
|
|
6577
5002
|
if (index === void 0) {
|
|
6578
|
-
index =
|
|
5003
|
+
index = createLoadedGeoIndex();
|
|
6579
5004
|
target.geoIndexes.set(entry.fieldPath, index);
|
|
6580
5005
|
}
|
|
6581
5006
|
for (let i = 0; i < entry.docIds.length; i++) {
|
|
@@ -6809,7 +5234,7 @@ function deserializePartition(state, data, clearFn, schema) {
|
|
|
6809
5234
|
state.enumIndexes.set(path, idx);
|
|
6810
5235
|
}
|
|
6811
5236
|
for (const [path, entries] of Object.entries(data.fieldIndexes.geopoint)) {
|
|
6812
|
-
const geoIdx =
|
|
5237
|
+
const geoIdx = createLoadedGeoIndex();
|
|
6813
5238
|
const converted = entries.map((e) => ({
|
|
6814
5239
|
lat: e.lat,
|
|
6815
5240
|
lon: e.lon,
|
|
@@ -9053,4 +7478,4 @@ function fanOutMatchCount(manager, params, language, schema, options) {
|
|
|
9053
7478
|
return count;
|
|
9054
7479
|
}
|
|
9055
7480
|
|
|
9056
|
-
export {
|
|
7481
|
+
export { FIELD_FILTER_OPERATORS, FILTER_EXPRESSION_KEYS, PATTERN_HOST, ValueAffixes, applyPagination, applyPartitionFiltersBitset, applyProjection, applySorting, availablePatternSearch, buildPartialWordTableFrom, clampRowCount, cloneProjected, collectQueryTermStats, copyVectorsInto, countPartialSpelling, countsWithoutScores, createBooleanIndex, createCompositePartition, createEnumIndex, createFrozenPartialWords, createNumericIndex, createPartitionIndex, createPatternWorkMeter, createSurfaceRegistry, decodePageCursor, documentValueBytes, documentWithOwnBuffers, encodeFieldIndexes, encodePageCursor, encodePartialSpellingsOf, encodeSegmentState, everyValueFacetConfig, fanOutMatchCount, fanOutQuery, filterTestCount, fulltextMatches, isCompositePartition, joinPatternWorkMeter, kWayMerge, mergeDocFrequencies, mergeFacets, mergePartitionStats, normalizeSort, oversampledFacetConfig, oversampledShardSize, partialSpellingsOfDocuments, partialWordHighlighter, partialWordsToHighlight, partitionStateOf, partitionsIn, patternIndexOf, projectIncludedPaths, projectionKeepsField, pruneStatsToQueryTerms, readProjectedPath, readResidentMemory, readSortValues, recordValueSize, registerPartialWordSearch, registerPatternSearch, requireMatchingCursor, requirePartialWordSearchFor, requirePatternSearch, requirePatternSearchFor, requireSortableFields, requireWithinResultWindow, resolveProjection, sanitizeGlobalStats, setNestedValue, sortModesOf, sortSignatureEntry, sortSignatureOf, survivorDocumentsOf, undeclaredFieldOnStrictIndex, validatedFilterOf, valueWithOwnBuffers };
|