cry-search 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.
- package/CLAUDE.md +285 -0
- package/LICENSE.md +67 -0
- package/README.md +283 -0
- package/UNIVERSE.md +818 -0
- package/dist/common/SearchUniverse.d.ts +210 -0
- package/dist/common/SearchUniverse.d.ts.map +1 -0
- package/dist/common/findInArray.d.ts +37 -0
- package/dist/common/findInArray.d.ts.map +1 -0
- package/dist/common/findInArrayReturnDataAndMeta.d.ts +52 -0
- package/dist/common/findInArrayReturnDataAndMeta.d.ts.map +1 -0
- package/dist/common/findInLinkedArrays.d.ts +66 -0
- package/dist/common/findInLinkedArrays.d.ts.map +1 -0
- package/dist/common/numeric/createSearchArrayMetadata.d.ts +65 -0
- package/dist/common/numeric/createSearchArrayMetadata.d.ts.map +1 -0
- package/dist/common/numeric/createSearchLinkedMetadata.d.ts +46 -0
- package/dist/common/numeric/createSearchLinkedMetadata.d.ts.map +1 -0
- package/dist/common/numeric/findInLinkedArrays.d.ts +32 -0
- package/dist/common/numeric/findInLinkedArrays.d.ts.map +1 -0
- package/dist/common/numeric/index.d.ts +9 -0
- package/dist/common/numeric/index.d.ts.map +1 -0
- package/dist/common/numeric/searchInData.d.ts +31 -0
- package/dist/common/numeric/searchInData.d.ts.map +1 -0
- package/dist/common/numeric/updateSearchMetadata.d.ts +60 -0
- package/dist/common/numeric/updateSearchMetadata.d.ts.map +1 -0
- package/dist/common/string/createSearchArrayMetadata.d.ts +117 -0
- package/dist/common/string/createSearchArrayMetadata.d.ts.map +1 -0
- package/dist/common/string/createSearchLinkedMetadata.d.ts +36 -0
- package/dist/common/string/createSearchLinkedMetadata.d.ts.map +1 -0
- package/dist/common/string/index.d.ts +10 -0
- package/dist/common/string/index.d.ts.map +1 -0
- package/dist/common/string/updateSearchMetadata.d.ts +103 -0
- package/dist/common/string/updateSearchMetadata.d.ts.map +1 -0
- package/dist/common/syncSearchArrayMetadata.d.ts +64 -0
- package/dist/common/syncSearchArrayMetadata.d.ts.map +1 -0
- package/dist/common/updateSearchLinkedMetadata.d.ts +129 -0
- package/dist/common/updateSearchLinkedMetadata.d.ts.map +1 -0
- package/dist/index.cjs +1827 -0
- package/dist/index.d.cts +32 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1795 -0
- package/dist/types/index.d.ts +300 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types.d.ts +6 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils/matchToken.d.ts +65 -0
- package/dist/utils/matchToken.d.ts.map +1 -0
- package/dist/utils/matchTokenNumeric.d.ts +94 -0
- package/dist/utils/matchTokenNumeric.d.ts.map +1 -0
- package/dist/utils/normalizeDates.d.ts +39 -0
- package/dist/utils/normalizeDates.d.ts.map +1 -0
- package/dist/utils/prepareStringForSearch.d.ts +28 -0
- package/dist/utils/prepareStringForSearch.d.ts.map +1 -0
- package/dist/utils/prepareStringForSearchNumeric.d.ts +42 -0
- package/dist/utils/prepareStringForSearchNumeric.d.ts.map +1 -0
- package/dist/utils/preprocessString.d.ts +26 -0
- package/dist/utils/preprocessString.d.ts.map +1 -0
- package/dist/utils/sanitiseString.d.ts +26 -0
- package/dist/utils/sanitiseString.d.ts.map +1 -0
- package/dist/utils/tokenRegistry.d.ts +70 -0
- package/dist/utils/tokenRegistry.d.ts.map +1 -0
- package/dist/utils/tokenize.d.ts +46 -0
- package/dist/utils/tokenize.d.ts.map +1 -0
- package/package.json +67 -0
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import type { Id, NumericSearchMetadata, SearchableData, SearchableObject, UniversalSearchOpts, CollectionConfig, UpdateResult, BatchUpdateResult } from '../types';
|
|
2
|
+
export type { UniversalSearchOpts, CollectionConfig, UpdateResult, BatchUpdateResult } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* SearchUniverse manages multiple collections with their metadata and relationships.
|
|
5
|
+
* Provides unified update methods that automatically handle linked data indexes.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* const universe = new SearchUniverse();
|
|
10
|
+
*
|
|
11
|
+
* // Register collections
|
|
12
|
+
* universe.registerCollection<Stranka>('stranke', {
|
|
13
|
+
* spec: { searchInFields: ['name', 'address'] }
|
|
14
|
+
* });
|
|
15
|
+
*
|
|
16
|
+
* universe.registerCollection<Pacient>('pacienti', {
|
|
17
|
+
* spec: { dontSearchInFields: ['stranka_id'] },
|
|
18
|
+
* linkedTo: {
|
|
19
|
+
* collectionName: 'stranke',
|
|
20
|
+
* foreignKeyGetter: (p) => p.stranka_id
|
|
21
|
+
* }
|
|
22
|
+
* });
|
|
23
|
+
*
|
|
24
|
+
* // Load initial data
|
|
25
|
+
* universe.loadCollection('stranke', strankeArray);
|
|
26
|
+
* universe.loadCollection('pacienti', pacientiArray);
|
|
27
|
+
*
|
|
28
|
+
* // Update items - automatically handles metadata and indexes
|
|
29
|
+
* universe.updateSearchMetadata('pacienti', 'p1', updatedPacient);
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare class SearchUniverse {
|
|
33
|
+
private collections;
|
|
34
|
+
/**
|
|
35
|
+
* Registers a new collection with optional configuration.
|
|
36
|
+
*
|
|
37
|
+
* @param name - Unique name for the collection
|
|
38
|
+
* @param config - Configuration including spec and links
|
|
39
|
+
*/
|
|
40
|
+
registerCollection<T extends SearchableObject, C = unknown>(name: string, config?: CollectionConfig<T, C>): void;
|
|
41
|
+
/**
|
|
42
|
+
* Checks if a collection exists.
|
|
43
|
+
*
|
|
44
|
+
* @param name - Collection name to check
|
|
45
|
+
* @returns True if the collection is registered
|
|
46
|
+
*/
|
|
47
|
+
hasCollection(name: string): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Gets all registered collection names.
|
|
50
|
+
*
|
|
51
|
+
* @returns Array of collection names
|
|
52
|
+
*/
|
|
53
|
+
getCollectionNames(): string[];
|
|
54
|
+
/**
|
|
55
|
+
* Loads data into a collection, replacing any existing data.
|
|
56
|
+
* Builds metadata and updates linked indexes.
|
|
57
|
+
*
|
|
58
|
+
* @param name - Collection name
|
|
59
|
+
* @param items - Array of items to load
|
|
60
|
+
*/
|
|
61
|
+
loadCollection<T extends SearchableObject>(name: string, items: T[]): void;
|
|
62
|
+
/**
|
|
63
|
+
* Gets an item from a collection by ID.
|
|
64
|
+
*
|
|
65
|
+
* @typeParam T - Type of the item
|
|
66
|
+
* @param collectionName - Name of the collection
|
|
67
|
+
* @param id - ID of the item to retrieve
|
|
68
|
+
* @returns The item, or undefined if not found
|
|
69
|
+
*/
|
|
70
|
+
getItem<T extends SearchableObject>(collectionName: string, id: Id): T | undefined;
|
|
71
|
+
/**
|
|
72
|
+
* Gets all items from a collection.
|
|
73
|
+
*
|
|
74
|
+
* @typeParam T - Type of items in the collection
|
|
75
|
+
* @param collectionName - Name of the collection
|
|
76
|
+
* @returns Array of all items
|
|
77
|
+
*/
|
|
78
|
+
getItems<T extends SearchableObject>(collectionName: string): T[];
|
|
79
|
+
/**
|
|
80
|
+
* Gets the number of items in a collection.
|
|
81
|
+
*
|
|
82
|
+
* @param collectionName - Name of the collection
|
|
83
|
+
* @returns Number of items in the collection
|
|
84
|
+
*/
|
|
85
|
+
getCollectionSize(collectionName: string): number;
|
|
86
|
+
/**
|
|
87
|
+
* Gets the search metadata for a collection.
|
|
88
|
+
*
|
|
89
|
+
* @param collectionName - Name of the collection
|
|
90
|
+
* @returns The NumericSearchMetadata map (id -> Uint32Array of token IDs)
|
|
91
|
+
*/
|
|
92
|
+
getMetadata(collectionName: string): NumericSearchMetadata;
|
|
93
|
+
/**
|
|
94
|
+
* Gets the data map for a collection.
|
|
95
|
+
*
|
|
96
|
+
* @typeParam T - Type of items in the collection
|
|
97
|
+
* @param collectionName - Name of the collection
|
|
98
|
+
* @returns The SearchableData map (id -> item)
|
|
99
|
+
*/
|
|
100
|
+
getData<T extends SearchableObject>(collectionName: string): SearchableData<T>;
|
|
101
|
+
/**
|
|
102
|
+
* Gets linked item IDs for a primary item.
|
|
103
|
+
*
|
|
104
|
+
* @param linkedCollectionName - Name of the linked collection
|
|
105
|
+
* @param primaryId - ID of the primary item
|
|
106
|
+
* @returns Array of linked item IDs (empty if none)
|
|
107
|
+
* @throws Error if the collection is not a linked collection
|
|
108
|
+
*/
|
|
109
|
+
getLinkedIds(linkedCollectionName: string, primaryId: Id): Id[];
|
|
110
|
+
/**
|
|
111
|
+
* Gets linked items for a primary item.
|
|
112
|
+
*
|
|
113
|
+
* @typeParam T - Type of linked items
|
|
114
|
+
* @param linkedCollectionName - Name of the linked collection
|
|
115
|
+
* @param primaryId - ID of the primary item
|
|
116
|
+
* @returns Array of linked items (empty if none)
|
|
117
|
+
*/
|
|
118
|
+
getLinkedItems<T extends SearchableObject>(linkedCollectionName: string, primaryId: Id): T[];
|
|
119
|
+
/**
|
|
120
|
+
* Updates search metadata for a single item.
|
|
121
|
+
* Automatically handles:
|
|
122
|
+
* - Adding new items
|
|
123
|
+
* - Updating existing items
|
|
124
|
+
* - Removing items marked as _deleted or _blocked
|
|
125
|
+
* - Updating linked indexes when foreign key changes
|
|
126
|
+
*
|
|
127
|
+
* @param collectionName - Name of the collection
|
|
128
|
+
* @param id - ID of the item to update
|
|
129
|
+
* @param item - The item (may be deleted/blocked)
|
|
130
|
+
* @returns UpdateResult indicating if item was added/updated/removed
|
|
131
|
+
*/
|
|
132
|
+
updateSearchMetadata<T extends SearchableObject>(collectionName: string, id: Id, item: T): UpdateResult;
|
|
133
|
+
/**
|
|
134
|
+
* Updates search metadata for multiple items in a batch.
|
|
135
|
+
*
|
|
136
|
+
* @param collectionName - Name of the collection
|
|
137
|
+
* @param items - Array of items to update (each must have _id)
|
|
138
|
+
* @returns BatchUpdateResult with counts
|
|
139
|
+
*/
|
|
140
|
+
updateSearchMetadataBatch<T extends SearchableObject>(collectionName: string, items: T[]): BatchUpdateResult;
|
|
141
|
+
/**
|
|
142
|
+
* Removes an item from a collection by ID.
|
|
143
|
+
*
|
|
144
|
+
* @param collectionName - Name of the collection
|
|
145
|
+
* @param id - ID of the item to remove
|
|
146
|
+
* @returns true if item was found and removed
|
|
147
|
+
*/
|
|
148
|
+
removeFromSearchMetadata(collectionName: string, id: Id): boolean;
|
|
149
|
+
/**
|
|
150
|
+
* Removes multiple items from a collection by IDs.
|
|
151
|
+
*
|
|
152
|
+
* @param collectionName - Name of the collection
|
|
153
|
+
* @param ids - Array of IDs to remove
|
|
154
|
+
* @returns Number of items actually removed
|
|
155
|
+
*/
|
|
156
|
+
removeFromSearchMetadataBatch(collectionName: string, ids: Id[]): number;
|
|
157
|
+
/**
|
|
158
|
+
* Gets collection or throws an error if not found.
|
|
159
|
+
*
|
|
160
|
+
* @param name - Collection name
|
|
161
|
+
* @returns The collection
|
|
162
|
+
* @throws Error if collection is not found
|
|
163
|
+
* @internal
|
|
164
|
+
*/
|
|
165
|
+
private getCollectionOrThrow;
|
|
166
|
+
/**
|
|
167
|
+
* Searches across all collections in the universe.
|
|
168
|
+
* Returns results grouped by collection name.
|
|
169
|
+
* For linked collections, returns combined results with their primary items.
|
|
170
|
+
* Only includes non-empty results.
|
|
171
|
+
*
|
|
172
|
+
* @param query - The search query string
|
|
173
|
+
* @param limit - Maximum number of results per collection (default: 10)
|
|
174
|
+
* @param opts - Search options for controlling match behavior and collection filtering
|
|
175
|
+
* @returns Object with collection names as keys and results as values.
|
|
176
|
+
* Standalone collections: array of items
|
|
177
|
+
* Linked collections: array of { linked: item, primary: primaryItem }
|
|
178
|
+
*
|
|
179
|
+
* @example
|
|
180
|
+
* ```typescript
|
|
181
|
+
* const results = universe.searchUniversally('krajnik');
|
|
182
|
+
* // Returns:
|
|
183
|
+
* // {
|
|
184
|
+
* // stranke: [{ _id: 's1', name: 'Krajnik', ... }],
|
|
185
|
+
* // pacienti: [{ linked: { _id: 'p1', ... }, primary: { _id: 's1', ... } }]
|
|
186
|
+
* // }
|
|
187
|
+
*
|
|
188
|
+
* // Filter to specific collections:
|
|
189
|
+
* const filtered = universe.searchUniversally('rex', 10, {
|
|
190
|
+
* inCollections: ['pacienti-stranke', 'racuni-pacienti']
|
|
191
|
+
* });
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
194
|
+
searchUniversally(query: string, limit?: number, opts?: UniversalSearchOpts): Record<string, SearchableObject[] | Array<{
|
|
195
|
+
linked: SearchableObject[];
|
|
196
|
+
primary: SearchableObject;
|
|
197
|
+
matchedIn: 'primary' | 'linked' | 'both';
|
|
198
|
+
}>>;
|
|
199
|
+
/**
|
|
200
|
+
* Clears all collections, removing all data, metadata, and linked indexes.
|
|
201
|
+
*
|
|
202
|
+
* @example
|
|
203
|
+
* ```typescript
|
|
204
|
+
* universe.clear();
|
|
205
|
+
* // All collections are now empty, can re-register and reload
|
|
206
|
+
* ```
|
|
207
|
+
*/
|
|
208
|
+
clear(): void;
|
|
209
|
+
}
|
|
210
|
+
//# sourceMappingURL=SearchUniverse.d.ts.map
|
|
@@ -0,0 +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;IAK1D;;;;;;OAMG;IACH,OAAO,CAAC,CAAC,SAAS,gBAAgB,EAAE,cAAc,EAAE,MAAM,GAAG,cAAc,CAAC,CAAC,CAAC;IAK9E;;;;;;;OAOG;IACH,YAAY,CAAC,oBAAoB,EAAE,MAAM,EAAE,SAAS,EAAE,EAAE,GAAG,EAAE,EAAE;IAQ/D;;;;;;;OAOG;IACH,cAAc,CAAC,CAAC,SAAS,gBAAgB,EACvC,oBAAoB,EAAE,MAAM,EAC5B,SAAS,EAAE,EAAE,GACZ,CAAC,EAAE;IAMN;;;;;;;;;;;;OAYG;IACH,oBAAoB,CAAC,CAAC,SAAS,gBAAgB,EAC7C,cAAc,EAAE,MAAM,EACtB,EAAE,EAAE,EAAE,EACN,IAAI,EAAE,CAAC,GACN,YAAY;IAoFf;;;;;;OAMG;IACH,yBAAyB,CAAC,CAAC,SAAS,gBAAgB,EAClD,cAAc,EAAE,MAAM,EACtB,KAAK,EAAE,CAAC,EAAE,GACT,iBAAiB;IA0BpB;;;;;;OAMG;IACH,wBAAwB,CAAC,cAAc,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,GAAG,OAAO;IAmCjE;;;;;;OAMG;IACH,6BAA6B,CAAC,cAAc,EAAE,MAAM,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,MAAM;IAcxE;;;;;;;OAOG;IACH,OAAO,CAAC,oBAAoB;IAQ5B;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACH,iBAAiB,CACf,KAAK,EAAE,MAAM,EACb,KAAK,GAAE,MAAW,EAClB,IAAI,CAAC,EAAE,mBAAmB,GACzB,MAAM,CAAC,MAAM,EAAE,gBAAgB,EAAE,GAAG,KAAK,CAAC;QAAE,MAAM,EAAE,gBAAgB,EAAE,CAAC;QAAC,OAAO,EAAE,gBAAgB,CAAC;QAAC,SAAS,EAAE,SAAS,GAAG,QAAQ,GAAG,MAAM,CAAA;KAAE,CAAC,CAAC;IA8FlJ;;;;;;;;OAQG;IACH,KAAK,IAAI,IAAI;CAUd"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { SearchMetadata, SearchableObject, SearchableData, SearchOpts } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Searches a data set using pre-computed metadata.
|
|
4
|
+
*
|
|
5
|
+
* This is the main search function for single collections. It tokenizes the query,
|
|
6
|
+
* matches all tokens against each item's metadata, and returns matching items.
|
|
7
|
+
*
|
|
8
|
+
* Use this function when you only need the matching items. If you also need
|
|
9
|
+
* the query tokens or item metadata, use {@link findInArrayReturnDataAndMeta} instead.
|
|
10
|
+
*
|
|
11
|
+
* @typeParam T - Type of items being searched
|
|
12
|
+
*
|
|
13
|
+
* @param query - The search query string (will be tokenized)
|
|
14
|
+
* @param data - Map of items by ID (SearchableData)
|
|
15
|
+
* @param metadata - Pre-computed search metadata (SearchMetadata)
|
|
16
|
+
* @param limit - Maximum number of results to return (default: 10)
|
|
17
|
+
* @param opts - Optional search options for controlling match behavior
|
|
18
|
+
* @returns Array of matching items (up to limit)
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* const products = arrayToSearchableData([
|
|
23
|
+
* { _id: '1', name: 'Čokolada Milka', category: 'sladkarije' },
|
|
24
|
+
* { _id: '2', name: 'Mleko Alpsko', category: 'mlečni izdelki' },
|
|
25
|
+
* ]);
|
|
26
|
+
*
|
|
27
|
+
* const metadata = createSearchArrayMetadata(products);
|
|
28
|
+
*
|
|
29
|
+
* findInArray('cokolada', products, metadata, 10);
|
|
30
|
+
* // Returns: [{ _id: '1', name: 'Čokolada Milka', ... }]
|
|
31
|
+
*
|
|
32
|
+
* findInArray('mleko', products, metadata, 10, { matchWords: 'whole' });
|
|
33
|
+
* // Returns: [{ _id: '2', name: 'Mleko Alpsko', ... }]
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare function findInArray<T extends SearchableObject>(query: string, data: SearchableData<T>, metadata: SearchMetadata, limit?: number, opts?: SearchOpts): T[];
|
|
37
|
+
//# sourceMappingURL=findInArray.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"findInArray.d.ts","sourceRoot":"","sources":["../../src/common/findInArray.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,gBAAgB,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAG7F;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,gBAAgB,EACpD,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,cAAc,CAAC,CAAC,CAAC,EACvB,QAAQ,EAAE,cAAc,EACxB,KAAK,GAAE,MAAW,EAClB,IAAI,CAAC,EAAE,UAAU,GAChB,CAAC,EAAE,CAGL"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { Id, SearchMetadata, SearchableObject, SearchableData, SearchOpts, SearchResultWithMeta } from '../types';
|
|
2
|
+
export type { SearchResultWithMeta } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Searches a data set using pre-computed metadata and returns items with their tokens.
|
|
5
|
+
*
|
|
6
|
+
* This function is the core search implementation. It tokenizes the query,
|
|
7
|
+
* iterates through the metadata, and returns items where all query tokens
|
|
8
|
+
* match at least one item token (according to match mode rules).
|
|
9
|
+
*
|
|
10
|
+
* Use this function when you need access to the query tokens or item tokens
|
|
11
|
+
* (for debugging, highlighting, etc.). For simpler use cases, use {@link findInArray}.
|
|
12
|
+
*
|
|
13
|
+
* @typeParam T - Type of items being searched
|
|
14
|
+
*
|
|
15
|
+
* @param query - The search query string (will be tokenized)
|
|
16
|
+
* @param data - Map of items by ID (SearchableData)
|
|
17
|
+
* @param metadata - Pre-computed search metadata (SearchMetadata)
|
|
18
|
+
* @param limit - Maximum number of results to return (default: 10)
|
|
19
|
+
* @param opts - Optional search options for controlling match behavior
|
|
20
|
+
* @returns Search results including query tokens and matching items with their tokens
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* const result = findInArrayReturnDataAndMeta('john doe', data, metadata, 10);
|
|
25
|
+
*
|
|
26
|
+
* console.log(result.queryTokens); // ['doe', 'john']
|
|
27
|
+
* console.log(result.results[0].item); // { _id: '1', name: 'John Doe', ... }
|
|
28
|
+
* console.log(result.results[0].tokens); // ['doe', 'john', ...]
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare function findInArrayReturnDataAndMeta<T extends SearchableObject>(query: string, data: SearchableData<T>, metadata: SearchMetadata, limit?: number, opts?: SearchOpts): SearchResultWithMeta<T>;
|
|
32
|
+
/**
|
|
33
|
+
* Searches metadata and returns just the matching item IDs.
|
|
34
|
+
*
|
|
35
|
+
* This is a lightweight search function that doesn't fetch the full objects,
|
|
36
|
+
* only their IDs. Useful when you need to know what matches without loading
|
|
37
|
+
* all the data, or when you want to fetch items from a different source.
|
|
38
|
+
*
|
|
39
|
+
* @param query - The search query string (will be tokenized)
|
|
40
|
+
* @param metadata - Pre-computed search metadata (SearchMetadata)
|
|
41
|
+
* @param limit - Maximum number of results to return (default: 10)
|
|
42
|
+
* @param opts - Optional search options for controlling match behavior
|
|
43
|
+
* @returns Array of matching item IDs (up to limit)
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* const ids = findInArrayReturnIds('john', metadata, 10);
|
|
48
|
+
* // Returns: ['id1', 'id2', ...]
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export declare function findInArrayReturnIds(query: string, metadata: SearchMetadata, limit?: number, opts?: SearchOpts): Id[];
|
|
52
|
+
//# sourceMappingURL=findInArrayReturnDataAndMeta.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"findInArrayReturnDataAndMeta.d.ts","sourceRoot":"","sources":["../../src/common/findInArrayReturnDataAndMeta.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,EAAE,EACF,cAAc,EACd,gBAAgB,EAChB,cAAc,EACd,UAAU,EACV,oBAAoB,EACrB,MAAM,UAAU,CAAC;AAKlB,YAAY,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAErD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,4BAA4B,CAAC,CAAC,SAAS,gBAAgB,EACrE,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,cAAc,CAAC,CAAC,CAAC,EACvB,QAAQ,EAAE,cAAc,EACxB,KAAK,GAAE,MAAW,EAClB,IAAI,CAAC,EAAE,UAAU,GAChB,oBAAoB,CAAC,CAAC,CAAC,CAkCzB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,cAAc,EACxB,KAAK,GAAE,MAAW,EAClB,IAAI,CAAC,EAAE,UAAU,GAChB,EAAE,EAAE,CAoBN"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { SearchableObject, SearchOpts, LinkedSearchResult, LinkedSearchResultWithMeta, SearchLinkedMetadataWithData } from '../types';
|
|
2
|
+
export type { LinkedSearchResult, LinkedSearchResultWithMeta } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Searches across linked data sets, matching against primary + all its linked items combined.
|
|
5
|
+
*
|
|
6
|
+
* For each primary item, collects all tokens from the primary and all its linked items,
|
|
7
|
+
* then matches query tokens against this combined pool. Returns primary items with
|
|
8
|
+
* only the linked items that contributed to the match.
|
|
9
|
+
*
|
|
10
|
+
* **Key behaviors:**
|
|
11
|
+
* - Tokens that match in the primary are excluded from linked matching (prevents
|
|
12
|
+
* foreign key redundancy)
|
|
13
|
+
* - Only linked items that match ALL remaining tokens are included in results
|
|
14
|
+
* - `matchedIn` indicates where the match was found: 'primary', 'linked', or 'both'
|
|
15
|
+
*
|
|
16
|
+
* @typeParam TPrimary - Type of primary items (e.g., Stranka)
|
|
17
|
+
* @typeParam TLinked - Type of linked items (e.g., Pacient)
|
|
18
|
+
*
|
|
19
|
+
* @param query - The search query string (will be tokenized)
|
|
20
|
+
* @param linked - Linked metadata from {@link createSearchLinkedMetadata}
|
|
21
|
+
* @param limit - Maximum number of results to return (default: 10)
|
|
22
|
+
* @param opts - Optional search options for controlling match behavior
|
|
23
|
+
* @returns Search results with query tokens and matching items
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* const linkedMeta = createSearchLinkedMetadata(
|
|
28
|
+
* strankeData, strankeMeta,
|
|
29
|
+
* pacientiData, pacientiMeta,
|
|
30
|
+
* (p) => p.stranka_id
|
|
31
|
+
* );
|
|
32
|
+
*
|
|
33
|
+
* // Search "krajnik angie" matches stranka "Krajnik" with pacient "Angie"
|
|
34
|
+
* const result = findInLinkedArrays('krajnik angie', linkedMeta, 10);
|
|
35
|
+
*
|
|
36
|
+
* console.log(result.results[0]);
|
|
37
|
+
* // {
|
|
38
|
+
* // primary: { _id: 's1', ime: 'Janez', priimek: 'Krajnik' },
|
|
39
|
+
* // linked: [{ _id: 'p1', ime: 'Angie', pasma: 'labrador' }],
|
|
40
|
+
* // matchedIn: 'both'
|
|
41
|
+
* // }
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export declare function findInLinkedArrays<TPrimary extends SearchableObject, TLinked extends SearchableObject>(query: string, linked: SearchLinkedMetadataWithData<TPrimary, TLinked>, limit?: number, opts?: SearchOpts): LinkedSearchResultWithMeta<TPrimary, TLinked>;
|
|
45
|
+
/**
|
|
46
|
+
* Simplified version of {@link findInLinkedArrays} that returns just the results.
|
|
47
|
+
*
|
|
48
|
+
* Use this when you don't need the query tokens metadata.
|
|
49
|
+
*
|
|
50
|
+
* @typeParam TPrimary - Type of primary items (e.g., Stranka)
|
|
51
|
+
* @typeParam TLinked - Type of linked items (e.g., Pacient)
|
|
52
|
+
*
|
|
53
|
+
* @param query - The search query string (will be tokenized)
|
|
54
|
+
* @param linked - Linked metadata from {@link createSearchLinkedMetadata}
|
|
55
|
+
* @param limit - Maximum number of results to return (default: 10)
|
|
56
|
+
* @param opts - Optional search options for controlling match behavior
|
|
57
|
+
* @returns Array of matching results (without query tokens metadata)
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```typescript
|
|
61
|
+
* const results = findInLinkedArraysSimple('krajnik', linkedMeta, 10);
|
|
62
|
+
* // Returns: [{ primary: Stranka, linked: [...], matchedIn: 'primary' }, ...]
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
export declare function findInLinkedArraysSimple<TPrimary extends SearchableObject, TLinked extends SearchableObject>(query: string, linked: SearchLinkedMetadataWithData<TPrimary, TLinked>, limit?: number, opts?: SearchOpts): LinkedSearchResult<TPrimary, TLinked>[];
|
|
66
|
+
//# sourceMappingURL=findInLinkedArrays.d.ts.map
|
|
@@ -0,0 +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,CAyF/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,65 @@
|
|
|
1
|
+
import type { MatchMode, NumericSearchMetadata, NumericTokenSortedList, SearchableObject, SearchableData, SearchableObjectSpec } from '../../types';
|
|
2
|
+
/**
|
|
3
|
+
* Prefix characters for per-field match modes.
|
|
4
|
+
* Note: With numeric tokens, prefixes are encoded differently.
|
|
5
|
+
* High bits of token ID can encode the match mode.
|
|
6
|
+
*/
|
|
7
|
+
export declare const MATCH_MODE_BITS: Record<MatchMode, number>;
|
|
8
|
+
/** Mask for extracting token ID (lower 29 bits) */
|
|
9
|
+
export declare const TOKEN_ID_MASK: number;
|
|
10
|
+
/**
|
|
11
|
+
* Encodes a token ID with a match mode.
|
|
12
|
+
* @param tokenId - The base token ID (must be < 2^29)
|
|
13
|
+
* @param mode - The match mode to encode
|
|
14
|
+
* @returns Encoded token with mode bits
|
|
15
|
+
*/
|
|
16
|
+
export declare function encodeTokenWithMode(tokenId: number, mode: MatchMode): number;
|
|
17
|
+
/**
|
|
18
|
+
* Decodes a token to get the original token ID.
|
|
19
|
+
* @param encoded - The encoded token
|
|
20
|
+
* @returns The original token ID
|
|
21
|
+
*/
|
|
22
|
+
export declare function decodeTokenId(encoded: number): number;
|
|
23
|
+
/**
|
|
24
|
+
* Decodes a token to get the match mode.
|
|
25
|
+
* @param encoded - The encoded token
|
|
26
|
+
* @returns The match mode (or 'start' as default if mode bits are 0)
|
|
27
|
+
*/
|
|
28
|
+
export declare function decodeMatchMode(encoded: number): MatchMode;
|
|
29
|
+
/**
|
|
30
|
+
* Prepares an object for search, returning numeric token IDs.
|
|
31
|
+
*
|
|
32
|
+
* @param obj - The searchable object to prepare
|
|
33
|
+
* @param spec - Optional specification for extraction and match modes
|
|
34
|
+
* @param tokensMap - Map for string->number conversion
|
|
35
|
+
* @returns undefined if object is _deleted or _blocked, otherwise sorted Uint32Array
|
|
36
|
+
*/
|
|
37
|
+
export declare function prepareObjectForSearchNumeric<T extends SearchableObject, C = unknown>(obj: T, spec: SearchableObjectSpec<T, C> | undefined, tokensMap: Map<string, number>): NumericTokenSortedList | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* Creates numeric search metadata for a collection of items.
|
|
40
|
+
*
|
|
41
|
+
* Pre-processes all searchable text into sorted numeric token IDs.
|
|
42
|
+
* Items with `_deleted` or `_blocked` fields are automatically excluded.
|
|
43
|
+
*
|
|
44
|
+
* The tokensMap is created at the start and cleared after metadata creation
|
|
45
|
+
* to free memory. Only the global tokens array remains in memory.
|
|
46
|
+
*
|
|
47
|
+
* @param data - Map of items by ID (SearchableData)
|
|
48
|
+
* @param spec - Optional specification for how to extract searchable text
|
|
49
|
+
* @returns NumericSearchMetadata map (Id → sorted Uint32Array of token IDs)
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* const items = arrayToSearchableData([
|
|
54
|
+
* { _id: '1', name: 'John Doe', barcode: '123456' },
|
|
55
|
+
* { _id: '2', name: 'Jane Smith', barcode: '789012' },
|
|
56
|
+
* ]);
|
|
57
|
+
*
|
|
58
|
+
* const metadata = createSearchArrayMetadataNumeric(items, {
|
|
59
|
+
* searchInFields: ['name', 'barcode'],
|
|
60
|
+
* fieldMatchModes: { barcode: 'startEnd' },
|
|
61
|
+
* });
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
export declare function createSearchArrayMetadataNumeric<T extends SearchableObject, C = unknown>(data: SearchableData<T>, spec?: SearchableObjectSpec<T, C>): NumericSearchMetadata;
|
|
65
|
+
//# sourceMappingURL=createSearchArrayMetadata.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createSearchArrayMetadata.d.ts","sourceRoot":"","sources":["../../../src/common/numeric/createSearchArrayMetadata.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,SAAS,EACT,qBAAqB,EACrB,sBAAsB,EACtB,gBAAgB,EAChB,cAAc,EACd,oBAAoB,EACrB,MAAM,aAAa,CAAC;AASrB;;;;GAIG;AACH,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,SAAS,EAAE,MAAM,CAMrD,CAAC;AAKF,mDAAmD;AACnD,eAAO,MAAM,aAAa,QAAwB,CAAC;AAEnD;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,GAAG,MAAM,CAE5E;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAErD;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,CAS1D;AAoED;;;;;;;GAOG;AACH,wBAAgB,6BAA6B,CAAC,CAAC,SAAS,gBAAgB,EAAE,CAAC,GAAG,OAAO,EACnF,GAAG,EAAE,CAAC,EACN,IAAI,EAAE,oBAAoB,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,SAAS,EAC5C,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAC7B,sBAAsB,GAAG,SAAS,CAgBpC;AA8DD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,gCAAgC,CAAC,CAAC,SAAS,gBAAgB,EAAE,CAAC,GAAG,OAAO,EACtF,IAAI,EAAE,cAAc,CAAC,CAAC,CAAC,EACvB,IAAI,CAAC,EAAE,oBAAoB,CAAC,CAAC,EAAE,CAAC,CAAC,GAChC,qBAAqB,CAmBvB"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { Id, NumericSearchMetadata, SearchableObject, SearchableData } from '../../types';
|
|
2
|
+
/**
|
|
3
|
+
* Extended linked search metadata for numeric tokens.
|
|
4
|
+
*/
|
|
5
|
+
export interface NumericLinkedSearchMetadataWithData<TPrimary extends SearchableObject, TLinked extends SearchableObject> {
|
|
6
|
+
/** Metadata for primary items (numeric tokens) */
|
|
7
|
+
primaryMeta: NumericSearchMetadata;
|
|
8
|
+
/** Metadata for linked/secondary items (numeric tokens) */
|
|
9
|
+
linkedMeta: NumericSearchMetadata;
|
|
10
|
+
/** Index: primary._id -> linked._id[] */
|
|
11
|
+
primaryToLinked: Map<Id, Id[]>;
|
|
12
|
+
/** Reference to primary data map */
|
|
13
|
+
primaryData: SearchableData<TPrimary>;
|
|
14
|
+
/** Reference to linked data map */
|
|
15
|
+
linkedData: SearchableData<TLinked>;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Creates linked metadata for searching across two related data sets with numeric tokens.
|
|
19
|
+
*
|
|
20
|
+
* This function builds a reverse index from primary items to their linked items,
|
|
21
|
+
* enabling efficient combined searches.
|
|
22
|
+
*
|
|
23
|
+
* The tokensMap is NOT created here because the metadata is already numeric.
|
|
24
|
+
* This function only builds the primaryToLinked index.
|
|
25
|
+
*
|
|
26
|
+
* @typeParam TPrimary - Type of primary items (e.g., Stranka)
|
|
27
|
+
* @typeParam TLinked - Type of linked items (e.g., Pacient)
|
|
28
|
+
*
|
|
29
|
+
* @param primaryData - Primary data map (e.g., stranke)
|
|
30
|
+
* @param primaryMetadata - Pre-computed numeric metadata for primary items
|
|
31
|
+
* @param linkedData - Linked/secondary data map (e.g., pacienti)
|
|
32
|
+
* @param linkedMetadata - Pre-computed numeric metadata for linked items
|
|
33
|
+
* @param foreignKeyGetter - Function to extract the primary ID from a linked item
|
|
34
|
+
* @returns Linked metadata for combined searching
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* const linkedMeta = createSearchLinkedMetadataNumeric(
|
|
39
|
+
* strankeData, strankeMeta,
|
|
40
|
+
* pacientiData, pacientiMeta,
|
|
41
|
+
* (pacient) => pacient.stranka_id
|
|
42
|
+
* );
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export declare function createSearchLinkedMetadataNumeric<TPrimary extends SearchableObject, TLinked extends SearchableObject>(primaryData: SearchableData<TPrimary>, primaryMetadata: NumericSearchMetadata, linkedData: SearchableData<TLinked>, linkedMetadata: NumericSearchMetadata, foreignKeyGetter: (linked: TLinked) => Id | undefined): NumericLinkedSearchMetadataWithData<TPrimary, TLinked>;
|
|
46
|
+
//# sourceMappingURL=createSearchLinkedMetadata.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createSearchLinkedMetadata.d.ts","sourceRoot":"","sources":["../../../src/common/numeric/createSearchLinkedMetadata.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,EAAE,EACF,qBAAqB,EACrB,gBAAgB,EAChB,cAAc,EACf,MAAM,aAAa,CAAC;AAErB;;GAEG;AACH,MAAM,WAAW,mCAAmC,CAClD,QAAQ,SAAS,gBAAgB,EACjC,OAAO,SAAS,gBAAgB;IAEhC,kDAAkD;IAClD,WAAW,EAAE,qBAAqB,CAAC;IACnC,2DAA2D;IAC3D,UAAU,EAAE,qBAAqB,CAAC;IAClC,yCAAyC;IACzC,eAAe,EAAE,GAAG,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;IAC/B,oCAAoC;IACpC,WAAW,EAAE,cAAc,CAAC,QAAQ,CAAC,CAAC;IACtC,mCAAmC;IACnC,UAAU,EAAE,cAAc,CAAC,OAAO,CAAC,CAAC;CACrC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,iCAAiC,CAC/C,QAAQ,SAAS,gBAAgB,EACjC,OAAO,SAAS,gBAAgB,EAEhC,WAAW,EAAE,cAAc,CAAC,QAAQ,CAAC,EACrC,eAAe,EAAE,qBAAqB,EACtC,UAAU,EAAE,cAAc,CAAC,OAAO,CAAC,EACnC,cAAc,EAAE,qBAAqB,EACrC,gBAAgB,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,EAAE,GAAG,SAAS,GACpD,mCAAmC,CAAC,QAAQ,EAAE,OAAO,CAAC,CAoBxD"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { SearchableObject, SearchOpts, LinkedSearchResult, LinkedSearchResultWithMeta } from '../../types';
|
|
2
|
+
import type { NumericLinkedSearchMetadataWithData } from './createSearchLinkedMetadata';
|
|
3
|
+
/**
|
|
4
|
+
* Searches across linked data sets using numeric tokens.
|
|
5
|
+
*
|
|
6
|
+
* For each primary item, collects all tokens from the primary and all its linked items,
|
|
7
|
+
* then matches query tokens against this combined pool. Returns primary items with
|
|
8
|
+
* only the linked items that contributed to the match.
|
|
9
|
+
*
|
|
10
|
+
* **Key behaviors:**
|
|
11
|
+
* - Tokens that match in the primary are excluded from linked matching (prevents
|
|
12
|
+
* foreign key redundancy)
|
|
13
|
+
* - Only linked items that match ALL remaining tokens are included in results
|
|
14
|
+
* - `matchedIn` indicates where the match was found: 'primary', 'linked', or 'both'
|
|
15
|
+
*
|
|
16
|
+
* @typeParam TPrimary - Type of primary items (e.g., Stranka)
|
|
17
|
+
* @typeParam TLinked - Type of linked items (e.g., Pacient)
|
|
18
|
+
*
|
|
19
|
+
* @param query - The search query string (will be tokenized)
|
|
20
|
+
* @param linked - Linked metadata from {@link createSearchLinkedMetadataNumeric}
|
|
21
|
+
* @param limit - Maximum number of results to return (default: 10)
|
|
22
|
+
* @param opts - Optional search options for controlling match behavior
|
|
23
|
+
* @returns Search results with query tokens and matching items
|
|
24
|
+
*/
|
|
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
|
+
/**
|
|
27
|
+
* Simplified version of {@link findInLinkedArraysNumeric} that returns just the results.
|
|
28
|
+
*
|
|
29
|
+
* Use this when you don't need the query tokens metadata.
|
|
30
|
+
*/
|
|
31
|
+
export declare function findInLinkedArraysSimpleNumeric<TPrimary extends SearchableObject, TLinked extends SearchableObject>(query: string, linked: NumericLinkedSearchMetadataWithData<TPrimary, TLinked>, limit?: number, opts?: SearchOpts): LinkedSearchResult<TPrimary, TLinked>[];
|
|
32
|
+
//# sourceMappingURL=findInLinkedArrays.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"findInLinkedArrays.d.ts","sourceRoot":"","sources":["../../../src/common/numeric/findInLinkedArrays.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,gBAAgB,EAChB,UAAU,EACV,kBAAkB,EAClB,0BAA0B,EAC3B,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,mCAAmC,EAAE,MAAM,8BAA8B,CAAC;AAQxF;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,yBAAyB,CACvC,QAAQ,SAAS,gBAAgB,EACjC,OAAO,SAAS,gBAAgB,EAEhC,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,mCAAmC,CAAC,QAAQ,EAAE,OAAO,CAAC,EAC9D,KAAK,GAAE,MAAW,EAClB,IAAI,CAAC,EAAE,UAAU,GAChB,0BAA0B,CAAC,QAAQ,EAAE,OAAO,CAAC,CAyJ/C;AAED;;;;GAIG;AACH,wBAAgB,+BAA+B,CAC7C,QAAQ,SAAS,gBAAgB,EACjC,OAAO,SAAS,gBAAgB,EAEhC,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,mCAAmC,CAAC,QAAQ,EAAE,OAAO,CAAC,EAC9D,KAAK,GAAE,MAAW,EAClB,IAAI,CAAC,EAAE,UAAU,GAChB,kBAAkB,CAAC,QAAQ,EAAE,OAAO,CAAC,EAAE,CAEzC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Numeric token implementation - memory-optimized search using Uint32Array
|
|
3
|
+
*/
|
|
4
|
+
export { createSearchArrayMetadataNumeric, prepareObjectForSearchNumeric, encodeTokenWithMode, decodeTokenId, decodeMatchMode, TOKEN_ID_MASK, MATCH_MODE_BITS, } from './createSearchArrayMetadata';
|
|
5
|
+
export { createSearchLinkedMetadataNumeric, type NumericLinkedSearchMetadataWithData, } from './createSearchLinkedMetadata';
|
|
6
|
+
export { updateSearchMetadataNumeric, updateSearchMetadataBatchNumeric, removeFromSearchMetadataNumeric, removeFromSearchMetadataBatchNumeric, } from './updateSearchMetadata';
|
|
7
|
+
export { searchInDataReturnIdsNumeric, searchInDataReturnObjectsNumeric, searchInDataReturnIdsWithLimitNumeric, } from './searchInData';
|
|
8
|
+
export { findInLinkedArraysNumeric, findInLinkedArraysSimpleNumeric, } from './findInLinkedArrays';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Id, NumericSearchMetadata, SearchableData, SearchableObject, SearchOpts } from '../../types';
|
|
2
|
+
/**
|
|
3
|
+
* Searches in numeric metadata and returns matching IDs.
|
|
4
|
+
*
|
|
5
|
+
* @param query - The search query string
|
|
6
|
+
* @param metadata - The NumericSearchMetadata to search in
|
|
7
|
+
* @param opts - Optional search options for match mode
|
|
8
|
+
* @returns Array of matching object IDs
|
|
9
|
+
*/
|
|
10
|
+
export declare function searchInDataReturnIdsNumeric(query: string, metadata: NumericSearchMetadata, opts?: SearchOpts): Id[];
|
|
11
|
+
/**
|
|
12
|
+
* Searches in numeric metadata and returns matching objects.
|
|
13
|
+
*
|
|
14
|
+
* @param query - The search query string
|
|
15
|
+
* @param metadata - The NumericSearchMetadata to search in
|
|
16
|
+
* @param data - The SearchableData map for object lookup
|
|
17
|
+
* @param opts - Optional search options for match mode
|
|
18
|
+
* @returns Map of matching objects by ID
|
|
19
|
+
*/
|
|
20
|
+
export declare function searchInDataReturnObjectsNumeric<T extends SearchableObject>(query: string, metadata: NumericSearchMetadata, data: SearchableData<T>, opts?: SearchOpts): Map<Id, T>;
|
|
21
|
+
/**
|
|
22
|
+
* Searches with a limit and returns matching IDs.
|
|
23
|
+
*
|
|
24
|
+
* @param query - The search query string
|
|
25
|
+
* @param metadata - The NumericSearchMetadata to search in
|
|
26
|
+
* @param limit - Maximum number of results to return
|
|
27
|
+
* @param opts - Optional search options for match mode
|
|
28
|
+
* @returns Array of matching object IDs (up to limit)
|
|
29
|
+
*/
|
|
30
|
+
export declare function searchInDataReturnIdsWithLimitNumeric(query: string, metadata: NumericSearchMetadata, limit: number, opts?: SearchOpts): Id[];
|
|
31
|
+
//# sourceMappingURL=searchInData.d.ts.map
|
|
@@ -0,0 +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,CAoBN;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"}
|