cry-search 1.0.0 → 1.0.3
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/CLAUDE.md +144 -13
- package/README.md +111 -5
- package/dist/common/SearchUniverse.d.ts.map +1 -1
- package/dist/common/findInLinkedArrays.d.ts +1 -1
- package/dist/common/findInLinkedArrays.d.ts.map +1 -1
- package/dist/common/numeric/AugmentedMetadata.d.ts +111 -0
- package/dist/common/numeric/AugmentedMetadata.d.ts.map +1 -0
- package/dist/common/numeric/findInLinkedArrays.d.ts +1 -1
- package/dist/common/numeric/index.d.ts +3 -0
- package/dist/common/numeric/index.d.ts.map +1 -1
- package/dist/common/numeric/searchInData.d.ts.map +1 -1
- package/dist/common/numeric/syncSearchArrayMetadata.d.ts +64 -0
- package/dist/common/numeric/syncSearchArrayMetadata.d.ts.map +1 -0
- package/dist/common/numeric/updateSearchLinkedMetadata.d.ts +130 -0
- package/dist/common/numeric/updateSearchLinkedMetadata.d.ts.map +1 -0
- package/dist/common/syncSearchArrayMetadata.d.ts +12 -8
- package/dist/common/syncSearchArrayMetadata.d.ts.map +1 -1
- package/dist/common/updateSearchLinkedMetadata.d.ts +26 -16
- package/dist/common/updateSearchLinkedMetadata.d.ts.map +1 -1
- package/dist/index.cjs +265 -490
- package/dist/index.d.cts +3 -9
- package/dist/index.d.ts +3 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +265 -490
- package/dist/string.cjs +922 -0
- package/dist/string.d.cts +26 -0
- package/dist/string.d.ts +26 -0
- package/dist/string.d.ts.map +1 -0
- package/dist/string.js +890 -0
- package/dist/types/index.d.ts +21 -3
- package/dist/types/index.d.ts.map +1 -1
- package/dist/utils/matchTokenNumeric.d.ts +17 -2
- package/dist/utils/matchTokenNumeric.d.ts.map +1 -1
- package/dist/utils/sanitiseString.d.ts +7 -3
- package/dist/utils/sanitiseString.d.ts.map +1 -1
- package/dist/utils/tokenize.d.ts.map +1 -1
- package/package.json +14 -4
package/CLAUDE.md
CHANGED
|
@@ -6,6 +6,17 @@ cry-search is a library for fast searching in large datasets.
|
|
|
6
6
|
1. Bun bundler for development, testing, and bundling
|
|
7
7
|
2. ESM jscript in dist for distribution
|
|
8
8
|
|
|
9
|
+
## Documentation
|
|
10
|
+
|
|
11
|
+
Documentation is spread across multiple files that must be kept in sync:
|
|
12
|
+
|
|
13
|
+
1. [CLAUDE.md](./CLAUDE.md) - Technical specification, types, architecture details
|
|
14
|
+
2. [README.md](./README.md) - User-facing documentation, examples, quick start
|
|
15
|
+
3. [UNIVERSE.md](./UNIVERSE.md) - SearchUniverse multi-collection manager documentation
|
|
16
|
+
4. **JSDoc comments** - Inline documentation in source files (`src/**/*.ts`)
|
|
17
|
+
|
|
18
|
+
**Important:** When updating documentation (types, behavior, API changes), update ALL relevant files together to maintain consistency.
|
|
19
|
+
|
|
9
20
|
## Architecture
|
|
10
21
|
|
|
11
22
|
The library has two implementations:
|
|
@@ -60,15 +71,20 @@ The numeric implementation uses a global token registry (`src/utils/tokenRegistr
|
|
|
60
71
|
3. sanitation
|
|
61
72
|
1. case-insensitive
|
|
62
73
|
2. diacritics-insensitive (č,ć,c -> same c)
|
|
63
|
-
3. we only keep letters (a-z), digits (0-9), periods (
|
|
64
|
-
4. other characters are replaced with space (
|
|
74
|
+
3. we only keep letters (`a-z`), digits (`0-9`), periods (`.`), minuses (`-`), tildes (`~`), query prefixes (`<>+*!=?`), spaces (` `) in search
|
|
75
|
+
4. other characters are replaced with space (` `)
|
|
65
76
|
2. tokenization
|
|
66
77
|
1. we split strings on spaces
|
|
67
78
|
2. then we trim all substrings
|
|
68
79
|
3. matching
|
|
69
80
|
1. we match words in any order
|
|
70
|
-
2.
|
|
71
|
-
1.
|
|
81
|
+
2. number matching depends on TARGET token length (not query length):
|
|
82
|
+
1. short numbers (≤6 digits in target): whole match only
|
|
83
|
+
- eg. query "123" vs target "123" → match
|
|
84
|
+
- eg. query "12" vs target "123" → no match (target is short, needs exact)
|
|
85
|
+
2. long numbers (>6 digits in target): startEnd match
|
|
86
|
+
- eg. query "60731" vs target "3838989760731" → match (13-digit barcode)
|
|
87
|
+
- eg. query "989" vs target "3838989760731" → no match (not at start/end)
|
|
72
88
|
4. nested data extraction
|
|
73
89
|
1. nested objects and arrays are automatically extracted recursively
|
|
74
90
|
2. Date objects are converted to ISO strings before tokenization
|
|
@@ -114,6 +130,32 @@ The numeric implementation uses a global token registry (`src/utils/tokenRegistr
|
|
|
114
130
|
4. example use case
|
|
115
131
|
1. search "krajnik angie" matches stranka "Krajnik" with pacient "Angie"
|
|
116
132
|
2. returns: { primary: Stranka, secondaries: [matching Pacient], matchedIn: 'both' }
|
|
133
|
+
9. augmented metadata
|
|
134
|
+
1. purpose: add local/temporary searchable data to existing metadata without modifying the base metadata
|
|
135
|
+
2. use case: search for items combined with page-specific data (e.g., match status, local flags, computed properties)
|
|
136
|
+
3. class AugmentedMetadata
|
|
137
|
+
1. wraps existing NumericSearchMetadata
|
|
138
|
+
2. allows adding additional search tokens dynamically
|
|
139
|
+
3. memory efficient: items without augmentation reuse original Uint32Array
|
|
140
|
+
4. items with augmentation get merged sorted token array (base + augmented)
|
|
141
|
+
5. constructor takes: baseMetadata, optional spec, optional initial augmented data
|
|
142
|
+
6. spec controls tokenization: searchInFields, fieldMatchModes, etc.
|
|
143
|
+
4. updating augmented data
|
|
144
|
+
1. updateAugmented(id, obj) - single item update
|
|
145
|
+
2. updateAugmentedBatch(map) - batch update (more efficient)
|
|
146
|
+
3. clearAugmented(id) - remove augmentation for one item
|
|
147
|
+
4. clearAllAugmented() - remove all augmentations
|
|
148
|
+
5. searching
|
|
149
|
+
1. implements NumericSearchMetadata interface
|
|
150
|
+
2. works with all search functions (searchInDataReturnIds, etc.)
|
|
151
|
+
3. combines base + augmented tokens during search
|
|
152
|
+
4. supports all query prefixes and match modes
|
|
153
|
+
6. example use case
|
|
154
|
+
1. global zdravila metadata with names, manufacturers
|
|
155
|
+
2. page-local augmented metadata adds "uparjen"/"neuparjen" status
|
|
156
|
+
3. search "aspirin uparjen" finds Aspirin items with "uparjen" status
|
|
157
|
+
4. updating status doesn't modify global metadata
|
|
158
|
+
5. removing augmentation reverts to base metadata only
|
|
117
159
|
|
|
118
160
|
## Types
|
|
119
161
|
|
|
@@ -135,7 +177,16 @@ The numeric implementation uses a global token registry (`src/utils/tokenRegistr
|
|
|
135
177
|
10. MatchMode: 'start' | 'end' | 'startEnd' | 'anywhere' | 'whole'
|
|
136
178
|
1. Field token prefixes: '<' (start), '>' (end), '+' (startEnd), '*' (anywhere), '!' (whole)
|
|
137
179
|
2. Numeric: encoded in high 3 bits of Uint32 token ID
|
|
138
|
-
11.
|
|
180
|
+
11. SearchOpts:
|
|
181
|
+
1. matchWords?: MatchMode (default: 'start') - how to match words
|
|
182
|
+
2. matchNumbers?: MatchMode (default: 'startEnd') - how to match long numbers (>threshold digits)
|
|
183
|
+
3. matchNumbersShort?: MatchMode (default: 'whole') - how to match short numbers (≤threshold digits)
|
|
184
|
+
4. matchNumbersThreshold?: number (default: 6) - digit count threshold for short vs long
|
|
185
|
+
12. LinkedSearchResultWithMeta<TPrimary, TLinked>:
|
|
186
|
+
1. queryTokens: string[] - tokenized query
|
|
187
|
+
2. results: LinkedSearchResult[] - matching results
|
|
188
|
+
3. hasNegation: boolean - whether query contains negated tokens
|
|
189
|
+
13. SearchableLinkedObjectsSpec: primary SearchableObjectSpec, linked SearchableObjectSpec, foreignKeyGetter
|
|
139
190
|
|
|
140
191
|
## Search Query Prefixes
|
|
141
192
|
|
|
@@ -148,8 +199,11 @@ Override match behavior per token at search time. Priority: query prefix > field
|
|
|
148
199
|
| `..word` | end | Match tokens ending with word | `..Pro` matches "MacBookPro" |
|
|
149
200
|
| `=word` | whole | Exact match only | `=jan` matches "jan" not "jana" |
|
|
150
201
|
| `?word` | anywhere | Match word anywhere in token | `?book` matches "MacBook" |
|
|
151
|
-
|
|
|
152
|
-
|
|
|
202
|
+
| `-word` | negation | Exclude results containing word (letter after -) | `apple -iphone` excludes iPhones |
|
|
203
|
+
| `--word` | negation | Exclude (works for words and numbers) | `--123` excludes items with "123" |
|
|
204
|
+
| `~word` | negation | Exclude (works for words and numbers) | `~iphone` or `~123` |
|
|
205
|
+
|
|
206
|
+
**Note:** `-5` is NOT negation (it's a negative number). Use `--5` or `~5` to negate numbers.
|
|
153
207
|
|
|
154
208
|
### Programmatic prefixes
|
|
155
209
|
| Prefix | Mode |
|
|
@@ -161,11 +215,14 @@ Override match behavior per token at search time. Priority: query prefix > field
|
|
|
161
215
|
| `!word` | whole |
|
|
162
216
|
|
|
163
217
|
### Examples
|
|
164
|
-
1. `"jana useni"` → finds "jana usenik" (default
|
|
218
|
+
1. `"jana useni"` → finds "jana usenik" (default start matching for words)
|
|
165
219
|
2. `"jana =useni"` → no match (whole match required, "useni" ≠ "usenik")
|
|
166
|
-
3. `"jana
|
|
167
|
-
4. `"
|
|
168
|
-
5. `"..
|
|
220
|
+
3. `"jana -macka"` → finds "jana" but excludes any result containing "macka"
|
|
221
|
+
4. `"krajnik --cat"` → finds "krajnik" but excludes linked items with "cat" (mačke)
|
|
222
|
+
5. `"APL.."` → finds all tokens starting with "APL" (APL-IP15P, APL-MBP16)
|
|
223
|
+
6. `"..nik"` → finds tokens ending with "nik" (usenik, krajnik)
|
|
224
|
+
7. `"60731"` → finds barcode "3838989760731" (13-digit target uses startEnd)
|
|
225
|
+
8. `"=9001"` → finds exact "9001" but NOT "035585249001" or "9001917"
|
|
169
226
|
|
|
170
227
|
|
|
171
228
|
## Main Functions (Default = Numeric)
|
|
@@ -191,6 +248,54 @@ Override match behavior per token at search time. Priority: query prefix > field
|
|
|
191
248
|
8. updateSearchMetadataBatch(metadata, batch, spec)
|
|
192
249
|
1. creates temporary tokensMap, clears after use
|
|
193
250
|
2. updates or deletes metadata for batch of objects
|
|
251
|
+
9. syncSearchArrayMetadata(metadata, newData, spec?)
|
|
252
|
+
1. syncs metadata with new data (inkrementalno posodabljanje)
|
|
253
|
+
2. adds new items, updates changed items, removes old items
|
|
254
|
+
3. compares token arrays - skips unchanged items (performance optimization)
|
|
255
|
+
4. more efficient than full rebuild for partial updates
|
|
256
|
+
5. uses single tokensMap for all operations (memory efficient)
|
|
257
|
+
10. syncSearchArrayMetadataWithPrevious(metadata, previousData, newData, options?, spec?)
|
|
258
|
+
1. more efficient than syncSearchArrayMetadata when you have both datasets
|
|
259
|
+
2. uses previousData to determine removals (no metadata.keys() iteration)
|
|
260
|
+
3. skipUpdateCheck option - skip checking for updates (even faster)
|
|
261
|
+
4. best for regular refresh cycles (e.g., every 30s from server)
|
|
262
|
+
11. AugmentedMetadata class
|
|
263
|
+
1. constructor(baseMetadata, spec?, augmentedDataMap?)
|
|
264
|
+
1. baseMetadata: NumericSearchMetadata - base metadata to wrap (not modified)
|
|
265
|
+
2. spec?: SearchableObjectSpec - controls tokenization of augmented objects
|
|
266
|
+
3. augmentedDataMap?: Map<Id, any> - optional initial augmented data
|
|
267
|
+
2. updateAugmented(id, obj) - add/update augmented data for one item
|
|
268
|
+
3. updateAugmentedBatch(map) - batch update (more efficient than multiple single updates)
|
|
269
|
+
4. clearAugmented(id) - remove augmentation for one item
|
|
270
|
+
5. clearAllAugmented() - remove all augmentations
|
|
271
|
+
6. implements NumericSearchMetadata interface (get, has, size, keys, values, entries, forEach)
|
|
272
|
+
7. Map mutation methods (set, delete, clear) throw errors - use update methods instead
|
|
273
|
+
12. Linked metadata update functions (incremental updates to linked metadata)
|
|
274
|
+
1. upsertPrimaryItem(linked, item, spec?)
|
|
275
|
+
1. adds or updates a primary item in linked metadata
|
|
276
|
+
2. updates primaryData, primaryMeta, and initializes primaryToLinked index
|
|
277
|
+
3. handles _deleted/_blocked by removing metadata
|
|
278
|
+
4. returns { added: boolean } - true if item was new
|
|
279
|
+
2. removePrimaryItem(linked, primaryId)
|
|
280
|
+
1. removes primary item from data, metadata, and primaryToLinked index
|
|
281
|
+
2. does NOT remove linked items (they become orphans)
|
|
282
|
+
3. returns true if found and removed, false otherwise
|
|
283
|
+
3. upsertLinkedItem(linked, item, foreignKeyGetter, spec?)
|
|
284
|
+
1. adds or updates a linked item in linked metadata
|
|
285
|
+
2. updates linkedData, linkedMeta, and primaryToLinked index
|
|
286
|
+
3. handles foreign key changes (moves item between primaries)
|
|
287
|
+
4. handles _deleted/_blocked by removing metadata
|
|
288
|
+
5. returns { added: boolean, previousPrimaryId?: Id }
|
|
289
|
+
4. removeLinkedItem(linked, linkedId, foreignKeyGetter)
|
|
290
|
+
1. removes linked item from data, metadata, and primaryToLinked index
|
|
291
|
+
2. returns true if found and removed, false otherwise
|
|
292
|
+
5. syncLinkedItemsForPrimary(linked, primaryId, newLinkedItems, foreignKeyGetter, spec?)
|
|
293
|
+
1. full sync of linked items for a single primary
|
|
294
|
+
2. removes items not in newLinkedItems
|
|
295
|
+
3. updates items with changed tokens
|
|
296
|
+
4. adds new items
|
|
297
|
+
5. only processes items whose foreign key matches primaryId
|
|
298
|
+
6. returns { added: number, updated: number, removed: number }
|
|
194
299
|
|
|
195
300
|
## Token Registry Functions
|
|
196
301
|
|
|
@@ -206,15 +311,38 @@ Override match behavior per token at search time. Priority: query prefix > field
|
|
|
206
311
|
|
|
207
312
|
## String Implementation (Legacy)
|
|
208
313
|
|
|
209
|
-
|
|
314
|
+
The string-based implementation is available as a separate entry point for backwards compatibility.
|
|
315
|
+
|
|
316
|
+
**Import from `cry-search/string`:**
|
|
317
|
+
```typescript
|
|
318
|
+
import {
|
|
319
|
+
createSearchArrayMetadataString,
|
|
320
|
+
updateSearchMetadataString,
|
|
321
|
+
findInArray,
|
|
322
|
+
// ... other string-based functions
|
|
323
|
+
} from 'cry-search/string';
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
**Available functions with `*String` suffix:**
|
|
210
327
|
- createSearchArrayMetadataString
|
|
211
328
|
- createSearchLinkedMetadataString
|
|
212
329
|
- updateSearchMetadataString
|
|
213
330
|
- updateSearchMetadataBatchString
|
|
331
|
+
- syncSearchArrayMetadataString
|
|
332
|
+
- syncSearchArrayMetadataStringWithPrevious
|
|
333
|
+
- upsertPrimaryItemString
|
|
334
|
+
- removePrimaryItemString
|
|
335
|
+
- upsertLinkedItemString
|
|
336
|
+
- removeLinkedItemString
|
|
337
|
+
- syncLinkedItemsForPrimaryString
|
|
214
338
|
- findInArray (uses string metadata)
|
|
215
339
|
- findInArrayReturnDataAndMeta
|
|
216
340
|
- findInLinkedArrays
|
|
217
341
|
|
|
342
|
+
**Bundle sizes:**
|
|
343
|
+
- Main bundle (`cry-search`): ~49 KB - includes only numeric implementation
|
|
344
|
+
- String bundle (`cry-search/string`): ~26 KB - includes only string implementation
|
|
345
|
+
|
|
218
346
|
## File Structure
|
|
219
347
|
|
|
220
348
|
```
|
|
@@ -225,7 +353,10 @@ src/
|
|
|
225
353
|
│ │ ├── createSearchArrayMetadata.ts
|
|
226
354
|
│ │ ├── createSearchLinkedMetadata.ts
|
|
227
355
|
│ │ ├── updateSearchMetadata.ts
|
|
228
|
-
│ │
|
|
356
|
+
│ │ ├── updateSearchLinkedMetadata.ts
|
|
357
|
+
│ │ ├── searchInData.ts
|
|
358
|
+
│ │ ├── syncSearchArrayMetadata.ts
|
|
359
|
+
│ │ └── AugmentedMetadata.ts
|
|
229
360
|
│ ├── string/ # Legacy string implementation
|
|
230
361
|
│ │ ├── index.ts
|
|
231
362
|
│ │ ├── createSearchArrayMetadata.ts
|
package/README.md
CHANGED
|
@@ -7,8 +7,9 @@ A fast, memory-efficient search library for large datasets with support for toke
|
|
|
7
7
|
- **Fast search** - Pre-built metadata enables instant queries on large datasets
|
|
8
8
|
- **Memory efficient** - Numeric token storage uses ~45% less memory than string-based approaches
|
|
9
9
|
- **Updatable** - Add, update, or remove items without rebuilding metadata
|
|
10
|
+
- **Augmented metadata** - Add local/temporary searchable data without modifying global metadata
|
|
10
11
|
- **Flexible matching** - Per-field match modes and query prefixes for prefix, suffix, anywhere, exact, and negation
|
|
11
|
-
- **Search
|
|
12
|
+
- **Search prefixes** - use `-word`, `--word`, or `~word` to exclude, `..word` for suffix, `=word` for exact match
|
|
12
13
|
- **Automatic normalization** - Handles diacritics, case, dates, and number formatting
|
|
13
14
|
- **[Universal search](./UNIVERSE.md)** - Search and update across linked collections (e.g., customers with their pets)
|
|
14
15
|
|
|
@@ -22,6 +23,7 @@ A fast, memory-efficient search library for large datasets with support for toke
|
|
|
22
23
|
- [Single Table Search](#single-table-search)
|
|
23
24
|
- [SearchUniverse with Linked Collections](#searchuniverse-with-linked-collections)
|
|
24
25
|
- [Updating Existing Data](#updating-existing-data)
|
|
26
|
+
- [Augmented Metadata - Local Search Context](#augmented-metadata---local-search-context)
|
|
25
27
|
- [Architecture](#architecture)
|
|
26
28
|
- [Text Processing Pipeline](#text-processing-pipeline)
|
|
27
29
|
- [Metadata Building](#metadata-building)
|
|
@@ -196,6 +198,86 @@ universe.updateSearchMetadata('pacienti', 'p1', {
|
|
|
196
198
|
});
|
|
197
199
|
```
|
|
198
200
|
|
|
201
|
+
### Augmented Metadata - Local Search Context
|
|
202
|
+
|
|
203
|
+
Sometimes you need to search items combined with page-specific data (like match status, local flags, computed properties) without modifying the global metadata. `AugmentedMetadata` wraps existing metadata and allows adding temporary searchable data.
|
|
204
|
+
|
|
205
|
+
```typescript
|
|
206
|
+
import {
|
|
207
|
+
createSearchArrayMetadata,
|
|
208
|
+
searchInDataReturnIds,
|
|
209
|
+
AugmentedMetadata,
|
|
210
|
+
arrayToSearchableData,
|
|
211
|
+
type SearchableObject,
|
|
212
|
+
} from 'cry-search';
|
|
213
|
+
|
|
214
|
+
interface Medicine extends SearchableObject {
|
|
215
|
+
_id: string;
|
|
216
|
+
name: string;
|
|
217
|
+
manufacturer: string;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// Global data - shared across application
|
|
221
|
+
const medicines: Medicine[] = [
|
|
222
|
+
{ _id: '1', name: 'Aspirin', manufacturer: 'Bayer' },
|
|
223
|
+
{ _id: '2', name: 'Paracetamol', manufacturer: 'Krka' },
|
|
224
|
+
{ _id: '3', name: 'Ibuprofen', manufacturer: 'Lek' },
|
|
225
|
+
];
|
|
226
|
+
|
|
227
|
+
const data = arrayToSearchableData(medicines);
|
|
228
|
+
const globalMetadata = createSearchArrayMetadata(data);
|
|
229
|
+
|
|
230
|
+
// Page-specific: matching medicines with external registry
|
|
231
|
+
// Create augmented metadata with local match status
|
|
232
|
+
const augmented = new AugmentedMetadata(
|
|
233
|
+
globalMetadata,
|
|
234
|
+
{ searchInFields: ['status', 'notes'] } // Control which fields to index
|
|
235
|
+
);
|
|
236
|
+
|
|
237
|
+
// User matches medicines with external registry
|
|
238
|
+
augmented.updateAugmented('1', { status: 'matched', notes: 'verified' });
|
|
239
|
+
augmented.updateAugmented('2', { status: 'unmatched', notes: '' });
|
|
240
|
+
augmented.updateAugmented('3', { status: 'matching in progress', notes: 'awaiting approval' });
|
|
241
|
+
|
|
242
|
+
// Search by base data + augmented status
|
|
243
|
+
const matchedAspirin = searchInDataReturnIds('aspirin matched', augmented);
|
|
244
|
+
// Returns: ['1']
|
|
245
|
+
|
|
246
|
+
const unmatchedItems = searchInDataReturnIds('unmatched', augmented);
|
|
247
|
+
// Returns: ['2']
|
|
248
|
+
|
|
249
|
+
const inProgress = searchInDataReturnIds('progress', augmented);
|
|
250
|
+
// Returns: ['3']
|
|
251
|
+
|
|
252
|
+
// Search with negation
|
|
253
|
+
const notMatched = searchInDataReturnIds('bayer -matched', augmented);
|
|
254
|
+
// Returns: [] (Bayer Aspirin is matched)
|
|
255
|
+
|
|
256
|
+
// Batch update for efficiency
|
|
257
|
+
augmented.updateAugmentedBatch(new Map([
|
|
258
|
+
['1', { status: 'matched', notes: 'final' }],
|
|
259
|
+
['2', { status: 'matched', notes: 'approved' }],
|
|
260
|
+
['3', undefined], // Remove augmentation
|
|
261
|
+
]));
|
|
262
|
+
|
|
263
|
+
// Clear specific item
|
|
264
|
+
augmented.clearAugmented('1'); // Reverts to global metadata only
|
|
265
|
+
|
|
266
|
+
// Clear all augmentations
|
|
267
|
+
augmented.clearAllAugmented(); // Reset to global state
|
|
268
|
+
|
|
269
|
+
// AugmentedMetadata is memory efficient:
|
|
270
|
+
// - Items without augmentation reuse original Uint32Array (no memory duplication)
|
|
271
|
+
// - Items with augmentation get merged sorted token array (base + augmented)
|
|
272
|
+
// - Global metadata remains unchanged
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
**Use cases:**
|
|
276
|
+
- Medicine matching with external registries (matched/unmatched status)
|
|
277
|
+
- Products with local pricing or availability flags
|
|
278
|
+
- Documents with review status or approval state
|
|
279
|
+
- Items with computed scores or temporary categories
|
|
280
|
+
|
|
199
281
|
## Architecture
|
|
200
282
|
|
|
201
283
|
cry-search uses a two-phase approach: **build** metadata once, then **search** instantly.
|
|
@@ -237,7 +319,13 @@ Override match behavior per token at search time using prefixes:
|
|
|
237
319
|
| `..word` | end | Match tokens ending with "word" |
|
|
238
320
|
| `=word` | whole | Exact match only |
|
|
239
321
|
| `?word` | anywhere | Match "word" anywhere in token |
|
|
240
|
-
|
|
|
322
|
+
| `-word` | negation | Exclude results (only when followed by letter) |
|
|
323
|
+
| `--word` | negation | Exclude results (works for words and numbers) |
|
|
324
|
+
| `~word` | negation | Exclude results (works for words and numbers) |
|
|
325
|
+
|
|
326
|
+
**Note:** `-5` is NOT negation (it's a negative number). Use `--5` or `~5` to negate numbers.
|
|
327
|
+
|
|
328
|
+
**Detecting negation:** Linked search results include a `hasNegation: boolean` flag indicating if the query contained negation tokens.
|
|
241
329
|
|
|
242
330
|
Alternative prefixes (for programmatic use): `<word` (start), `>word` (end), `+word` (startEnd), `*word` (anywhere), `!word` (whole)
|
|
243
331
|
|
|
@@ -247,28 +335,46 @@ searchInDataReturnObjects('jana =usenik', metadata, data);
|
|
|
247
335
|
// Matches "Jana Usenik" but not "Jana Useniker"
|
|
248
336
|
|
|
249
337
|
// Find "apple" but exclude results containing "iphone"
|
|
250
|
-
searchInDataReturnObjects('apple
|
|
338
|
+
searchInDataReturnObjects('apple -iphone', metadata, data);
|
|
251
339
|
// Matches MacBook Pro but not iPhone
|
|
252
340
|
|
|
253
341
|
// Find products with SKU starting with "APL"
|
|
254
342
|
searchInDataReturnObjects('APL..', metadata, data);
|
|
255
343
|
// Matches APL-IP15P, APL-MBP16, etc.
|
|
344
|
+
|
|
345
|
+
// Find exact barcode code
|
|
346
|
+
searchInDataReturnObjects('=9001', metadata, data);
|
|
347
|
+
// Matches "9001" but NOT "035585249001" or "9001917"
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
### Number Matching
|
|
351
|
+
|
|
352
|
+
Match mode for numbers is determined by the **target token's length** (not the query):
|
|
353
|
+
- **Short numbers (≤6 digits)**: require exact (whole) match
|
|
354
|
+
- **Long numbers (>6 digits)**: allow start or end match (for barcodes)
|
|
355
|
+
|
|
356
|
+
```typescript
|
|
357
|
+
// Query "60731" against barcode "3838989760731" (13 digits) → MATCH (ends with 60731)
|
|
358
|
+
// Query "123" against code "123" (3 digits) → MATCH (exact)
|
|
359
|
+
// Query "12" against code "123" (3 digits) → NO MATCH (short number needs exact)
|
|
256
360
|
```
|
|
257
361
|
|
|
258
362
|
Priority: query prefix > field match mode > global SearchOpts default.
|
|
259
363
|
|
|
260
364
|
## Legacy String Implementation
|
|
261
365
|
|
|
262
|
-
A string-based implementation is available for backwards compatibility. Import
|
|
366
|
+
A string-based implementation is available for backwards compatibility. Import from the `/string` subpath:
|
|
263
367
|
|
|
264
368
|
```typescript
|
|
265
369
|
import {
|
|
266
370
|
createSearchArrayMetadataString,
|
|
267
371
|
updateSearchMetadataString,
|
|
268
372
|
findInArray, // String-based search function
|
|
269
|
-
} from 'cry-search';
|
|
373
|
+
} from 'cry-search/string';
|
|
270
374
|
```
|
|
271
375
|
|
|
376
|
+
The string implementation is excluded from the main bundle. The default import (`cry-search`) only includes the modern numeric implementation, keeping bundle sizes smaller.
|
|
377
|
+
|
|
272
378
|
## Specification
|
|
273
379
|
|
|
274
380
|
See [CLAUDE.md](./CLAUDE.md) for the complete technical specification including:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SearchUniverse.d.ts","sourceRoot":"","sources":["../../src/common/SearchUniverse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,EAAE,EACF,qBAAqB,EACrB,cAAc,EACd,gBAAgB,EAEhB,mBAAmB,EACnB,gBAAgB,EAChB,YAAY,EACZ,iBAAiB,EAClB,MAAM,UAAU,CAAC;AAWlB,YAAY,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAcvG;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,WAAW,CAAiC;IAEpD;;;;;OAKG;IACH,kBAAkB,CAAC,CAAC,SAAS,gBAAgB,EAAE,CAAC,GAAG,OAAO,EACxD,IAAI,EAAE,MAAM,EACZ,MAAM,GAAE,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAM,GAClC,IAAI;IAmBP;;;;;OAKG;IACH,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAIpC;;;;OAIG;IACH,kBAAkB,IAAI,MAAM,EAAE;IAI9B;;;;;;OAMG;IACH,cAAc,CAAC,CAAC,SAAS,gBAAgB,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,IAAI;IAsC1E;;;;;;;OAOG;IACH,OAAO,CAAC,CAAC,SAAS,gBAAgB,EAAE,cAAc,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,GAAG,CAAC,GAAG,SAAS;IAKlF;;;;;;OAMG;IACH,QAAQ,CAAC,CAAC,SAAS,gBAAgB,EAAE,cAAc,EAAE,MAAM,GAAG,CAAC,EAAE;IAKjE;;;;;OAKG;IACH,iBAAiB,CAAC,cAAc,EAAE,MAAM,GAAG,MAAM;IAKjD;;;;;OAKG;IACH,WAAW,CAAC,cAAc,EAAE,MAAM,GAAG,qBAAqB;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LinkedSearchResultWithMeta } from '../types';
|
|
|
20
20
|
* @param linked - Linked metadata from {@link createSearchLinkedMetadata}
|
|
21
21
|
* @param limit - Maximum number of results to return (default: 10)
|
|
22
22
|
* @param opts - Optional search options for controlling match behavior
|
|
23
|
-
* @returns Search results with query tokens and
|
|
23
|
+
* @returns Search results with query tokens, matching items, and hasNegation flag
|
|
24
24
|
*
|
|
25
25
|
* @example
|
|
26
26
|
* ```typescript
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"findInLinkedArrays.d.ts","sourceRoot":"","sources":["../../src/common/findInLinkedArrays.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,gBAAgB,EAChB,UAAU,EACV,kBAAkB,EAClB,0BAA0B,EAC1B,4BAA4B,EAC7B,MAAM,UAAU,CAAC;AAKlB,YAAY,EAAE,kBAAkB,EAAE,0BAA0B,EAAE,MAAM,UAAU,CAAC;AAE/E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,wBAAgB,kBAAkB,CAChC,QAAQ,SAAS,gBAAgB,EACjC,OAAO,SAAS,gBAAgB,EAEhC,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,4BAA4B,CAAC,QAAQ,EAAE,OAAO,CAAC,EACvD,KAAK,GAAE,MAAW,EAClB,IAAI,CAAC,EAAE,UAAU,GAChB,0BAA0B,CAAC,QAAQ,EAAE,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"findInLinkedArrays.d.ts","sourceRoot":"","sources":["../../src/common/findInLinkedArrays.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,gBAAgB,EAChB,UAAU,EACV,kBAAkB,EAClB,0BAA0B,EAC1B,4BAA4B,EAC7B,MAAM,UAAU,CAAC;AAKlB,YAAY,EAAE,kBAAkB,EAAE,0BAA0B,EAAE,MAAM,UAAU,CAAC;AAE/E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,wBAAgB,kBAAkB,CAChC,QAAQ,SAAS,gBAAgB,EACjC,OAAO,SAAS,gBAAgB,EAEhC,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,4BAA4B,CAAC,QAAQ,EAAE,OAAO,CAAC,EACvD,KAAK,GAAE,MAAW,EAClB,IAAI,CAAC,EAAE,UAAU,GAChB,0BAA0B,CAAC,QAAQ,EAAE,OAAO,CAAC,CAgG/C;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,wBAAwB,CACtC,QAAQ,SAAS,gBAAgB,EACjC,OAAO,SAAS,gBAAgB,EAEhC,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,4BAA4B,CAAC,QAAQ,EAAE,OAAO,CAAC,EACvD,KAAK,GAAE,MAAW,EAClB,IAAI,CAAC,EAAE,UAAU,GAChB,kBAAkB,CAAC,QAAQ,EAAE,OAAO,CAAC,EAAE,CAEzC"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import type { Id, NumericSearchMetadata, NumericTokenSortedList, SearchableObjectSpec } from '../../types/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* AugmentedMetadata wraps existing NumericSearchMetadata and allows adding
|
|
4
|
+
* additional search tokens dynamically without modifying the base metadata.
|
|
5
|
+
*
|
|
6
|
+
* Use case: Add local/temporary data (e.g., "uparjen"/"neuparjen" status) to
|
|
7
|
+
* existing global metadata for searching.
|
|
8
|
+
*
|
|
9
|
+
* Items without augmentation reuse the original Uint32Array (no memory duplication).
|
|
10
|
+
* Items with augmentation get a merged sorted token array.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* const augmented = new AugmentedMetadata(zdravilaMeta, { searchInFields: ['status', 'notes'] });
|
|
14
|
+
* augmented.updateAugmented(id1, { status: "uparjen", notes: "v teku" });
|
|
15
|
+
* augmented.updateAugmented(id2, { status: "neuparjen" });
|
|
16
|
+
*
|
|
17
|
+
* // Now search works with augmented tokens
|
|
18
|
+
* const results = searchInDataReturnIds("aspirin uparjen", augmented);
|
|
19
|
+
*/
|
|
20
|
+
export declare class AugmentedMetadata implements NumericSearchMetadata {
|
|
21
|
+
private baseMetadata;
|
|
22
|
+
private augmentedTokens;
|
|
23
|
+
private spec;
|
|
24
|
+
/**
|
|
25
|
+
* @param baseMetadata - Base search metadata (not modified)
|
|
26
|
+
* @param spec - Optional spec for tokenizing augmented objects (searchInFields, fieldMatchModes, etc.)
|
|
27
|
+
* @param augmentedDataMap - Optional initial augmented data map (id -> object)
|
|
28
|
+
*/
|
|
29
|
+
constructor(baseMetadata: NumericSearchMetadata, spec?: SearchableObjectSpec<any>, augmentedDataMap?: Map<Id, any>);
|
|
30
|
+
/**
|
|
31
|
+
* Update augmented data for a single item.
|
|
32
|
+
* Pass undefined to remove augmentation for this item.
|
|
33
|
+
*
|
|
34
|
+
* @param id - Item ID
|
|
35
|
+
* @param augmentedData - Additional searchable object (will be tokenized using spec)
|
|
36
|
+
*/
|
|
37
|
+
updateAugmented(id: Id, augmentedData: any): void;
|
|
38
|
+
/**
|
|
39
|
+
* Batch update augmented data for multiple items.
|
|
40
|
+
* More efficient than calling updateAugmented multiple times.
|
|
41
|
+
*
|
|
42
|
+
* @param augmentedDataMap - Map of id -> augmented object (will be tokenized using spec)
|
|
43
|
+
*/
|
|
44
|
+
updateAugmentedBatch(augmentedDataMap: Map<Id, any>): void;
|
|
45
|
+
/**
|
|
46
|
+
* Remove augmentation for a single item (reverts to base metadata only).
|
|
47
|
+
*/
|
|
48
|
+
clearAugmented(id: Id): void;
|
|
49
|
+
/**
|
|
50
|
+
* Remove all augmentations (reverts to base metadata for all items).
|
|
51
|
+
*/
|
|
52
|
+
clearAllAugmented(): void;
|
|
53
|
+
/**
|
|
54
|
+
* Get merged tokens for an item (base + augmented).
|
|
55
|
+
* Returns undefined if item doesn't exist in base metadata.
|
|
56
|
+
*/
|
|
57
|
+
get(id: Id): NumericTokenSortedList | undefined;
|
|
58
|
+
/**
|
|
59
|
+
* Check if item exists in base metadata.
|
|
60
|
+
*/
|
|
61
|
+
has(id: Id): boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Get number of items in base metadata.
|
|
64
|
+
*/
|
|
65
|
+
get size(): number;
|
|
66
|
+
/**
|
|
67
|
+
* Iterate over all items (id -> merged tokens).
|
|
68
|
+
*/
|
|
69
|
+
[Symbol.iterator](): MapIterator<[Id, NumericTokenSortedList]>;
|
|
70
|
+
/**
|
|
71
|
+
* Iterate over all IDs.
|
|
72
|
+
*/
|
|
73
|
+
keys(): MapIterator<Id>;
|
|
74
|
+
/**
|
|
75
|
+
* Iterate over all merged token arrays.
|
|
76
|
+
*/
|
|
77
|
+
values(): MapIterator<NumericTokenSortedList>;
|
|
78
|
+
/**
|
|
79
|
+
* Iterate over all [id, merged tokens] entries.
|
|
80
|
+
*/
|
|
81
|
+
entries(): MapIterator<[Id, NumericTokenSortedList]>;
|
|
82
|
+
/**
|
|
83
|
+
* Execute callback for each item.
|
|
84
|
+
*/
|
|
85
|
+
forEach(callbackfn: (value: NumericTokenSortedList, key: Id, map: Map<Id, NumericTokenSortedList>) => void): void;
|
|
86
|
+
/**
|
|
87
|
+
* Not supported - this is a read-only wrapper.
|
|
88
|
+
* Use updateAugmented() or updateAugmentedBatch() instead.
|
|
89
|
+
*/
|
|
90
|
+
set(_key: Id, _value: NumericTokenSortedList): this;
|
|
91
|
+
/**
|
|
92
|
+
* Not supported - this is a read-only wrapper.
|
|
93
|
+
* Use clearAugmented() instead.
|
|
94
|
+
*/
|
|
95
|
+
delete(_key: Id): boolean;
|
|
96
|
+
/**
|
|
97
|
+
* Not supported - this is a read-only wrapper.
|
|
98
|
+
* Use clearAllAugmented() instead.
|
|
99
|
+
*/
|
|
100
|
+
clear(): void;
|
|
101
|
+
/**
|
|
102
|
+
* Symbol.toStringTag for Map interface.
|
|
103
|
+
*/
|
|
104
|
+
get [Symbol.toStringTag](): string;
|
|
105
|
+
/**
|
|
106
|
+
* Merge two sorted Uint32Arrays into a new sorted Uint32Array.
|
|
107
|
+
* Removes duplicates.
|
|
108
|
+
*/
|
|
109
|
+
private mergeSortedTokenArrays;
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=AugmentedMetadata.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AugmentedMetadata.d.ts","sourceRoot":"","sources":["../../../src/common/numeric/AugmentedMetadata.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAA;AAInH;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,iBAAkB,YAAW,qBAAqB;IAC7D,OAAO,CAAC,YAAY,CAAuB;IAC3C,OAAO,CAAC,eAAe,CAAiC;IACxD,OAAO,CAAC,IAAI,CAAuC;IAEnD;;;;OAIG;gBAED,YAAY,EAAE,qBAAqB,EACnC,IAAI,CAAC,EAAE,oBAAoB,CAAC,GAAG,CAAC,EAChC,gBAAgB,CAAC,EAAE,GAAG,CAAC,EAAE,EAAE,GAAG,CAAC;IAWjC;;;;;;OAMG;IACH,eAAe,CAAC,EAAE,EAAE,EAAE,EAAE,aAAa,EAAE,GAAG,GAAG,IAAI;IAkBjD;;;;;OAKG;IACH,oBAAoB,CAAC,gBAAgB,EAAE,GAAG,CAAC,EAAE,EAAE,GAAG,CAAC,GAAG,IAAI;IAqB1D;;OAEG;IACH,cAAc,CAAC,EAAE,EAAE,EAAE,GAAG,IAAI;IAI5B;;OAEG;IACH,iBAAiB,IAAI,IAAI;IAIzB;;;OAGG;IACH,GAAG,CAAC,EAAE,EAAE,EAAE,GAAG,sBAAsB,GAAG,SAAS;IAW/C;;OAEG;IACH,GAAG,CAAC,EAAE,EAAE,EAAE,GAAG,OAAO;IAIpB;;OAEG;IACH,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED;;OAEG;IACH,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,WAAW,CAAC,CAAC,EAAE,EAAE,sBAAsB,CAAC,CAAC;IAwB9D;;OAEG;IACH,IAAI,IAAI,WAAW,CAAC,EAAE,CAAC;IAIvB;;OAEG;IACH,MAAM,IAAI,WAAW,CAAC,sBAAsB,CAAC;IAsB7C;;OAEG;IACH,OAAO,IAAI,WAAW,CAAC,CAAC,EAAE,EAAE,sBAAsB,CAAC,CAAC;IAIpD;;OAEG;IACH,OAAO,CAAC,UAAU,EAAE,CAAC,KAAK,EAAE,sBAAsB,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE,EAAE,sBAAsB,CAAC,KAAK,IAAI,GAAG,IAAI;IAMjH;;;OAGG;IACH,GAAG,CAAC,IAAI,EAAE,EAAE,EAAE,MAAM,EAAE,sBAAsB,GAAG,IAAI;IAInD;;;OAGG;IACH,MAAM,CAAC,IAAI,EAAE,EAAE,GAAG,OAAO;IAIzB;;;OAGG;IACH,KAAK,IAAI,IAAI;IAIb;;OAEG;IACH,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,MAAM,CAEjC;IAED;;;OAGG;IACH,OAAO,CAAC,sBAAsB;CAoD/B"}
|
|
@@ -20,7 +20,7 @@ import type { NumericLinkedSearchMetadataWithData } from './createSearchLinkedMe
|
|
|
20
20
|
* @param linked - Linked metadata from {@link createSearchLinkedMetadataNumeric}
|
|
21
21
|
* @param limit - Maximum number of results to return (default: 10)
|
|
22
22
|
* @param opts - Optional search options for controlling match behavior
|
|
23
|
-
* @returns Search results with query tokens and
|
|
23
|
+
* @returns Search results with query tokens, matching items, and hasNegation flag
|
|
24
24
|
*/
|
|
25
25
|
export declare function findInLinkedArraysNumeric<TPrimary extends SearchableObject, TLinked extends SearchableObject>(query: string, linked: NumericLinkedSearchMetadataWithData<TPrimary, TLinked>, limit?: number, opts?: SearchOpts): LinkedSearchResultWithMeta<TPrimary, TLinked>;
|
|
26
26
|
/**
|
|
@@ -6,4 +6,7 @@ export { createSearchLinkedMetadataNumeric, type NumericLinkedSearchMetadataWith
|
|
|
6
6
|
export { updateSearchMetadataNumeric, updateSearchMetadataBatchNumeric, removeFromSearchMetadataNumeric, removeFromSearchMetadataBatchNumeric, } from './updateSearchMetadata';
|
|
7
7
|
export { searchInDataReturnIdsNumeric, searchInDataReturnObjectsNumeric, searchInDataReturnIdsWithLimitNumeric, } from './searchInData';
|
|
8
8
|
export { findInLinkedArraysNumeric, findInLinkedArraysSimpleNumeric, } from './findInLinkedArrays';
|
|
9
|
+
export { AugmentedMetadata } from './AugmentedMetadata';
|
|
10
|
+
export { syncSearchArrayMetadataNumeric, syncSearchArrayMetadataNumericWithPrevious, } from './syncSearchArrayMetadata';
|
|
11
|
+
export { upsertPrimaryItemNumeric, removePrimaryItemNumeric, upsertLinkedItemNumeric, removeLinkedItemNumeric, syncLinkedItemsForPrimaryNumeric, } from './updateSearchLinkedMetadata';
|
|
9
12
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/common/numeric/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,gCAAgC,EAChC,6BAA6B,EAC7B,mBAAmB,EACnB,aAAa,EACb,eAAe,EACf,aAAa,EACb,eAAe,GAChB,MAAM,6BAA6B,CAAC;AAErC,OAAO,EACL,iCAAiC,EACjC,KAAK,mCAAmC,GACzC,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EACL,2BAA2B,EAC3B,gCAAgC,EAChC,+BAA+B,EAC/B,oCAAoC,GACrC,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EACL,4BAA4B,EAC5B,gCAAgC,EAChC,qCAAqC,GACtC,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACL,yBAAyB,EACzB,+BAA+B,GAChC,MAAM,sBAAsB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/common/numeric/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,gCAAgC,EAChC,6BAA6B,EAC7B,mBAAmB,EACnB,aAAa,EACb,eAAe,EACf,aAAa,EACb,eAAe,GAChB,MAAM,6BAA6B,CAAC;AAErC,OAAO,EACL,iCAAiC,EACjC,KAAK,mCAAmC,GACzC,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EACL,2BAA2B,EAC3B,gCAAgC,EAChC,+BAA+B,EAC/B,oCAAoC,GACrC,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EACL,4BAA4B,EAC5B,gCAAgC,EAChC,qCAAqC,GACtC,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACL,yBAAyB,EACzB,+BAA+B,GAChC,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD,OAAO,EACL,8BAA8B,EAC9B,0CAA0C,GAC3C,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EACL,wBAAwB,EACxB,wBAAwB,EACxB,uBAAuB,EACvB,uBAAuB,EACvB,gCAAgC,GACjC,MAAM,8BAA8B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"searchInData.d.ts","sourceRoot":"","sources":["../../../src/common/numeric/searchInData.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,EAAE,EACF,qBAAqB,EACrB,cAAc,EACd,gBAAgB,EAChB,UAAU,EACX,MAAM,aAAa,CAAC;AAIrB;;;;;;;GAOG;AACH,wBAAgB,4BAA4B,CAC1C,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,qBAAqB,EAC/B,IAAI,CAAC,EAAE,UAAU,GAChB,EAAE,EAAE,
|
|
1
|
+
{"version":3,"file":"searchInData.d.ts","sourceRoot":"","sources":["../../../src/common/numeric/searchInData.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,EAAE,EACF,qBAAqB,EACrB,cAAc,EACd,gBAAgB,EAChB,UAAU,EACX,MAAM,aAAa,CAAC;AAIrB;;;;;;;GAOG;AACH,wBAAgB,4BAA4B,CAC1C,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,qBAAqB,EAC/B,IAAI,CAAC,EAAE,UAAU,GAChB,EAAE,EAAE,CAEN;AAED;;;;;;;;GAQG;AACH,wBAAgB,gCAAgC,CAAC,CAAC,SAAS,gBAAgB,EACzE,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,qBAAqB,EAC/B,IAAI,EAAE,cAAc,CAAC,CAAC,CAAC,EACvB,IAAI,CAAC,EAAE,UAAU,GAChB,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC,CAYZ;AAED;;;;;;;;GAQG;AACH,wBAAgB,qCAAqC,CACnD,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,qBAAqB,EAC/B,KAAK,EAAE,MAAM,EACb,IAAI,CAAC,EAAE,UAAU,GAChB,EAAE,EAAE,CAsBN"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { NumericSearchMetadata, SearchableData, SearchableObject, SearchableObjectSpec, SyncResult, SyncOptions } from '../../types/index.js';
|
|
2
|
+
export type { SyncResult, SyncOptions } from '../../types/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Syncs numeric search metadata with new data.
|
|
5
|
+
*
|
|
6
|
+
* This function performs a full sync of metadata against the provided data:
|
|
7
|
+
* - Adds metadata for new items
|
|
8
|
+
* - Removes metadata for items no longer in data (or marked `_deleted`/`_blocked`)
|
|
9
|
+
* - Updates metadata for items whose tokens have changed
|
|
10
|
+
*
|
|
11
|
+
* Use this when you have completely new data to sync with. If you have both
|
|
12
|
+
* previous and new data available, use {@link syncSearchArrayMetadataNumericWithPrevious}
|
|
13
|
+
* for more efficient diffing.
|
|
14
|
+
*
|
|
15
|
+
* @typeParam T - Type of the searchable objects
|
|
16
|
+
* @typeParam C - Type of the search context
|
|
17
|
+
*
|
|
18
|
+
* @param metadata - The NumericSearchMetadata map to update (mutated in place)
|
|
19
|
+
* @param newData - The new data to sync with
|
|
20
|
+
* @param spec - Optional specification for how to extract searchable text
|
|
21
|
+
* @returns SyncResult with counts and IDs of added/updated/removed items
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* const newProducts = arrayToSearchableData(freshProductsFromServer);
|
|
26
|
+
* const result = syncSearchArrayMetadataNumeric(metadata, newProducts, spec);
|
|
27
|
+
*
|
|
28
|
+
* console.log(`Added: ${result.added}, Updated: ${result.updated}, Removed: ${result.removed}`);
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare function syncSearchArrayMetadataNumeric<T extends SearchableObject, C = unknown>(metadata: NumericSearchMetadata, newData: SearchableData<T>, spec?: SearchableObjectSpec<T, C>): SyncResult;
|
|
32
|
+
/**
|
|
33
|
+
* Syncs numeric search metadata using previous and new data for efficient diffing.
|
|
34
|
+
*
|
|
35
|
+
* More efficient than {@link syncSearchArrayMetadataNumeric} when you have both the
|
|
36
|
+
* previous and new data available. Uses the previous data to determine
|
|
37
|
+
* what was removed without iterating through all metadata keys.
|
|
38
|
+
*
|
|
39
|
+
* @typeParam T - Type of the searchable objects
|
|
40
|
+
* @typeParam C - Type of the search context
|
|
41
|
+
*
|
|
42
|
+
* @param metadata - The NumericSearchMetadata map to update (mutated in place)
|
|
43
|
+
* @param previousData - The previous data (used to determine what was removed)
|
|
44
|
+
* @param newData - The new data to sync with
|
|
45
|
+
* @param options - Optional sync options (e.g., skipUpdateCheck)
|
|
46
|
+
* @param spec - Optional specification for how to extract searchable text
|
|
47
|
+
* @returns SyncResult with counts and IDs of added/updated/removed items
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```typescript
|
|
51
|
+
* const previousProducts = currentData;
|
|
52
|
+
* const newProducts = arrayToSearchableData(freshProductsFromServer);
|
|
53
|
+
*
|
|
54
|
+
* const result = syncSearchArrayMetadataNumericWithPrevious(
|
|
55
|
+
* metadata,
|
|
56
|
+
* previousProducts,
|
|
57
|
+
* newProducts,
|
|
58
|
+
* { skipUpdateCheck: false },
|
|
59
|
+
* spec
|
|
60
|
+
* );
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export declare function syncSearchArrayMetadataNumericWithPrevious<T extends SearchableObject, C = unknown>(metadata: NumericSearchMetadata, previousData: SearchableData<T>, newData: SearchableData<T>, options?: SyncOptions, spec?: SearchableObjectSpec<T, C>): SyncResult;
|
|
64
|
+
//# sourceMappingURL=syncSearchArrayMetadata.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"syncSearchArrayMetadata.d.ts","sourceRoot":"","sources":["../../../src/common/numeric/syncSearchArrayMetadata.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,qBAAqB,EACrB,cAAc,EACd,gBAAgB,EAChB,oBAAoB,EAEpB,UAAU,EACV,WAAW,EACZ,MAAM,sBAAsB,CAAA;AAK7B,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAkBnE;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,8BAA8B,CAAC,CAAC,SAAS,gBAAgB,EAAE,CAAC,GAAG,OAAO,EACpF,QAAQ,EAAE,qBAAqB,EAC/B,OAAO,EAAE,cAAc,CAAC,CAAC,CAAC,EAC1B,IAAI,CAAC,EAAE,oBAAoB,CAAC,CAAC,EAAE,CAAC,CAAC,GAChC,UAAU,CAoDZ;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,0CAA0C,CAAC,CAAC,SAAS,gBAAgB,EAAE,CAAC,GAAG,OAAO,EAChG,QAAQ,EAAE,qBAAqB,EAC/B,YAAY,EAAE,cAAc,CAAC,CAAC,CAAC,EAC/B,OAAO,EAAE,cAAc,CAAC,CAAC,CAAC,EAC1B,OAAO,CAAC,EAAE,WAAW,EACrB,IAAI,CAAC,EAAE,oBAAoB,CAAC,CAAC,EAAE,CAAC,CAAC,GAChC,UAAU,CAsDZ"}
|