@yoch/frozenminisearch 1.0.0

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.
@@ -0,0 +1,13 @@
1
+ 'use strict'
2
+
3
+ const mod = require('./index.cjs')
4
+ const main = mod.default || mod
5
+
6
+ module.exports = main
7
+ module.exports.default = main
8
+
9
+ for (const key of Object.keys(mod)) {
10
+ if (key !== 'default') {
11
+ module.exports[key] = mod[key]
12
+ }
13
+ }
@@ -0,0 +1,620 @@
1
+ /**
2
+ * Wildcard query symbol (matches all documents).
3
+ * Use {@link FrozenMiniSearch.wildcard} in application code.
4
+ */
5
+ declare const WILDCARD_QUERY: unique symbol;
6
+
7
+ /**
8
+ * BM25+ algorithm parameters.
9
+ */
10
+ type BM25Params = {
11
+ k: number;
12
+ b: number;
13
+ d: number;
14
+ };
15
+ type LowercaseCombinationOperator = 'or' | 'and' | 'and_not';
16
+ type CombinationOperator = LowercaseCombinationOperator | Uppercase<LowercaseCombinationOperator> | Capitalize<LowercaseCombinationOperator>;
17
+ type LogLevel = 'debug' | 'info' | 'warn' | 'error';
18
+ /**
19
+ * Search options to customize the search behavior.
20
+ */
21
+ type SearchOptions = {
22
+ /**
23
+ * Names of the fields to search in. If omitted, all fields are searched.
24
+ */
25
+ fields?: string[];
26
+ /**
27
+ * Function used to filter search results, for example on the basis of stored
28
+ * fields. It takes as argument each search result and should return a boolean
29
+ * to indicate if the result should be kept or not.
30
+ */
31
+ filter?: (result: SearchResult) => boolean;
32
+ /**
33
+ * Key-value object of field names to boosting values. By default, fields are
34
+ * assigned a boosting factor of 1. If one assigns to a field a boosting value
35
+ * of 2, a result that matches the query in that field is assigned a score
36
+ * twice as high as a result matching the query in another field, all else
37
+ * being equal.
38
+ */
39
+ boost?: {
40
+ [fieldName: string]: number;
41
+ };
42
+ /**
43
+ * Function to calculate a boost factor for each query term. Returning a
44
+ * factor lower than 1 reduces the importance of the term, greater than 1
45
+ * increases it, and exactly 1 is neutral.
46
+ */
47
+ boostTerm?: (term: string, i: number, terms: string[]) => number;
48
+ /**
49
+ * Relative weights to assign to prefix search results and fuzzy search
50
+ * results. Exact matches are assigned a weight of 1.
51
+ */
52
+ weights?: {
53
+ fuzzy: number;
54
+ prefix: number;
55
+ };
56
+ /**
57
+ * Function to calculate a boost factor for documents. It takes as arguments
58
+ * the document ID, and a term that matches the search in that document, and
59
+ * the value of the stored fields for the document (if any). A falsy value
60
+ * skips the search result completely.
61
+ */
62
+ boostDocument?: (documentId: any, term: string, storedFields?: Record<string, unknown>) => number;
63
+ /**
64
+ * Controls whether to perform prefix search. Either a boolean, or a function
65
+ * called per query term that returns a boolean.
66
+ */
67
+ prefix?: boolean | ((term: string, index: number, terms: string[]) => boolean);
68
+ /**
69
+ * Controls whether to perform fuzzy search. Either a boolean (default
70
+ * fuzziness), a number (explicit edit distance ≥ 1, or fractional 0–1 of the
71
+ * term length), or a function returning either.
72
+ */
73
+ fuzzy?: boolean | number | ((term: string, index: number, terms: string[]) => boolean | number);
74
+ /**
75
+ * Maximum fuzziness when using a fractional fuzzy value. Defaults to 6.
76
+ */
77
+ maxFuzzy?: number;
78
+ /**
79
+ * The operand to combine partial results for each term. Defaults to "OR".
80
+ */
81
+ combineWith?: CombinationOperator;
82
+ /**
83
+ * Function to tokenize the search query. By default, the same tokenizer used
84
+ * for indexing is used also for search.
85
+ */
86
+ tokenize?: (text: string) => string[];
87
+ /**
88
+ * Function to process or normalize terms in the search query. By default, the
89
+ * same term processor used for indexing is used also for search.
90
+ */
91
+ processTerm?: (term: string) => string | string[] | null | undefined | false;
92
+ /**
93
+ * BM25+ algorithm parameters. Customizing these is almost never necessary.
94
+ */
95
+ bm25?: BM25Params;
96
+ };
97
+ /**
98
+ * `SearchOptions` with library defaults filled in. Used as the canonical shape
99
+ * resolved by `MiniSearch` / `FrozenMiniSearch` before passing options around.
100
+ */
101
+ type SearchOptionsWithDefaults = SearchOptions & {
102
+ boost: {
103
+ [fieldName: string]: number;
104
+ };
105
+ weights: {
106
+ fuzzy: number;
107
+ prefix: number;
108
+ };
109
+ prefix: boolean | ((term: string, index: number, terms: string[]) => boolean);
110
+ fuzzy: boolean | number | ((term: string, index: number, terms: string[]) => boolean | number);
111
+ maxFuzzy: number;
112
+ combineWith: CombinationOperator;
113
+ bm25: BM25Params;
114
+ };
115
+ /**
116
+ * Configuration options passed to the {@link MiniSearch} constructor.
117
+ *
118
+ * @typeParam T The type of documents being indexed.
119
+ */
120
+ type Options<T = any> = {
121
+ /** Names of the document fields to be indexed. */
122
+ fields: string[];
123
+ /** Name of the ID field, uniquely identifying a document. Defaults to `"id"`. */
124
+ idField?: string;
125
+ /** Names of fields to store, so that search results would include them. */
126
+ storeFields?: string[];
127
+ /** Function used to extract the value of each field in documents. */
128
+ extractField?: (document: T, fieldName: string) => any;
129
+ /** Function used to turn field values into strings for indexing. */
130
+ stringifyField?: (fieldValue: any, fieldName: string) => string;
131
+ /** Function used to split a field value into individual terms to be indexed. */
132
+ tokenize?: (text: string, fieldName?: string) => string[];
133
+ /** Function used to process a term before indexing or search (e.g. stemming). */
134
+ processTerm?: (term: string, fieldName?: string) => string | string[] | null | undefined | false;
135
+ /** Function called to log messages from the library. */
136
+ logger?: (level: LogLevel, message: string, code?: string) => void;
137
+ /** Auto-vacuum behaviour after {@link MiniSearch.discard}; defaults to `true`. */
138
+ autoVacuum?: boolean | AutoVacuumOptions;
139
+ /** Default search options. */
140
+ searchOptions?: SearchOptions;
141
+ /** Default auto-suggest options. */
142
+ autoSuggestOptions?: SearchOptions;
143
+ };
144
+ /**
145
+ * Canonical `Options<T>` with defaults filled in. Shared by `MiniSearch`,
146
+ * `FrozenMiniSearch`, the frozen builder, and the binary load path so they
147
+ * cannot drift.
148
+ */
149
+ type OptionsWithDefaults<T = any> = Options<T> & {
150
+ storeFields: string[];
151
+ idField: string;
152
+ extractField: (document: T, fieldName: string) => any;
153
+ stringifyField: (fieldValue: any, fieldName: string) => string;
154
+ tokenize: (text: string, fieldName: string) => string[];
155
+ processTerm: (term: string, fieldName: string) => string | string[] | null | undefined | false;
156
+ logger: (level: LogLevel, message: string, code?: string) => void;
157
+ autoVacuum: false | AutoVacuumOptions;
158
+ searchOptions: SearchOptionsWithDefaults;
159
+ autoSuggestOptions: SearchOptions;
160
+ };
161
+ /**
162
+ * A search-completion suggestion.
163
+ */
164
+ type Suggestion = {
165
+ /** The suggested phrase. */
166
+ suggestion: string;
167
+ /** The suggestion as an array of terms. */
168
+ terms: string[];
169
+ /** Score for the suggestion. */
170
+ score: number;
171
+ };
172
+ /**
173
+ * Match information for a search result: keys are terms that matched, values
174
+ * are the list of fields each term was found in.
175
+ */
176
+ type MatchInfo = {
177
+ [term: string]: string[];
178
+ };
179
+ /**
180
+ * A single search result, including the document ID, terms that matched, the
181
+ * match information, the score, and all the stored fields.
182
+ */
183
+ type SearchResult = {
184
+ /** The document ID. */
185
+ id: any;
186
+ /** Document terms that matched (e.g. `"motorcycle"` for prefix `"moto"`). */
187
+ terms: string[];
188
+ /** Query terms that matched (e.g. `"moto"` for prefix `"moto"`). */
189
+ queryTerms: string[];
190
+ /** Score of the search result. */
191
+ score: number;
192
+ /** Match information, see {@link MatchInfo}. */
193
+ match: MatchInfo;
194
+ /** Stored fields are merged onto the result. */
195
+ [key: string]: any;
196
+ };
197
+ /** A boolean combination of sub-queries. */
198
+ type QueryCombination = SearchOptions & {
199
+ queries: Query[];
200
+ };
201
+ /**
202
+ * Wildcard query symbol, used to match all documents.
203
+ * Use {@link FrozenMiniSearch.wildcard}.
204
+ */
205
+ type Wildcard = typeof WILDCARD_QUERY;
206
+ /**
207
+ * Search query expression: a query string, an expression tree combining
208
+ * several queries with `AND`/`OR`/`AND_NOT`, or the wildcard symbol.
209
+ */
210
+ type Query = QueryCombination | string | Wildcard;
211
+ /**
212
+ * Options controlling vacuuming behaviour.
213
+ */
214
+ type VacuumOptions = {
215
+ /** Number of terms traversed per batch. Defaults to 1000. */
216
+ batchSize?: number;
217
+ /** Wait time between batches in milliseconds. Defaults to 10. */
218
+ batchWait?: number;
219
+ };
220
+ /**
221
+ * Minimum thresholds for `dirtCount` and `dirtFactor` triggering an automatic
222
+ * vacuum.
223
+ */
224
+ type VacuumConditions = {
225
+ /** Minimum dirt count; defaults to 20. */
226
+ minDirtCount?: number;
227
+ /** Minimum dirt factor; defaults to 0.1. */
228
+ minDirtFactor?: number;
229
+ };
230
+ /**
231
+ * Options controlling auto-vacuum behaviour. Combines {@link VacuumOptions} and
232
+ * {@link VacuumConditions}.
233
+ */
234
+ type AutoVacuumOptions = VacuumOptions & VacuumConditions;
235
+
236
+ declare const OR: LowercaseCombinationOperator;
237
+ declare const AND: LowercaseCombinationOperator;
238
+ declare const AND_NOT: LowercaseCombinationOperator;
239
+
240
+ /**
241
+ * Smallest unsigned typed array that can hold the structure's indices. Widths
242
+ * are chosen adaptively at build time (`packedIndexArray` in `layout.ts`); reads via
243
+ * `arr[i]` are width-agnostic, so query code never branches on the concrete type.
244
+ */
245
+ type PackedIndexArray = Uint8Array | Uint16Array | Uint32Array;
246
+ type PackedTermRef = {
247
+ termIndex: number;
248
+ length: number;
249
+ };
250
+ type PackedFuzzyRef = PackedTermRef & {
251
+ distance: number;
252
+ };
253
+ /** In-memory packed string radix map (term → payload). */
254
+ interface PackedStringRadixMap<V = number> {
255
+ readonly size: number;
256
+ get(term: string): V | undefined;
257
+ entries(): Iterable<[string, V]>;
258
+ prefixRefs(prefix: string): Iterable<PackedTermRef>;
259
+ /** Lazy generator; see `packedRadixFuzzyRefs` in `fuzzy.ts` for rationale. */
260
+ fuzzyRefs(term: string, maxDistance: number): Iterable<PackedFuzzyRef>;
261
+ termByIndex(termIndex: number): string;
262
+ termLengthByIndex(termIndex: number): number;
263
+ /** @deprecated Internal benchmark/compat wrapper. Prefer `prefixRefs` + `termByIndex`. */
264
+ prefixEntries(prefix: string): Iterable<[string, V]>;
265
+ /**
266
+ * @deprecated Internal benchmark/compat wrapper. Prefer `fuzzyRefs` + `termByIndex`.
267
+ *
268
+ * Fuzzy matches for `term` within `maxDistance` edit distance. Yields every matching
269
+ * `[term, value, distance]`; iteration order is implementation-defined (compare sets, not order).
270
+ */
271
+ fuzzyEntries(term: string, maxDistance: number): Iterable<[string, V, number]>;
272
+ packedByteLength(): number;
273
+ packedNodeCount(): number;
274
+ packedEdgeCount(): number;
275
+ }
276
+ interface PackedRadixTreeData {
277
+ readonly size: number;
278
+ readonly nodeCount: number;
279
+ readonly edgeCount: number;
280
+ readonly labelHeap: string;
281
+ /**
282
+ * CSR edge offsets, length `nodeCount + 1`. Node `n` owns edges
283
+ * `[nodeEdgeOffset[n], nodeEdgeOffset[n + 1])`; the final entry equals
284
+ * `edgeCount`. Replaces the former `nodeFirstEdge`/`nodeEdgeCount` pair: edges
285
+ * are laid out contiguously in node order, so the per-node first index is just
286
+ * the prefix sum of the counts and need not be stored separately.
287
+ */
288
+ readonly nodeEdgeOffset: PackedIndexArray;
289
+ /**
290
+ * Leaf payload per node (term index for a frozen index). Meaningful only when
291
+ * the node has a leaf, i.e. `nodeLeafOrder[n] !== 0`; otherwise the cell is
292
+ * unused (stored as `0`). Width adapts to the largest payload.
293
+ */
294
+ readonly nodeValue: PackedIndexArray;
295
+ /**
296
+ * Leaf slot among a node's siblings, encoded as `slot + 1` with `0` meaning
297
+ * "no leaf". This avoids a wide sentinel: the column adapts to the largest
298
+ * child count instead of forcing `Uint32`. Decode with {@link decodeLeafSlot}.
299
+ */
300
+ readonly nodeLeafOrder: PackedIndexArray;
301
+ readonly edgeLabelStart: PackedIndexArray;
302
+ readonly edgeLabelLength: PackedIndexArray;
303
+ readonly edgeChild: PackedIndexArray;
304
+ }
305
+
306
+ /**
307
+ * Node-indexed parent pointers enabling per-term reconstruction without ever
308
+ * materializing a global path blob. Reconstruction climbs leaf → root in
309
+ * O(depth) and touches only the terms actually requested, which is the whole
310
+ * point of deferring string materialization.
311
+ *
312
+ * - `leafNodeByTermIndex[ti]` is the node carrying term `ti`'s leaf.
313
+ * - `parentNode[node]` is `node`'s parent (root = node `0`, value unused).
314
+ * - `parentEdge[node]` is the edge index linking `parentNode[node]` to `node`.
315
+ *
316
+ * All three are built by cheap linear scans (O(nodeCount + edgeCount)), with no
317
+ * recursion and no per-term allocation, so building them is far cheaper than the
318
+ * former whole-tree DFS + path-edge blob.
319
+ */
320
+ type PackedLazyTermMetadata = {
321
+ leafNodeByTermIndex: PackedIndexArray;
322
+ parentNode: PackedIndexArray;
323
+ parentEdge: PackedIndexArray;
324
+ };
325
+
326
+ declare class PackedRadixTree implements PackedStringRadixMap<number>, PackedRadixTreeData {
327
+ readonly size: number;
328
+ readonly nodeCount: number;
329
+ readonly edgeCount: number;
330
+ readonly labelHeap: string;
331
+ readonly nodeEdgeOffset: PackedIndexArray;
332
+ readonly nodeValue: PackedIndexArray;
333
+ readonly nodeLeafOrder: PackedIndexArray;
334
+ readonly edgeLabelStart: PackedIndexArray;
335
+ readonly edgeLabelLength: PackedIndexArray;
336
+ readonly edgeChild: PackedIndexArray;
337
+ private _lazyTermMetadata;
338
+ private constructor();
339
+ static fromData(data: PackedRadixTreeData): PackedRadixTree;
340
+ private findEdge;
341
+ get(term: string): number | undefined;
342
+ entries(): IterableIterator<[string, number]>;
343
+ /** @deprecated Internal benchmark/compat wrapper. Prefer `prefixRefs` + `termByIndex`. */
344
+ prefixEntries(prefix: string): IterableIterator<[string, number]>;
345
+ prefixRefs(prefix: string): IterableIterator<PackedTermRef>;
346
+ /**
347
+ * Walk `prefix` to the subtree root; returns accumulated heap label prefix string.
348
+ * `null` when no terms share the prefix.
349
+ */
350
+ private resolvePrefixWalk;
351
+ private resolvePrefixWalkRef;
352
+ /**
353
+ * Follow `key` from the root. Shared by exact lookup and prefix iteration.
354
+ * Mid-edge stop uses the full edge label in `prefix` (SearchableMap parity).
355
+ */
356
+ private walkKey;
357
+ /**
358
+ * Depth-first traversal matching {@link SearchableMap}'s `TreeIterator`, which
359
+ * visits siblings in reverse Map-insertion order (last key first). The leaf, if
360
+ * any, sits at `nodeLeafOrder` among the original sibling slots; everything else
361
+ * is an edge. Exact order matters for prefix iteration and autoSuggest parity.
362
+ */
363
+ private emitSubtree;
364
+ private emitSubtreeRefs;
365
+ /** @deprecated Internal benchmark/compat wrapper. Prefer `fuzzyRefs` + `termByIndex`. */
366
+ fuzzyEntries(term: string, maxDistance: number): Iterable<[string, number, number]>;
367
+ fuzzyRefs(term: string, maxDistance: number): Iterable<PackedFuzzyRef>;
368
+ lazyTermMetadata(): PackedLazyTermMetadata;
369
+ termLengthByIndex(termIndex: number): number;
370
+ termByIndex(termIndex: number): string;
371
+ packedByteLength(): number;
372
+ packedNodeCount(): number;
373
+ packedEdgeCount(): number;
374
+ }
375
+
376
+ /** Frozen term index used by {@link FrozenMiniSearch} (packed radix tree). */
377
+ type FrozenTermIndex = PackedRadixTree;
378
+
379
+ type IdLookupMode = 'identity' | 'lazy-map';
380
+ interface IdToShortIdLookup {
381
+ readonly mode: IdLookupMode;
382
+ readonly mapEntryCount: number;
383
+ has(id: unknown): boolean;
384
+ get(id: unknown): number | undefined;
385
+ }
386
+
387
+ type DocIdArray = Uint16Array | Uint32Array;
388
+ /** Adaptive-width unsigned column for term frequencies (u8 or u16; never u32). */
389
+ type FreqArray = Uint8Array | Uint16Array;
390
+
391
+ type FieldIdArray = Uint8Array | Uint16Array;
392
+ type PostingsLayoutKind = 'dense' | 'sparse';
393
+ interface FrozenPostingsLayout {
394
+ fieldCount: number;
395
+ termCount: number;
396
+ nextId: number;
397
+ layout: PostingsLayoutKind;
398
+ docIdWidth: 16 | 32;
399
+ /** Width of sparse field id column; null when layout is dense. */
400
+ sparseFieldIdWidth: 8 | 16 | null;
401
+ allDocIds: DocIdArray;
402
+ allFreqs: FreqArray;
403
+ denseOffsets: Uint32Array | null;
404
+ denseLengths: Uint32Array | null;
405
+ sparseTermStarts: Uint32Array | null;
406
+ sparseFieldIds: FieldIdArray | null;
407
+ sparseOffsets: Uint32Array | null;
408
+ sparseLengths: Uint32Array | null;
409
+ }
410
+
411
+ /** Adaptive-width unsigned column (1/2/4 bytes per element) for field lengths and packed radix columns. */
412
+ type FieldLengthArray = PackedIndexArray;
413
+
414
+ interface FrozenMemoryBreakdown {
415
+ termCount: number;
416
+ documentCount: number;
417
+ nextId: number;
418
+ postings: {
419
+ slotCount: number;
420
+ layout: string;
421
+ docIdWidth: number;
422
+ allDocIdsBytes: number;
423
+ allFreqsBytes: number;
424
+ offsetsBytes: number;
425
+ lengthsBytes: number;
426
+ totalTypedBytes: number;
427
+ };
428
+ radixTree: {
429
+ nodeCount: number;
430
+ edgeCount: number;
431
+ estimatedBytes: number;
432
+ };
433
+ documents: {
434
+ externalIdsSlots: number;
435
+ storedFieldsSlots: number;
436
+ idLookupMode: string;
437
+ idToShortIdEntries: number;
438
+ fieldLengthMatrixBytes: number;
439
+ avgFieldLengthBytes: number;
440
+ storedFieldsJsonBytes: number;
441
+ };
442
+ estimatedStructuredBytes: number;
443
+ }
444
+ /**
445
+ * Low-level parameters for {@link assembleFrozen} (custom frozen index pipelines).
446
+ * Field types are part of the public surface for advanced assembly; typical apps use
447
+ * {@link buildFrozenFromDocuments}, {@link FrozenMiniSearch.fromMiniSearchJson}, or binary load instead.
448
+ */
449
+ interface FrozenAssembleParams<T = any> {
450
+ options: OptionsWithDefaults<T>;
451
+ documentCount: number;
452
+ nextId: number;
453
+ fieldIds: {
454
+ [field: string]: number;
455
+ };
456
+ fieldCount: number;
457
+ externalIds: unknown[];
458
+ idLookup: IdToShortIdLookup;
459
+ storedFields: (Record<string, unknown> | undefined)[];
460
+ fieldLengthMatrix: FieldLengthArray;
461
+ avgFieldLength: Float32Array;
462
+ index: FrozenTermIndex;
463
+ termCount: number;
464
+ postings: FrozenPostingsLayout;
465
+ }
466
+
467
+ /** Lucaong MiniSearch JSON snapshot (`toJSON` / `loadJSON` wire format). */
468
+ type SerializedIndexEntry = Record<string, number>;
469
+ type MiniSearchSnapshot = {
470
+ documentCount: number;
471
+ nextId: number;
472
+ documentIds: {
473
+ [shortId: string]: unknown;
474
+ };
475
+ fieldIds: {
476
+ [fieldName: string]: number;
477
+ };
478
+ fieldLength: {
479
+ [shortId: string]: number[];
480
+ };
481
+ averageFieldLength: number[];
482
+ storedFields: {
483
+ [shortId: string]: Record<string, unknown> | undefined;
484
+ };
485
+ dirtCount?: number;
486
+ index: [string, {
487
+ [fieldId: string]: SerializedIndexEntry | {
488
+ ds: SerializedIndexEntry;
489
+ };
490
+ }][];
491
+ serializationVersion: number;
492
+ };
493
+
494
+ interface FrozenIndexBuilderHints {
495
+ /** Pre-size per-document arrays when the final document count is known. */
496
+ estimatedDocumentCount?: number;
497
+ }
498
+ /** Incremental builder for {@link FrozenMiniSearch} without materializing a full `documents[]` array. */
499
+ declare class FrozenIndexBuilder<T> {
500
+ private readonly _options;
501
+ private readonly _fieldIds;
502
+ private readonly _fieldCount;
503
+ private readonly _index;
504
+ private readonly _terms;
505
+ private readonly _postingsDocIds;
506
+ private readonly _postingsFreqs;
507
+ private readonly _externalIds;
508
+ private readonly _storedFields;
509
+ private readonly _fieldLengthData;
510
+ private readonly _avgFieldLength;
511
+ private readonly _postingsState;
512
+ private readonly _seenIds;
513
+ private _nextId;
514
+ private _frozen;
515
+ constructor(options: Options<T>, hints?: FrozenIndexBuilderHints);
516
+ /** Number of documents indexed so far (not yet frozen). */
517
+ get documentCount(): number;
518
+ add(document: T): void;
519
+ /**
520
+ * Adds all the given documents to the index.
521
+ *
522
+ * @param documents An array of documents to be indexed
523
+ */
524
+ addAll(documents: readonly T[]): void;
525
+ /**
526
+ * Adds all the given documents to the index asynchronously.
527
+ *
528
+ * Returns a promise that resolves (to `undefined`) when the indexing is done.
529
+ * This method is useful when indexing many documents, to avoid blocking the main
530
+ * thread. The indexing is performed asynchronously and in chunks. Finalize with
531
+ * {@link freezeFrozenIndexBuilder} when done.
532
+ *
533
+ * @param documents An array of documents to be indexed
534
+ * @param options Configuration options
535
+ * @return A promise resolving to `undefined` when the indexing is done
536
+ */
537
+ addAllAsync(documents: readonly T[], options?: {
538
+ chunkSize?: number;
539
+ }): Promise<void>;
540
+ /**
541
+ * Finalize this builder into assembly params. Call {@link assembleFrozen} or
542
+ * {@link freezeFrozenIndexBuilder} to obtain a {@link FrozenMiniSearch} instance.
543
+ */
544
+ freezeParams(): FrozenAssembleParams<T>;
545
+ }
546
+ /** Create an incremental builder for {@link FrozenMiniSearch}. */
547
+ declare function createFrozenIndexBuilder<T>(options: Options<T>, hints?: FrozenIndexBuilderHints): FrozenIndexBuilder<T>;
548
+
549
+ declare function frozenMemoryBreakdown(frozen: FrozenMiniSearch): FrozenMemoryBreakdown;
550
+ /** Instantiate {@link FrozenMiniSearch} from pre-built flat index parts (full validation). */
551
+ declare function assembleFrozen<T>(params: FrozenAssembleParams<T>): FrozenMiniSearch<T>;
552
+ declare function buildFrozenFromDocuments<T>(documents: readonly T[], options: Options<T>): FrozenMiniSearch<T>;
553
+ /** Finalize a {@link FrozenIndexBuilder} into a read-only index. */
554
+ declare function freezeFrozenIndexBuilder<T>(builder: FrozenIndexBuilder<T>): FrozenMiniSearch<T>;
555
+ declare class FrozenMiniSearch<T = any> {
556
+ private readonly _options;
557
+ private readonly _index;
558
+ private readonly _documentCount;
559
+ private readonly _nextId;
560
+ private readonly _externalIds;
561
+ private readonly _idLookup;
562
+ private readonly _fieldIds;
563
+ private readonly _fieldCount;
564
+ private readonly _fieldLengthMatrix;
565
+ private readonly _avgFieldLength;
566
+ private readonly _storedFields;
567
+ private readonly _termCount;
568
+ private readonly _postings;
569
+ private readonly _fieldTermFlyweight;
570
+ private readonly _aggregateContext;
571
+ private readonly _queryEngineParams;
572
+ constructor(params: FrozenAssembleParams<T>);
573
+ static readonly wildcard: typeof WILDCARD_QUERY;
574
+ get documentCount(): number;
575
+ get termCount(): number;
576
+ memoryBreakdown(): FrozenMemoryBreakdown;
577
+ has(id: unknown): boolean;
578
+ getStoredFields(id: unknown): Record<string, unknown> | undefined;
579
+ search(query: Query, searchOptions?: SearchOptions): SearchResult[];
580
+ autoSuggest(queryString: string, options?: SearchOptions): Suggestion[];
581
+ /** Serialize this index as a frozen binary snapshot (synchronous). */
582
+ saveBinarySync(): Buffer;
583
+ /** Non-blocking zstd compression; same output as {@link saveBinarySync}. */
584
+ saveBinaryAsync(): Promise<Buffer>;
585
+ /** Load a frozen binary snapshot. */
586
+ static loadBinarySync<T>(buffer: Buffer, options?: Options<T>): FrozenMiniSearch<T>;
587
+ /** Load a frozen binary snapshot with streaming zstd decompression (bounded memory). */
588
+ static loadBinaryAsync<T>(buffer: Buffer, options?: Options<T>): Promise<FrozenMiniSearch<T>>;
589
+ private static fromBinarySnapshot;
590
+ /** Build a read-only index in one pass from documents. */
591
+ static fromDocuments<T>(documents: readonly T[], options: Options<T>): FrozenMiniSearch<T>;
592
+ /**
593
+ * Convert a lucaong MiniSearch JSON snapshot (`toJSON` / `loadJSON` wire format) into a
594
+ * frozen index. No runtime dependency on the `minisearch` package.
595
+ */
596
+ static fromMiniSearchJson<T>(json: string, options?: Options<T>): FrozenMiniSearch<T>;
597
+ /**
598
+ * Same as {@link fromMiniSearchJson} with a pre-parsed snapshot object.
599
+ * `storedFields` are shallow-copied; callers must not mutate nested values
600
+ * after load if they intend to keep the index immutable.
601
+ */
602
+ static fromMiniSearchSnapshot<T>(snapshot: MiniSearchSnapshot, options?: Options<T>): FrozenMiniSearch<T>;
603
+ /** Accepts any object exposing `toJSON()` in lucaong MiniSearch snapshot shape. */
604
+ static fromMiniSearch<T>(source: {
605
+ toJSON(): MiniSearchSnapshot;
606
+ }, options?: Options<T>): FrozenMiniSearch<T>;
607
+ /**
608
+ * Build a read-only index from an async stream of documents (e.g. CSV parser).
609
+ * For sync iterables, use {@link createFrozenIndexBuilder} with `for...of` instead.
610
+ *
611
+ * @param hints Optional builder hints; `estimatedDocumentCount` pre-allocates
612
+ * per-document arrays when the final document count is known upfront.
613
+ */
614
+ static fromAsyncIterable<T>(iterable: AsyncIterable<T>, options: Options<T>, hints?: FrozenIndexBuilderHints): Promise<FrozenMiniSearch<T>>;
615
+ private getFieldLength;
616
+ private executeQuery;
617
+ }
618
+
619
+ export { AND, AND_NOT, FrozenIndexBuilder, OR, assembleFrozen, buildFrozenFromDocuments, createFrozenIndexBuilder, FrozenMiniSearch as default, freezeFrozenIndexBuilder, frozenMemoryBreakdown };
620
+ export type { BM25Params, CombinationOperator, FrozenAssembleParams, FrozenIndexBuilderHints, FrozenMemoryBreakdown, LogLevel, LowercaseCombinationOperator, MatchInfo, MiniSearchSnapshot, Options, Query, QueryCombination, SearchOptions, SearchResult, SerializedIndexEntry, Suggestion, Wildcard };