@wovvmap/map-data 0.0.0-stage → 1.2.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/README.md +65 -2
- package/dist/adapters/index.d.ts +12 -0
- package/dist/adapters/index.d.ts.map +1 -0
- package/dist/adapters/index.js +16 -0
- package/dist/adapters/sdkApiAdapter.d.ts +20 -0
- package/dist/adapters/sdkApiAdapter.d.ts.map +1 -0
- package/dist/adapters/sdkApiAdapter.js +31 -0
- package/dist/adapters/types.d.ts +84 -0
- package/dist/adapters/types.d.ts.map +1 -0
- package/dist/adapters/types.js +8 -0
- package/dist/cache/mallMapCache.types.d.ts +32 -0
- package/dist/cache/mallMapCache.types.d.ts.map +1 -0
- package/dist/cache/mallMapCache.types.js +1 -0
- package/dist/cache/memoryMallMapCache.d.ts +37 -0
- package/dist/cache/memoryMallMapCache.d.ts.map +1 -0
- package/dist/cache/memoryMallMapCache.js +44 -0
- package/dist/catalog/catalogIndexReadPort.d.ts +35 -0
- package/dist/catalog/catalogIndexReadPort.d.ts.map +1 -0
- package/dist/catalog/catalogIndexReadPort.js +1 -0
- package/dist/catalog/catalogReader.d.ts +496 -0
- package/dist/catalog/catalogReader.d.ts.map +1 -0
- package/dist/catalog/catalogReader.js +1799 -0
- package/dist/catalog/index.d.ts +9 -0
- package/dist/catalog/index.d.ts.map +1 -0
- package/dist/catalog/index.js +6 -0
- package/dist/catalog/offerAvailability.d.ts +25 -0
- package/dist/catalog/offerAvailability.d.ts.map +1 -0
- package/dist/catalog/offerAvailability.js +107 -0
- package/dist/controllers/mallController.d.ts +69 -0
- package/dist/controllers/mallController.d.ts.map +1 -0
- package/dist/controllers/mallController.js +92 -0
- package/dist/controllers/mallController.types.d.ts +10 -0
- package/dist/controllers/mallController.types.d.ts.map +1 -0
- package/dist/controllers/mallController.types.js +1 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +22 -0
- package/dist/indexer/nodeDataIndexer.types.d.ts +16 -0
- package/dist/indexer/nodeDataIndexer.types.d.ts.map +1 -0
- package/dist/indexer/nodeDataIndexer.types.js +1 -0
- package/dist/models/catalog.d.ts +2 -0
- package/dist/models/catalog.d.ts.map +1 -0
- package/dist/models/catalog.js +1 -0
- package/dist/models/floor.d.ts +16 -0
- package/dist/models/floor.d.ts.map +1 -0
- package/dist/models/floor.js +1 -0
- package/dist/models/mall.d.ts +29 -0
- package/dist/models/mall.d.ts.map +1 -0
- package/dist/models/mall.js +1 -0
- package/dist/parser/index.d.ts +3 -0
- package/dist/parser/index.d.ts.map +1 -0
- package/dist/parser/index.js +1 -0
- package/dist/parser/mapParser.types.d.ts +34 -0
- package/dist/parser/mapParser.types.d.ts.map +1 -0
- package/dist/parser/mapParser.types.js +1 -0
- package/dist/parser/mapParserService.d.ts +8 -0
- package/dist/parser/mapParserService.d.ts.map +1 -0
- package/dist/parser/mapParserService.js +61 -0
- package/dist/prepared/index.d.ts +3 -0
- package/dist/prepared/index.d.ts.map +1 -0
- package/dist/prepared/index.js +2 -0
- package/dist/prepared/preparedGeometryValidation.d.ts +6 -0
- package/dist/prepared/preparedGeometryValidation.d.ts.map +1 -0
- package/dist/prepared/preparedGeometryValidation.js +76 -0
- package/dist/prepared/preparedMapFields.d.ts +36 -0
- package/dist/prepared/preparedMapFields.d.ts.map +1 -0
- package/dist/prepared/preparedMapFields.js +205 -0
- package/dist/prepared/preparedMapReader.d.ts +68 -0
- package/dist/prepared/preparedMapReader.d.ts.map +1 -0
- package/dist/prepared/preparedMapReader.js +231 -0
- package/dist/prepared/preparedMapValidation.d.ts +23 -0
- package/dist/prepared/preparedMapValidation.d.ts.map +1 -0
- package/dist/prepared/preparedMapValidation.js +216 -0
- package/dist/search/catalogEndpointLookup.d.ts +23 -0
- package/dist/search/catalogEndpointLookup.d.ts.map +1 -0
- package/dist/search/catalogEndpointLookup.js +56 -0
- package/dist/search/catalogSearchService.d.ts +182 -0
- package/dist/search/catalogSearchService.d.ts.map +1 -0
- package/dist/search/catalogSearchService.js +653 -0
- package/dist/search/searchProfiles.d.ts +240 -0
- package/dist/search/searchProfiles.d.ts.map +1 -0
- package/dist/search/searchProfiles.js +364 -0
- package/dist/services/mallService.d.ts +82 -0
- package/dist/services/mallService.d.ts.map +1 -0
- package/dist/services/mallService.js +230 -0
- package/dist/services/mallService.types.d.ts +51 -0
- package/dist/services/mallService.types.d.ts.map +1 -0
- package/dist/services/mallService.types.js +1 -0
- package/dist/transport/fetchHttpClient.d.ts +25 -0
- package/dist/transport/fetchHttpClient.d.ts.map +1 -0
- package/dist/transport/fetchHttpClient.js +170 -0
- package/dist/transport/httpClient.types.d.ts +26 -0
- package/dist/transport/httpClient.types.d.ts.map +1 -0
- package/dist/transport/httpClient.types.js +1 -0
- package/dist/transport/httpTransportError.d.ts +25 -0
- package/dist/transport/httpTransportError.d.ts.map +1 -0
- package/dist/transport/httpTransportError.js +16 -0
- package/package.json +33 -3
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file searchProfiles.ts
|
|
3
|
+
* @description Reusable WovVMap search field profiles for stores, categories, subcategories, and amenities,
|
|
4
|
+
* plus multi-location group ranking and display-representative policy helpers.
|
|
5
|
+
* Hinglish: Store, category, subcategory aur amenity records ke liye reusable `@wovvmap/search-core` field profiles
|
|
6
|
+
* aur multi-location group ranking/representative policy helpers.
|
|
7
|
+
*/
|
|
8
|
+
import type { PublicAmenityData, PublicCategoryData, PublicNodeData, PublicSubCategoryData } from '@wovvmap/contracts';
|
|
9
|
+
import { type PaidPromotionMatchGroup, type SearchIndex, type SearchIndexConfig, type SearchQueryOptions, type SearchResultItem, type SearchSortMode } from '@wovvmap/search-core';
|
|
10
|
+
/**
|
|
11
|
+
* Verified baseline searchable field weights for WovVMap store records (`PublicNodeData`).
|
|
12
|
+
* Preserves legacy `DirectionInput.tsx` store-name (`100`) and description (`7`) weight ratio.
|
|
13
|
+
*
|
|
14
|
+
* Hinglish: Store search ke liye verified field weights (`name: 100`, `description: 7`).
|
|
15
|
+
*/
|
|
16
|
+
export declare const STORE_SEARCH_FIELD_WEIGHTS: Readonly<{
|
|
17
|
+
readonly name: 100;
|
|
18
|
+
readonly description: 7;
|
|
19
|
+
}>;
|
|
20
|
+
/**
|
|
21
|
+
* Baseline searchable field weights for public category records (`PublicCategoryData`).
|
|
22
|
+
*
|
|
23
|
+
* Hinglish: Category search ke liye field weights (`name: 100`, `code: 40`).
|
|
24
|
+
*/
|
|
25
|
+
export declare const CATEGORY_SEARCH_FIELD_WEIGHTS: Readonly<{
|
|
26
|
+
readonly name: 100;
|
|
27
|
+
readonly code: 40;
|
|
28
|
+
}>;
|
|
29
|
+
/**
|
|
30
|
+
* Baseline searchable field weights for public subcategory records (`PublicSubCategoryData`).
|
|
31
|
+
*
|
|
32
|
+
* Hinglish: Subcategory search ke liye field weights (`name: 100`, `code: 40`, `description: 15`).
|
|
33
|
+
*/
|
|
34
|
+
export declare const SUBCATEGORY_SEARCH_FIELD_WEIGHTS: Readonly<{
|
|
35
|
+
readonly name: 100;
|
|
36
|
+
readonly code: 40;
|
|
37
|
+
readonly description: 15;
|
|
38
|
+
}>;
|
|
39
|
+
/**
|
|
40
|
+
* Baseline searchable field weights for public amenity records (`PublicAmenityData`).
|
|
41
|
+
*
|
|
42
|
+
* Hinglish: Amenity search ke liye field weights (`name: 100`, `fieldCode: 50`, `id: 30`).
|
|
43
|
+
*/
|
|
44
|
+
export declare const AMENITY_SEARCH_FIELD_WEIGHTS: Readonly<{
|
|
45
|
+
readonly name: 100;
|
|
46
|
+
readonly fieldCode: 50;
|
|
47
|
+
readonly id: 30;
|
|
48
|
+
}>;
|
|
49
|
+
/**
|
|
50
|
+
* Reusable `@wovvmap/search-core` configuration profile for `PublicNodeData` store records.
|
|
51
|
+
* Extracts `assets.locationName.text`, `contactInfo.description`, canonical `floorIndex` (preserving ground floor `0`),
|
|
52
|
+
* and canonical `paidPromotion` keyword weights once during index preparation.
|
|
53
|
+
*
|
|
54
|
+
* Hinglish: `PublicNodeData` stores ke liye reusable search index profile jo `locationName.text`,
|
|
55
|
+
* `contactInfo.description`, `floorIndex` aur canonical `paidPromotion` weights ko index preparation me map karta hai.
|
|
56
|
+
*/
|
|
57
|
+
export declare const STORE_SEARCH_INDEX_CONFIG: SearchIndexConfig<PublicNodeData>;
|
|
58
|
+
/**
|
|
59
|
+
* Reusable `@wovvmap/search-core` configuration profile for `PublicCategoryData` records.
|
|
60
|
+
* Indexes only public category `name` and `code` without scanning child member nodes or inventing promotions.
|
|
61
|
+
*
|
|
62
|
+
* Hinglish: `PublicCategoryData` ke liye reusable search profile (`name` aur `code`); child stores scan nahi karta.
|
|
63
|
+
*/
|
|
64
|
+
export declare const CATEGORY_SEARCH_INDEX_CONFIG: SearchIndexConfig<PublicCategoryData>;
|
|
65
|
+
/**
|
|
66
|
+
* Reusable `@wovvmap/search-core` configuration profile for `PublicSubCategoryData` records.
|
|
67
|
+
* Indexes `name`, `code`, and `description`; parent category eligibility is supplied by the caller via `eligibleIds`.
|
|
68
|
+
*
|
|
69
|
+
* Hinglish: `PublicSubCategoryData` ke liye reusable search profile (`name`, `code`, `description`);
|
|
70
|
+
* parent category filter caller dwara `eligibleIds` se diya jata hai.
|
|
71
|
+
*/
|
|
72
|
+
export declare const SUBCATEGORY_SEARCH_INDEX_CONFIG: SearchIndexConfig<PublicSubCategoryData>;
|
|
73
|
+
/**
|
|
74
|
+
* Reusable `@wovvmap/search-core` configuration profile for `PublicAmenityData` records.
|
|
75
|
+
* Indexes only `name`, `fieldCode`, and `id`; never scans `memberKeys` or `nodePoints` arrays.
|
|
76
|
+
*
|
|
77
|
+
* Hinglish: `PublicAmenityData` ke liye reusable search profile (`name`, `fieldCode`, `id`);
|
|
78
|
+
* member-node arrays ko kabhi scan nahi karta.
|
|
79
|
+
*/
|
|
80
|
+
export declare const AMENITY_SEARCH_INDEX_CONFIG: SearchIndexConfig<PublicAmenityData>;
|
|
81
|
+
/**
|
|
82
|
+
* Creates a prepared `SearchIndex<PublicNodeData>` using the canonical store search profile.
|
|
83
|
+
*
|
|
84
|
+
* Hinglish: Canonical store search profile ke saath `SearchIndex<PublicNodeData>` banata hai.
|
|
85
|
+
*/
|
|
86
|
+
export declare function createStoreSearchIndex(stores: readonly PublicNodeData[], overrides?: Omit<Partial<SearchIndexConfig<PublicNodeData>>, 'fields'>): SearchIndex<PublicNodeData>;
|
|
87
|
+
/**
|
|
88
|
+
* Creates a prepared `SearchIndex<PublicCategoryData>` using the canonical category search profile.
|
|
89
|
+
*
|
|
90
|
+
* Hinglish: Canonical category search profile ke saath `SearchIndex<PublicCategoryData>` banata hai.
|
|
91
|
+
*/
|
|
92
|
+
export declare function createCategorySearchIndex(categories: readonly PublicCategoryData[], overrides?: Omit<Partial<SearchIndexConfig<PublicCategoryData>>, 'fields'>): SearchIndex<PublicCategoryData>;
|
|
93
|
+
/**
|
|
94
|
+
* Creates a prepared `SearchIndex<PublicSubCategoryData>` using the canonical subcategory search profile.
|
|
95
|
+
*
|
|
96
|
+
* Hinglish: Canonical subcategory search profile ke saath `SearchIndex<PublicSubCategoryData>` banata hai.
|
|
97
|
+
*/
|
|
98
|
+
export declare function createSubCategorySearchIndex(subCategories: readonly PublicSubCategoryData[], overrides?: Omit<Partial<SearchIndexConfig<PublicSubCategoryData>>, 'fields'>): SearchIndex<PublicSubCategoryData>;
|
|
99
|
+
/**
|
|
100
|
+
* Creates a prepared `SearchIndex<PublicAmenityData>` using the canonical amenity search profile.
|
|
101
|
+
*
|
|
102
|
+
* Hinglish: Canonical amenity search profile ke saath `SearchIndex<PublicAmenityData>` banata hai.
|
|
103
|
+
*/
|
|
104
|
+
export declare function createAmenitySearchIndex(amenities: readonly PublicAmenityData[], overrides?: Omit<Partial<SearchIndexConfig<PublicAmenityData>>, 'fields'>): SearchIndex<PublicAmenityData>;
|
|
105
|
+
/**
|
|
106
|
+
* Single-location ranked store search entry produced by `rankGroupedStoreSearchResults`.
|
|
107
|
+
*
|
|
108
|
+
* Hinglish: Single-location store ka ranked search entry.
|
|
109
|
+
*/
|
|
110
|
+
export interface RankedSingleStoreSearchEntry {
|
|
111
|
+
readonly kind: 'store';
|
|
112
|
+
readonly nodeKey: string;
|
|
113
|
+
readonly score: number;
|
|
114
|
+
readonly matchedTerms: string[];
|
|
115
|
+
readonly matchedFields: string[];
|
|
116
|
+
readonly floorIndex?: number;
|
|
117
|
+
readonly paidPromotionGroup?: PaidPromotionMatchGroup;
|
|
118
|
+
readonly paidPromotionWeight?: number;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Multi-location grouped ranked store search entry produced by `rankGroupedStoreSearchResults`.
|
|
122
|
+
* Separates `rankingMemberKey` (the strongest ranked eligible member that determined the group's rank)
|
|
123
|
+
* from `representativeKey` (the display representative, preferring `activeFloorIndex` when available),
|
|
124
|
+
* while preserving all eligible matched `memberKeys` for group selection, highlighting, and routing.
|
|
125
|
+
*
|
|
126
|
+
* Hinglish: Multi-location group ka ranked search entry jisme `rankingMemberKey` (group ki rank tay karne wala strongest member)
|
|
127
|
+
* aur `representativeKey` (display representative) alag rehte hain, aur saare eligible `memberKeys` सुरक्षित rehte hain.
|
|
128
|
+
*/
|
|
129
|
+
export interface RankedGroupStoreSearchEntry {
|
|
130
|
+
readonly kind: 'group';
|
|
131
|
+
readonly groupId: string;
|
|
132
|
+
readonly rankingMemberKey: string;
|
|
133
|
+
readonly representativeKey: string;
|
|
134
|
+
readonly memberKeys: string[];
|
|
135
|
+
readonly availableFloors?: number[];
|
|
136
|
+
readonly score: number;
|
|
137
|
+
readonly matchedTerms: string[];
|
|
138
|
+
readonly matchedFields: string[];
|
|
139
|
+
readonly floorIndex?: number;
|
|
140
|
+
readonly paidPromotionGroup?: PaidPromotionMatchGroup;
|
|
141
|
+
readonly paidPromotionWeight?: number;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Discriminated union of ranked single-store and grouped-store search entries.
|
|
145
|
+
*
|
|
146
|
+
* Hinglish: Single store ya multi-location group ka discriminated ranked search entry.
|
|
147
|
+
*/
|
|
148
|
+
export type RankedStoreSearchEntry = RankedSingleStoreSearchEntry | RankedGroupStoreSearchEntry;
|
|
149
|
+
/**
|
|
150
|
+
* Options for collapsing ordered store search hits into ranked single/group entries using canonical group identity.
|
|
151
|
+
*
|
|
152
|
+
* Hinglish: Ordered store search hits ko canonical group identity ke hisab se group aur rank karne ke options.
|
|
153
|
+
*/
|
|
154
|
+
export interface GroupStoreSearchRankingOptions {
|
|
155
|
+
/**
|
|
156
|
+
* Resolves the canonical `groupId` for a store `nodeKey` from `map-data` indexes (or `null`/`undefined` if ungrouped).
|
|
157
|
+
* Must reuse the canonical location-name group identity rather than brand IDs.
|
|
158
|
+
*
|
|
159
|
+
* Hinglish: Store `nodeKey` ke liye `map-data` ka canonical `groupId` return karne wala lookup function.
|
|
160
|
+
*/
|
|
161
|
+
readonly getGroupId: (nodeKey: string) => string | null | undefined;
|
|
162
|
+
/**
|
|
163
|
+
* Optional active floor index (`0` = ground floor is valid) used to prefer an eligible matched member
|
|
164
|
+
* on the active floor as `representativeKey` without shrinking `memberKeys` or changing the group's rank.
|
|
165
|
+
*
|
|
166
|
+
* Hinglish: Display `representativeKey` ke liye active floor (`0` ground floor valid hai) prefer karne ka option.
|
|
167
|
+
*/
|
|
168
|
+
readonly activeFloorIndex?: number;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Collapses the **complete ordered eligible matches** (`SearchIndex.searchAll(...)`) into ranked single/group entries
|
|
172
|
+
* **before** row-level pagination is applied:
|
|
173
|
+
* 1. Input MUST be the complete unpaginated match list (`searchAll().items`), never a pre-paginated `.items` slice,
|
|
174
|
+
* so multi-location stores are never split across pages and `memberKeys` / `representativeKey` are always complete.
|
|
175
|
+
* 2. Group rank position, `score`, `paidPromotionGroup`, and `paidPromotionWeight` derive strictly from the
|
|
176
|
+
* strongest-ranked eligible matched member (its first occurrence in `completeOrderedMatches`).
|
|
177
|
+
* 3. Multiple locations of the same business never sum their scores or promotion weights.
|
|
178
|
+
* 4. Only eligible matched members present in `completeOrderedMatches` are included in `memberKeys`; excluded members never re-enter.
|
|
179
|
+
* 5. `representativeKey` prefers an eligible matched member on `activeFloorIndex` when present, tracked in a single collection pass
|
|
180
|
+
* without shrinking `memberKeys` or altering `rankingMemberKey`.
|
|
181
|
+
*
|
|
182
|
+
* Hinglish: `SearchIndex.searchAll(...)` ke complete ordered matches ko pagination se pehle canonical `groupId` se group karta hai:
|
|
183
|
+
* - Same store alag pages par nahi tootta aur `memberKeys` / active-floor `representativeKey` hamesha complete rehte hain.
|
|
184
|
+
* - Group ki rank uske strongest matched member se aati hai (multiple locations ke weights ya scores add nahi hote).
|
|
185
|
+
* - Excluded locations wapas group me nahi aati.
|
|
186
|
+
*/
|
|
187
|
+
export declare function rankGroupedStoreSearchResults(completeOrderedMatches: readonly SearchResultItem[], options: GroupStoreSearchRankingOptions): RankedStoreSearchEntry[];
|
|
188
|
+
/**
|
|
189
|
+
* Options for executing the full grouped store search pipeline:
|
|
190
|
+
* `Eligibility filter -> matching/ranking -> complete eligible matches ki grouping -> grouped row counts -> pagination`.
|
|
191
|
+
*
|
|
192
|
+
* Hinglish: Complete store search pipeline (`eligibility -> matching/ranking -> complete grouping -> grouped counts -> pagination`) ke options.
|
|
193
|
+
*/
|
|
194
|
+
export interface GroupedStoreSearchQueryOptions extends SearchQueryOptions {
|
|
195
|
+
/**
|
|
196
|
+
* Resolves the canonical `groupId` for a store `nodeKey` from `map-data` indexes (or `null`/`undefined` if ungrouped).
|
|
197
|
+
*
|
|
198
|
+
* Hinglish: Store `nodeKey` ke liye `map-data` ka canonical `groupId` return karne wala lookup function.
|
|
199
|
+
*/
|
|
200
|
+
readonly getGroupId: (nodeKey: string) => string | null | undefined;
|
|
201
|
+
/**
|
|
202
|
+
* Whether multi-location stores sharing a canonical `groupId` should be collapsed into a single grouped row
|
|
203
|
+
* before pagination. Default: `true`.
|
|
204
|
+
*
|
|
205
|
+
* Hinglish: Kya multi-location stores ko pagination se pehle ek group row me collapse karna hai (Default: `true`).
|
|
206
|
+
*/
|
|
207
|
+
readonly groupMultiLocation?: boolean;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Paginated store search result page produced after grouping complete eligible matches.
|
|
211
|
+
* Separates `totalRows` (count of grouped/single rows) from `totalMemberCount` (count of underlying matched store keys).
|
|
212
|
+
*
|
|
213
|
+
* Hinglish: Complete eligible matches ki grouping ke baad paginate kiya gaya store search result page;
|
|
214
|
+
* isme `totalRows` (grouped rows count) aur `totalMemberCount` (matched store keys count) alag rehte hain.
|
|
215
|
+
*/
|
|
216
|
+
export interface GroupedStoreSearchPageResult {
|
|
217
|
+
readonly query: string;
|
|
218
|
+
readonly sortBy: SearchSortMode;
|
|
219
|
+
readonly items: RankedStoreSearchEntry[];
|
|
220
|
+
readonly totalRows: number;
|
|
221
|
+
readonly totalMemberCount: number;
|
|
222
|
+
readonly totalIndexed: number;
|
|
223
|
+
readonly offset: number;
|
|
224
|
+
readonly limit: number;
|
|
225
|
+
readonly hasMore: boolean;
|
|
226
|
+
readonly nextOffset: number | null;
|
|
227
|
+
readonly availableFloors: number[];
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Executes the canonical store search pipeline in the required order:
|
|
231
|
+
* 1. Eligibility filtering (`eligibleIds`) + text/promotion matching & ranking over all eligible candidates (`storeIndex.searchAll`).
|
|
232
|
+
* 2. Complete eligible match grouping (`rankGroupedStoreSearchResults`) so multi-location stores never split across pages.
|
|
233
|
+
* 3. Separate `totalRows` (grouped row count) and `totalMemberCount` (matched member key count).
|
|
234
|
+
* 4. Bounded row-level pagination (`offset`, `limit`, `limit: 0` safe, `hasMore`, `nextOffset`).
|
|
235
|
+
*
|
|
236
|
+
* Hinglish: Canonical store search pipeline run karta hai:
|
|
237
|
+
* `Eligibility filter -> matching/ranking (searchAll) -> complete eligible matches ki grouping -> grouped row counts -> pagination`.
|
|
238
|
+
*/
|
|
239
|
+
export declare function executeGroupedStoreSearch(storeIndex: SearchIndex<PublicNodeData>, query: string, options: GroupedStoreSearchQueryOptions): GroupedStoreSearchPageResult;
|
|
240
|
+
//# sourceMappingURL=searchProfiles.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"searchProfiles.d.ts","sourceRoot":"","sources":["../../src/search/searchProfiles.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file searchProfiles.ts
|
|
3
|
+
* @description Reusable WovVMap search field profiles for stores, categories, subcategories, and amenities,
|
|
4
|
+
* plus multi-location group ranking and display-representative policy helpers.
|
|
5
|
+
* Hinglish: Store, category, subcategory aur amenity records ke liye reusable `@wovvmap/search-core` field profiles
|
|
6
|
+
* aur multi-location group ranking/representative policy helpers.
|
|
7
|
+
*/
|
|
8
|
+
import { createSearchIndex, } from '@wovvmap/search-core';
|
|
9
|
+
/**
|
|
10
|
+
* Verified baseline searchable field weights for WovVMap store records (`PublicNodeData`).
|
|
11
|
+
* Preserves legacy `DirectionInput.tsx` store-name (`100`) and description (`7`) weight ratio.
|
|
12
|
+
*
|
|
13
|
+
* Hinglish: Store search ke liye verified field weights (`name: 100`, `description: 7`).
|
|
14
|
+
*/
|
|
15
|
+
export const STORE_SEARCH_FIELD_WEIGHTS = Object.freeze({
|
|
16
|
+
name: 100,
|
|
17
|
+
description: 7,
|
|
18
|
+
});
|
|
19
|
+
/**
|
|
20
|
+
* Baseline searchable field weights for public category records (`PublicCategoryData`).
|
|
21
|
+
*
|
|
22
|
+
* Hinglish: Category search ke liye field weights (`name: 100`, `code: 40`).
|
|
23
|
+
*/
|
|
24
|
+
export const CATEGORY_SEARCH_FIELD_WEIGHTS = Object.freeze({
|
|
25
|
+
name: 100,
|
|
26
|
+
code: 40,
|
|
27
|
+
});
|
|
28
|
+
/**
|
|
29
|
+
* Baseline searchable field weights for public subcategory records (`PublicSubCategoryData`).
|
|
30
|
+
*
|
|
31
|
+
* Hinglish: Subcategory search ke liye field weights (`name: 100`, `code: 40`, `description: 15`).
|
|
32
|
+
*/
|
|
33
|
+
export const SUBCATEGORY_SEARCH_FIELD_WEIGHTS = Object.freeze({
|
|
34
|
+
name: 100,
|
|
35
|
+
code: 40,
|
|
36
|
+
description: 15,
|
|
37
|
+
});
|
|
38
|
+
/**
|
|
39
|
+
* Baseline searchable field weights for public amenity records (`PublicAmenityData`).
|
|
40
|
+
*
|
|
41
|
+
* Hinglish: Amenity search ke liye field weights (`name: 100`, `fieldCode: 50`, `id: 30`).
|
|
42
|
+
*/
|
|
43
|
+
export const AMENITY_SEARCH_FIELD_WEIGHTS = Object.freeze({
|
|
44
|
+
name: 100,
|
|
45
|
+
fieldCode: 50,
|
|
46
|
+
id: 30,
|
|
47
|
+
});
|
|
48
|
+
/**
|
|
49
|
+
* Reusable `@wovvmap/search-core` configuration profile for `PublicNodeData` store records.
|
|
50
|
+
* Extracts `assets.locationName.text`, `contactInfo.description`, canonical `floorIndex` (preserving ground floor `0`),
|
|
51
|
+
* and canonical `paidPromotion` keyword weights once during index preparation.
|
|
52
|
+
*
|
|
53
|
+
* Hinglish: `PublicNodeData` stores ke liye reusable search index profile jo `locationName.text`,
|
|
54
|
+
* `contactInfo.description`, `floorIndex` aur canonical `paidPromotion` weights ko index preparation me map karta hai.
|
|
55
|
+
*/
|
|
56
|
+
export const STORE_SEARCH_INDEX_CONFIG = Object.freeze({
|
|
57
|
+
getId: (store) => store.key,
|
|
58
|
+
getLabel: (store) => store.assets.locationName?.text ?? '',
|
|
59
|
+
getFloorIndex: (store) => store.floorIndex,
|
|
60
|
+
getPaidPromotion: (store) => store.paidPromotion,
|
|
61
|
+
fields: Object.freeze([
|
|
62
|
+
Object.freeze({
|
|
63
|
+
name: 'name',
|
|
64
|
+
weight: STORE_SEARCH_FIELD_WEIGHTS.name,
|
|
65
|
+
get: (store) => store.assets.locationName?.text,
|
|
66
|
+
}),
|
|
67
|
+
Object.freeze({
|
|
68
|
+
name: 'description',
|
|
69
|
+
weight: STORE_SEARCH_FIELD_WEIGHTS.description,
|
|
70
|
+
get: (store) => store.contactInfo.description,
|
|
71
|
+
}),
|
|
72
|
+
]),
|
|
73
|
+
});
|
|
74
|
+
/**
|
|
75
|
+
* Reusable `@wovvmap/search-core` configuration profile for `PublicCategoryData` records.
|
|
76
|
+
* Indexes only public category `name` and `code` without scanning child member nodes or inventing promotions.
|
|
77
|
+
*
|
|
78
|
+
* Hinglish: `PublicCategoryData` ke liye reusable search profile (`name` aur `code`); child stores scan nahi karta.
|
|
79
|
+
*/
|
|
80
|
+
export const CATEGORY_SEARCH_INDEX_CONFIG = Object.freeze({
|
|
81
|
+
getId: (category) => String(category.code),
|
|
82
|
+
getLabel: (category) => category.name,
|
|
83
|
+
fields: Object.freeze([
|
|
84
|
+
Object.freeze({
|
|
85
|
+
name: 'name',
|
|
86
|
+
weight: CATEGORY_SEARCH_FIELD_WEIGHTS.name,
|
|
87
|
+
get: (category) => category.name,
|
|
88
|
+
}),
|
|
89
|
+
Object.freeze({
|
|
90
|
+
name: 'code',
|
|
91
|
+
weight: CATEGORY_SEARCH_FIELD_WEIGHTS.code,
|
|
92
|
+
get: (category) => String(category.code),
|
|
93
|
+
}),
|
|
94
|
+
]),
|
|
95
|
+
});
|
|
96
|
+
/**
|
|
97
|
+
* Reusable `@wovvmap/search-core` configuration profile for `PublicSubCategoryData` records.
|
|
98
|
+
* Indexes `name`, `code`, and `description`; parent category eligibility is supplied by the caller via `eligibleIds`.
|
|
99
|
+
*
|
|
100
|
+
* Hinglish: `PublicSubCategoryData` ke liye reusable search profile (`name`, `code`, `description`);
|
|
101
|
+
* parent category filter caller dwara `eligibleIds` se diya jata hai.
|
|
102
|
+
*/
|
|
103
|
+
export const SUBCATEGORY_SEARCH_INDEX_CONFIG = Object.freeze({
|
|
104
|
+
getId: (subCategory) => String(subCategory.code),
|
|
105
|
+
getLabel: (subCategory) => subCategory.name,
|
|
106
|
+
fields: Object.freeze([
|
|
107
|
+
Object.freeze({
|
|
108
|
+
name: 'name',
|
|
109
|
+
weight: SUBCATEGORY_SEARCH_FIELD_WEIGHTS.name,
|
|
110
|
+
get: (subCategory) => subCategory.name,
|
|
111
|
+
}),
|
|
112
|
+
Object.freeze({
|
|
113
|
+
name: 'code',
|
|
114
|
+
weight: SUBCATEGORY_SEARCH_FIELD_WEIGHTS.code,
|
|
115
|
+
get: (subCategory) => String(subCategory.code),
|
|
116
|
+
}),
|
|
117
|
+
Object.freeze({
|
|
118
|
+
name: 'description',
|
|
119
|
+
weight: SUBCATEGORY_SEARCH_FIELD_WEIGHTS.description,
|
|
120
|
+
get: (subCategory) => subCategory.description,
|
|
121
|
+
}),
|
|
122
|
+
]),
|
|
123
|
+
});
|
|
124
|
+
/**
|
|
125
|
+
* Reusable `@wovvmap/search-core` configuration profile for `PublicAmenityData` records.
|
|
126
|
+
* Indexes only `name`, `fieldCode`, and `id`; never scans `memberKeys` or `nodePoints` arrays.
|
|
127
|
+
*
|
|
128
|
+
* Hinglish: `PublicAmenityData` ke liye reusable search profile (`name`, `fieldCode`, `id`);
|
|
129
|
+
* member-node arrays ko kabhi scan nahi karta.
|
|
130
|
+
*/
|
|
131
|
+
export const AMENITY_SEARCH_INDEX_CONFIG = Object.freeze({
|
|
132
|
+
getId: (amenity) => String(amenity.id),
|
|
133
|
+
getLabel: (amenity) => amenity.name,
|
|
134
|
+
fields: Object.freeze([
|
|
135
|
+
Object.freeze({
|
|
136
|
+
name: 'name',
|
|
137
|
+
weight: AMENITY_SEARCH_FIELD_WEIGHTS.name,
|
|
138
|
+
get: (amenity) => amenity.name,
|
|
139
|
+
}),
|
|
140
|
+
Object.freeze({
|
|
141
|
+
name: 'fieldCode',
|
|
142
|
+
weight: AMENITY_SEARCH_FIELD_WEIGHTS.fieldCode,
|
|
143
|
+
get: (amenity) => String(amenity.fieldCode),
|
|
144
|
+
}),
|
|
145
|
+
Object.freeze({
|
|
146
|
+
name: 'id',
|
|
147
|
+
weight: AMENITY_SEARCH_FIELD_WEIGHTS.id,
|
|
148
|
+
get: (amenity) => String(amenity.id),
|
|
149
|
+
}),
|
|
150
|
+
]),
|
|
151
|
+
});
|
|
152
|
+
/**
|
|
153
|
+
* Creates a prepared `SearchIndex<PublicNodeData>` using the canonical store search profile.
|
|
154
|
+
*
|
|
155
|
+
* Hinglish: Canonical store search profile ke saath `SearchIndex<PublicNodeData>` banata hai.
|
|
156
|
+
*/
|
|
157
|
+
export function createStoreSearchIndex(stores, overrides) {
|
|
158
|
+
return createSearchIndex(stores, overrides ? { ...STORE_SEARCH_INDEX_CONFIG, ...overrides } : STORE_SEARCH_INDEX_CONFIG);
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Creates a prepared `SearchIndex<PublicCategoryData>` using the canonical category search profile.
|
|
162
|
+
*
|
|
163
|
+
* Hinglish: Canonical category search profile ke saath `SearchIndex<PublicCategoryData>` banata hai.
|
|
164
|
+
*/
|
|
165
|
+
export function createCategorySearchIndex(categories, overrides) {
|
|
166
|
+
return createSearchIndex(categories, overrides ? { ...CATEGORY_SEARCH_INDEX_CONFIG, ...overrides } : CATEGORY_SEARCH_INDEX_CONFIG);
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Creates a prepared `SearchIndex<PublicSubCategoryData>` using the canonical subcategory search profile.
|
|
170
|
+
*
|
|
171
|
+
* Hinglish: Canonical subcategory search profile ke saath `SearchIndex<PublicSubCategoryData>` banata hai.
|
|
172
|
+
*/
|
|
173
|
+
export function createSubCategorySearchIndex(subCategories, overrides) {
|
|
174
|
+
return createSearchIndex(subCategories, overrides
|
|
175
|
+
? { ...SUBCATEGORY_SEARCH_INDEX_CONFIG, ...overrides }
|
|
176
|
+
: SUBCATEGORY_SEARCH_INDEX_CONFIG);
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Creates a prepared `SearchIndex<PublicAmenityData>` using the canonical amenity search profile.
|
|
180
|
+
*
|
|
181
|
+
* Hinglish: Canonical amenity search profile ke saath `SearchIndex<PublicAmenityData>` banata hai.
|
|
182
|
+
*/
|
|
183
|
+
export function createAmenitySearchIndex(amenities, overrides) {
|
|
184
|
+
return createSearchIndex(amenities, overrides ? { ...AMENITY_SEARCH_INDEX_CONFIG, ...overrides } : AMENITY_SEARCH_INDEX_CONFIG);
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Collapses the **complete ordered eligible matches** (`SearchIndex.searchAll(...)`) into ranked single/group entries
|
|
188
|
+
* **before** row-level pagination is applied:
|
|
189
|
+
* 1. Input MUST be the complete unpaginated match list (`searchAll().items`), never a pre-paginated `.items` slice,
|
|
190
|
+
* so multi-location stores are never split across pages and `memberKeys` / `representativeKey` are always complete.
|
|
191
|
+
* 2. Group rank position, `score`, `paidPromotionGroup`, and `paidPromotionWeight` derive strictly from the
|
|
192
|
+
* strongest-ranked eligible matched member (its first occurrence in `completeOrderedMatches`).
|
|
193
|
+
* 3. Multiple locations of the same business never sum their scores or promotion weights.
|
|
194
|
+
* 4. Only eligible matched members present in `completeOrderedMatches` are included in `memberKeys`; excluded members never re-enter.
|
|
195
|
+
* 5. `representativeKey` prefers an eligible matched member on `activeFloorIndex` when present, tracked in a single collection pass
|
|
196
|
+
* without shrinking `memberKeys` or altering `rankingMemberKey`.
|
|
197
|
+
*
|
|
198
|
+
* Hinglish: `SearchIndex.searchAll(...)` ke complete ordered matches ko pagination se pehle canonical `groupId` se group karta hai:
|
|
199
|
+
* - Same store alag pages par nahi tootta aur `memberKeys` / active-floor `representativeKey` hamesha complete rehte hain.
|
|
200
|
+
* - Group ki rank uske strongest matched member se aati hai (multiple locations ke weights ya scores add nahi hote).
|
|
201
|
+
* - Excluded locations wapas group me nahi aati.
|
|
202
|
+
*/
|
|
203
|
+
export function rankGroupedStoreSearchResults(completeOrderedMatches, options) {
|
|
204
|
+
if (completeOrderedMatches.length === 0) {
|
|
205
|
+
return [];
|
|
206
|
+
}
|
|
207
|
+
const activeFloor = typeof options.activeFloorIndex === 'number' && Number.isFinite(options.activeFloorIndex)
|
|
208
|
+
? options.activeFloorIndex
|
|
209
|
+
: undefined;
|
|
210
|
+
const groupBuckets = new Map();
|
|
211
|
+
const orderedSlots = [];
|
|
212
|
+
for (let i = 0; i < completeOrderedMatches.length; i++) {
|
|
213
|
+
const item = completeOrderedMatches[i];
|
|
214
|
+
const rawGroupId = options.getGroupId(item.id);
|
|
215
|
+
const groupId = typeof rawGroupId === 'string' && rawGroupId.trim().length > 0 ? rawGroupId : null;
|
|
216
|
+
if (groupId === null) {
|
|
217
|
+
orderedSlots.push({ type: 'single', item });
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
220
|
+
let bucket = groupBuckets.get(groupId);
|
|
221
|
+
if (bucket === undefined) {
|
|
222
|
+
const isOnActiveFloor = activeFloor !== undefined && item.floorIndex === activeFloor;
|
|
223
|
+
const floorSet = new Set();
|
|
224
|
+
if (typeof item.floorIndex === 'number' && Number.isFinite(item.floorIndex)) {
|
|
225
|
+
floorSet.add(item.floorIndex);
|
|
226
|
+
}
|
|
227
|
+
bucket = {
|
|
228
|
+
groupId,
|
|
229
|
+
strongestItem: item,
|
|
230
|
+
representativeItem: item,
|
|
231
|
+
hasActiveFloorRepresentative: isOnActiveFloor,
|
|
232
|
+
memberKeys: [item.id],
|
|
233
|
+
seenMemberKeys: new Set([item.id]),
|
|
234
|
+
floorSet,
|
|
235
|
+
};
|
|
236
|
+
groupBuckets.set(groupId, bucket);
|
|
237
|
+
orderedSlots.push({ type: 'group', bucket });
|
|
238
|
+
}
|
|
239
|
+
else if (!bucket.seenMemberKeys.has(item.id)) {
|
|
240
|
+
bucket.seenMemberKeys.add(item.id);
|
|
241
|
+
bucket.memberKeys.push(item.id);
|
|
242
|
+
if (typeof item.floorIndex === 'number' && Number.isFinite(item.floorIndex)) {
|
|
243
|
+
bucket.floorSet.add(item.floorIndex);
|
|
244
|
+
}
|
|
245
|
+
if (!bucket.hasActiveFloorRepresentative &&
|
|
246
|
+
activeFloor !== undefined &&
|
|
247
|
+
item.floorIndex === activeFloor) {
|
|
248
|
+
bucket.representativeItem = item;
|
|
249
|
+
bucket.hasActiveFloorRepresentative = true;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
const results = new Array(orderedSlots.length);
|
|
254
|
+
for (let i = 0; i < orderedSlots.length; i++) {
|
|
255
|
+
const slot = orderedSlots[i];
|
|
256
|
+
if (slot.type === 'single' || slot.bucket.memberKeys.length === 1) {
|
|
257
|
+
const singleItem = slot.type === 'single' ? slot.item : slot.bucket.strongestItem;
|
|
258
|
+
results[i] = toRankedSingleStoreEntry(singleItem);
|
|
259
|
+
continue;
|
|
260
|
+
}
|
|
261
|
+
const { groupId, strongestItem, representativeItem, memberKeys, floorSet } = slot.bucket;
|
|
262
|
+
const availableFloors = floorSet.size > 0 ? Array.from(floorSet).sort((a, b) => a - b) : undefined;
|
|
263
|
+
results[i] = {
|
|
264
|
+
kind: 'group',
|
|
265
|
+
groupId,
|
|
266
|
+
rankingMemberKey: strongestItem.id,
|
|
267
|
+
representativeKey: representativeItem.id,
|
|
268
|
+
memberKeys,
|
|
269
|
+
...(availableFloors !== undefined ? { availableFloors } : {}),
|
|
270
|
+
score: strongestItem.score,
|
|
271
|
+
matchedTerms: strongestItem.matchedTerms.slice(),
|
|
272
|
+
matchedFields: strongestItem.matchedFields.slice(),
|
|
273
|
+
...(representativeItem.floorIndex !== undefined
|
|
274
|
+
? { floorIndex: representativeItem.floorIndex }
|
|
275
|
+
: {}),
|
|
276
|
+
...(strongestItem.paidPromotionGroup !== undefined
|
|
277
|
+
? { paidPromotionGroup: strongestItem.paidPromotionGroup }
|
|
278
|
+
: {}),
|
|
279
|
+
...(strongestItem.paidPromotionWeight !== undefined
|
|
280
|
+
? { paidPromotionWeight: strongestItem.paidPromotionWeight }
|
|
281
|
+
: {}),
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
return results;
|
|
285
|
+
}
|
|
286
|
+
function toRankedSingleStoreEntry(item) {
|
|
287
|
+
return {
|
|
288
|
+
kind: 'store',
|
|
289
|
+
nodeKey: item.id,
|
|
290
|
+
score: item.score,
|
|
291
|
+
matchedTerms: item.matchedTerms.slice(),
|
|
292
|
+
matchedFields: item.matchedFields.slice(),
|
|
293
|
+
...(item.floorIndex !== undefined ? { floorIndex: item.floorIndex } : {}),
|
|
294
|
+
...(item.paidPromotionGroup !== undefined
|
|
295
|
+
? { paidPromotionGroup: item.paidPromotionGroup }
|
|
296
|
+
: {}),
|
|
297
|
+
...(item.paidPromotionWeight !== undefined
|
|
298
|
+
? { paidPromotionWeight: item.paidPromotionWeight }
|
|
299
|
+
: {}),
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Executes the canonical store search pipeline in the required order:
|
|
304
|
+
* 1. Eligibility filtering (`eligibleIds`) + text/promotion matching & ranking over all eligible candidates (`storeIndex.searchAll`).
|
|
305
|
+
* 2. Complete eligible match grouping (`rankGroupedStoreSearchResults`) so multi-location stores never split across pages.
|
|
306
|
+
* 3. Separate `totalRows` (grouped row count) and `totalMemberCount` (matched member key count).
|
|
307
|
+
* 4. Bounded row-level pagination (`offset`, `limit`, `limit: 0` safe, `hasMore`, `nextOffset`).
|
|
308
|
+
*
|
|
309
|
+
* Hinglish: Canonical store search pipeline run karta hai:
|
|
310
|
+
* `Eligibility filter -> matching/ranking (searchAll) -> complete eligible matches ki grouping -> grouped row counts -> pagination`.
|
|
311
|
+
*/
|
|
312
|
+
export function executeGroupedStoreSearch(storeIndex, query, options) {
|
|
313
|
+
const { offset, limit } = storeIndex.resolvePagination(options);
|
|
314
|
+
const allMatched = storeIndex.searchAll(query, options);
|
|
315
|
+
const totalMemberCount = allMatched.totalMatched;
|
|
316
|
+
const totalIndexed = allMatched.totalIndexed;
|
|
317
|
+
const floorSet = new Set();
|
|
318
|
+
for (let i = 0; i < allMatched.items.length; i++) {
|
|
319
|
+
const fl = allMatched.items[i].floorIndex;
|
|
320
|
+
if (typeof fl === 'number' && Number.isFinite(fl)) {
|
|
321
|
+
floorSet.add(fl);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
const availableFloors = Array.from(floorSet).sort((a, b) => a - b);
|
|
325
|
+
const allGroupedRows = options.groupMultiLocation === false
|
|
326
|
+
? allMatched.items.map(toRankedSingleStoreEntry)
|
|
327
|
+
: rankGroupedStoreSearchResults(allMatched.items, {
|
|
328
|
+
getGroupId: options.getGroupId,
|
|
329
|
+
activeFloorIndex: options.activeFloorIndex,
|
|
330
|
+
});
|
|
331
|
+
const totalRows = allGroupedRows.length;
|
|
332
|
+
if (limit === 0 || offset >= totalRows) {
|
|
333
|
+
const hasMoreWhenZeroLimit = limit === 0 && totalRows > offset;
|
|
334
|
+
return {
|
|
335
|
+
query: allMatched.query,
|
|
336
|
+
sortBy: allMatched.sortBy,
|
|
337
|
+
items: [],
|
|
338
|
+
totalRows,
|
|
339
|
+
totalMemberCount,
|
|
340
|
+
totalIndexed,
|
|
341
|
+
offset,
|
|
342
|
+
limit,
|
|
343
|
+
hasMore: hasMoreWhenZeroLimit,
|
|
344
|
+
nextOffset: null,
|
|
345
|
+
availableFloors,
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
const end = Math.min(totalRows, offset + limit);
|
|
349
|
+
const items = allGroupedRows.slice(offset, end);
|
|
350
|
+
const hasMore = end < totalRows;
|
|
351
|
+
return {
|
|
352
|
+
query: allMatched.query,
|
|
353
|
+
sortBy: allMatched.sortBy,
|
|
354
|
+
items,
|
|
355
|
+
totalRows,
|
|
356
|
+
totalMemberCount,
|
|
357
|
+
totalIndexed,
|
|
358
|
+
offset,
|
|
359
|
+
limit,
|
|
360
|
+
hasMore,
|
|
361
|
+
nextOffset: hasMore ? end : null,
|
|
362
|
+
availableFloors,
|
|
363
|
+
};
|
|
364
|
+
}
|