atriusmaps-node-sdk 1.0.0 → 3.2.28

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.
Files changed (105) hide show
  1. package/README.md +76 -0
  2. package/config/rollup.config.cjs.js +31 -0
  3. package/dist/cjs/_virtual/_empty_module_placeholder.js +5 -0
  4. package/dist/cjs/deploy/nodeEntry.js +15 -0
  5. package/dist/cjs/deploy/prepareSDKConfig.js +9 -0
  6. package/dist/cjs/package.json +1 -0
  7. package/dist/cjs/package.json.js +11 -0
  8. package/dist/cjs/plugins/clientAPI/src/clientAPI.js +9 -0
  9. package/dist/cjs/plugins/dynamicPois/src/dynamicPois.js +33 -0
  10. package/dist/cjs/plugins/poiDataManager/src/poiDataManager.js +36 -0
  11. package/dist/cjs/plugins/sdkServer/src/sdkHeadless.js +31 -0
  12. package/dist/cjs/plugins/sdkServer/src/sdkServer.js +13 -0
  13. package/dist/cjs/plugins/sdkServer/src/util.js +10 -0
  14. package/dist/cjs/plugins/searchService/src/poiSearch.js +28 -0
  15. package/dist/cjs/plugins/searchService/src/searchService.js +37 -0
  16. package/dist/cjs/plugins/searchService/src/searchTypeahead.js +8 -0
  17. package/dist/cjs/plugins/searchService/src/utils.js +13 -0
  18. package/dist/cjs/plugins/venueDataLoader/src/venueDataLoader.js +36 -0
  19. package/dist/cjs/plugins/venueDataLoader/src/venueLoadingUtils.js +34 -0
  20. package/dist/cjs/plugins/wayfinder/src/findRoute.js +30 -0
  21. package/dist/cjs/plugins/wayfinder/src/minPriorityQueue.js +5 -0
  22. package/dist/cjs/plugins/wayfinder/src/navGraph.js +13 -0
  23. package/dist/cjs/plugins/wayfinder/src/navGraphDebug.js +30 -0
  24. package/dist/cjs/plugins/wayfinder/src/segmentBadges.js +5 -0
  25. package/dist/cjs/plugins/wayfinder/src/segmentBuilder.js +32 -0
  26. package/dist/cjs/plugins/wayfinder/src/segmentCategories.js +5 -0
  27. package/dist/cjs/plugins/wayfinder/src/stepBuilder.js +10 -0
  28. package/dist/cjs/plugins/wayfinder/src/wayfinder.js +40 -0
  29. package/dist/cjs/src/app.js +44 -0
  30. package/dist/cjs/src/auth/Auth.js +23 -0
  31. package/dist/cjs/src/configs/postproc-mol-url-parms.js +9 -0
  32. package/dist/cjs/src/configs/postproc-stateTracking.js +31 -0
  33. package/dist/cjs/src/configs/sdkHeadless.json.js +47 -0
  34. package/dist/cjs/src/controller.js +14 -0
  35. package/dist/cjs/src/debugTools.js +30 -0
  36. package/dist/cjs/src/env.js +7 -0
  37. package/dist/cjs/src/extModules/bustle.js +13 -0
  38. package/dist/cjs/src/extModules/flexapi/src/help.js +9 -0
  39. package/dist/cjs/src/extModules/flexapi/src/index.js +13 -0
  40. package/dist/cjs/src/extModules/flexapi/src/validate.js +10 -0
  41. package/dist/cjs/src/extModules/geohasher.js +8 -0
  42. package/dist/cjs/src/extModules/log.js +7 -0
  43. package/dist/cjs/src/historyManager.js +7 -0
  44. package/dist/cjs/src/utils/bounds.js +10 -0
  45. package/dist/cjs/src/utils/buildStructureLookup.js +29 -0
  46. package/dist/cjs/src/utils/configUtils.js +8 -0
  47. package/dist/cjs/src/utils/dom.js +10 -0
  48. package/dist/cjs/src/utils/funcs.js +15 -0
  49. package/dist/cjs/src/utils/geodesy.js +8 -0
  50. package/dist/cjs/src/utils/geom.js +35 -0
  51. package/dist/cjs/src/utils/i18n.js +14 -0
  52. package/dist/cjs/src/utils/observable.js +5 -0
  53. package/dist/cjs/src/utils/rand.js +8 -0
  54. package/lib/_virtual/_empty_module_placeholder.js +1 -0
  55. package/lib/deploy/nodeEntry.js +1 -58
  56. package/lib/deploy/prepareSDKConfig.js +1 -112
  57. package/lib/package.json.js +1 -143
  58. package/lib/plugins/clientAPI/src/clientAPI.js +1 -14
  59. package/lib/plugins/dynamicPois/src/dynamicPois.js +1 -131
  60. package/lib/plugins/poiDataManager/src/poiDataManager.js +1 -207
  61. package/lib/plugins/sdkServer/src/sdkHeadless.js +1 -53
  62. package/lib/plugins/sdkServer/src/sdkServer.js +1 -211
  63. package/lib/plugins/sdkServer/src/util.js +1 -18
  64. package/lib/plugins/searchService/src/poiSearch.js +1 -39
  65. package/lib/plugins/searchService/src/searchService.js +1 -234
  66. package/lib/plugins/searchService/src/searchTypeahead.js +1 -63
  67. package/lib/plugins/searchService/src/utils.js +1 -30
  68. package/lib/plugins/venueDataLoader/src/venueDataLoader.js +1 -465
  69. package/lib/plugins/venueDataLoader/src/venueLoadingUtils.js +1 -84
  70. package/lib/plugins/wayfinder/src/findRoute.js +1 -134
  71. package/lib/plugins/wayfinder/src/minPriorityQueue.js +1 -89
  72. package/lib/plugins/wayfinder/src/navGraph.js +1 -370
  73. package/lib/plugins/wayfinder/src/navGraphDebug.js +1 -95
  74. package/lib/plugins/wayfinder/src/segmentBadges.js +1 -29
  75. package/lib/plugins/wayfinder/src/segmentBuilder.js +1 -241
  76. package/lib/plugins/wayfinder/src/segmentCategories.js +1 -30
  77. package/lib/plugins/wayfinder/src/stepBuilder.js +1 -236
  78. package/lib/plugins/wayfinder/src/wayfinder.js +1 -452
  79. package/lib/src/app.js +1 -150
  80. package/lib/src/auth/Auth.js +1 -35
  81. package/lib/src/configs/postproc-mol-url-parms.js +1 -58
  82. package/lib/src/configs/postproc-stateTracking.js +1 -40
  83. package/lib/src/configs/sdkHeadless.json.js +1 -42
  84. package/lib/src/controller.js +1 -45
  85. package/lib/src/debugTools.js +1 -108
  86. package/lib/src/env.js +1 -17
  87. package/lib/src/extModules/bustle.js +1 -126
  88. package/lib/src/extModules/flexapi/src/help.js +1 -21
  89. package/lib/src/extModules/flexapi/src/index.js +1 -66
  90. package/lib/src/extModules/flexapi/src/validate.js +1 -131
  91. package/lib/src/extModules/geohasher.js +1 -90
  92. package/lib/src/extModules/log.js +1 -70
  93. package/lib/src/historyManager.js +1 -30
  94. package/lib/src/utils/bounds.js +1 -23
  95. package/lib/src/utils/buildStructureLookup.js +1 -17
  96. package/lib/src/utils/configUtils.js +1 -61
  97. package/lib/src/utils/dom.js +1 -46
  98. package/lib/src/utils/funcs.js +1 -50
  99. package/lib/src/utils/geodesy.js +1 -35
  100. package/lib/src/utils/geom.js +1 -141
  101. package/lib/src/utils/i18n.js +1 -70
  102. package/lib/src/utils/observable.js +1 -76
  103. package/lib/src/utils/rand.js +1 -82
  104. package/package.json +23 -6
  105. package/lib/_virtual/_empty_module_placeholder +0 -3
@@ -1,234 +1 @@
1
- import * as R from 'ramda';
2
- import Zousan from 'zousan';
3
- import { getLocalized } from '../../../src/utils/configUtils.js';
4
- import { arrayPick } from '../../../src/utils/rand.js';
5
- import createPOISearch from './poiSearch.js';
6
- import createSearchTypeahead from './searchTypeahead.js';
7
-
8
- function create (app, config) {
9
- const state = {
10
- poiSearch: null,
11
- typeahead: null,
12
- indexesCreated: new Zousan(), // re-initialize this when changing venues
13
- defaultSearchTerms: null,
14
- specialQueryTerms: {}
15
- };
16
-
17
- const init = async () => {
18
- const pois = await app.bus.get('poi/getAll');
19
- state.poiSearch = createPOISearch(pois, app.i18n().language);
20
- state.typeahead = createSearchTypeahead(pois, state.poiSearch.search, app.i18n().language);
21
- state.defaultSearchTerms = getLocalized(config, 'defaultSearchTerms', app.i18n().language);
22
- state.indexesCreated.resolve();
23
- };
24
-
25
- /**
26
- * Prepares and send an event with up to 50 non-portal POIs sorted by distance to user location.
27
- */
28
- // todo check if async events (events which send a new event as a result) are still needed
29
- app.bus.on('search/queryNearby', async () => {
30
- const pois = await searchNearby();
31
- app.bus.send('search/showNearby', { pois, term: 'Nearby' });
32
- return pois
33
- });
34
-
35
- /**
36
- * Returns max 50 non-portal POIs sorted by distance to user location.
37
- * @returns Array.<POI>
38
- */
39
- app.bus.on('search/queryNearbyAsync', searchNearby);
40
-
41
- async function searchNearby () {
42
- const startLocation = await app.bus.get('user/getPhysicalLocation');
43
- const poisSameFloor = await app.bus.get('poi/getByFloorId', { floorId: startLocation.floorId });
44
- const isNotPortal = poi => poi.category.indexOf('portal') === -1 && poi.category !== 'element.door';
45
- const noPortalPois = Object.values(R.pickBy(isNotPortal, poisSameFloor));
46
- const poisWithDistance = await app.bus.get('wayfinder/addPathTimeMultiple', { pois: noPortalPois, startLocation });
47
- return R.sortBy(R.prop('distance'), Object.values(poisWithDistance)).slice(0, 50)
48
- }
49
-
50
- /**
51
- * Searches for POIs with search term or category name
52
- * and sends a new event 'search/showCategory' with search result POIs.
53
- *
54
- * @param {string} searchTerm - term to search POIs
55
- * @param {string} category - category name, fallback term to search POIs
56
- * @param {string} categoryName - label to display in search results input view
57
- */
58
- app.bus.on('search/queryCategory', async ({ category, categoryName, searchTerm }) => {
59
- const pois = await state.indexesCreated.then(() =>
60
- state.poiSearch.search({ query: searchTerm || category }));
61
- app.bus.send('search/showCategory', { pois, category, categoryName });
62
- return pois
63
- });
64
-
65
- /**
66
- * Searches for POIs with search term
67
- * and sends a new event 'search/showCategory' with search result POIs.
68
- *
69
- * @param {string} term - search term
70
- */
71
- // todo introduce consistent naming for parameters are return values (searchTem or term, pois or results, keywords or searchTerms)
72
- app.bus.on('search/query', ({ term }) => {
73
- return state.indexesCreated.then(() => {
74
- const pois = state.poiSearch.search({ query: term });
75
- app.bus.send('search/showSearchResults', { results: pois, term });
76
- return pois
77
- })
78
- });
79
-
80
- /**
81
- * Search for POIs with search term.
82
- *
83
- * @param {string} term - search term
84
- * @returns Array.<POI>
85
- */
86
- app.bus.on('search/queryAsync', ({ term }) =>
87
- state.indexesCreated.then(() => state.poiSearch.search({ query: term }))
88
- );
89
-
90
- /**
91
- * If search term matches any registered special query term,
92
- * then send an event with params for this special query,
93
- * otherwise search for POIs with term and send the event 'search/query' with search result POIs
94
- *
95
- * @param {string} term - search term or special query
96
- */
97
- app.bus.on('search/queryWithSpecial', ({ term }) => {
98
- if (state.specialQueryTerms[term]) {
99
- const { event, params } = state.specialQueryTerms[term];
100
- // use "send" as we can't gaurentee this event is a "get" or even returns POIs
101
- return app.bus.send(event, params)
102
- } else {
103
- return app.bus.get('search/query', { term })
104
- }
105
- });
106
-
107
- /**
108
- * Returns list of all localized default search terms declared in the configuration
109
- * or list of up to 'limit' random unique POI categories as a fallback.
110
- * Returns a list of keywords and sends an event 'search/showDefaultSearchKeywords' with same the list of keywords.
111
- *
112
- * @param {number} [limit=5] - Used to limit number of random unique categories list if default search terms are not defined in configuration.
113
- * @returns Array.<string> - list of keywords
114
- */
115
- app.bus.on('search/getDefaultSearchTerms', async ({ limit = 5 } = {}) => {
116
- const defaultSearchTerms = state.defaultSearchTerms;
117
- const hasDefaultSearchTerms = defaultSearchTerms && defaultSearchTerms.length;
118
- const keywords = hasDefaultSearchTerms
119
- ? defaultSearchTerms
120
- : await getUniqueRandomCategories(limit);
121
- app.bus.send('search/showDefaultSearchKeywords', { keywords });
122
- return keywords
123
- });
124
-
125
- async function getUniqueRandomCategories (limit) {
126
- const allCategories = (await app.bus.send('poi/getAllCategories'))[0];
127
- const uniqueCategories = Array.from(new Set(allCategories));
128
- const shuffledUniqueCategories = shuffle(uniqueCategories);
129
- return shuffledUniqueCategories.slice(0, limit)
130
- }
131
-
132
- function shuffle (a) {
133
- for (let i = a.length - 1; i > 0; i--) {
134
- const j = Math.floor(Math.random() * (i + 1));
135
- [a[i], a[j]] = [a[j], a[i]];
136
- }
137
- return a
138
- }
139
-
140
- /**
141
- * Returns list of up to 'limit' unique random navigable POIs.
142
- *
143
- * @param {number} [limit=5]
144
- * @returns Array.<POI>
145
- */
146
- app.bus.on('search/getDefaultSearchPois', async ({ limit = 5 } = {}) => {
147
- const allPois = await app.bus.get('poi/getAll');
148
- const navigablePred = (val, key) => val.isNavigable;
149
- const navigablePois = R.pickBy(navigablePred, allPois);
150
- return arrayPick(Object.values(navigablePois), limit)
151
- });
152
-
153
- /**
154
- * Registers an event and event params for special query term.
155
- * Optionally adds passed special query term to keywords search index.
156
- *
157
- * @param {string} term - special query term
158
- * @param {string} event - name of associated event
159
- * @param {Object} params - parameters for associated event
160
- * @param {boolean} addKeyword - indicates if term has to be added to keywords search index
161
- */
162
- app.bus.on('search/registerSpecialQuery', ({ term, event, params, addKeyword = true }) => {
163
- state.indexesCreated.then(() => {
164
- if (addKeyword) {
165
- state.typeahead.addKeyword(term);
166
- }
167
- state.specialQueryTerms[term] = { event, params };
168
- });
169
- });
170
-
171
- /**
172
- * Adds list of keywords to keywords search index.
173
- *
174
- * @param {Array.<string>} keywords - list of new keywords
175
- */
176
- app.bus.on('search/addKeywords', ({ keywords }) =>
177
- state.indexesCreated.then(() =>
178
- keywords.forEach(keyword => state.typeahead.addKeyword(keyword))));
179
-
180
- /**
181
- * Returns lists of keywords and POIs matching search term.
182
- *
183
- * For term shorter than 3 characters only keywords index is queried.
184
- * If no keywords are found or when term is longer,
185
- * then POIs index is queried for the the remaining results.
186
- *
187
- * @param {string} term - search term
188
- * @param {number} limit - maximum number of results
189
- * @returns {{ pois: Array.<POI>, keywords: Array.<String>, term: string }} - list of keywords, list of POIs, search term
190
- */
191
- app.bus.on('search/typeahead', ({ term, limit }) => state.indexesCreated.then(() => {
192
- const { keywords, pois } = state.typeahead.query(term, limit);
193
- return { keywords, pois, term }
194
- }));
195
-
196
- /**
197
- * Resets plugin state.
198
- */
199
- app.bus.on('venueData/loadNewVenue', () => {
200
- state.indexesCreated = new Zousan();
201
- init();
202
- });
203
-
204
- /**
205
- * Updates POIs search index with dynamic Grab POIs.
206
- *
207
- * @param {string} plugin - type of dynamic data
208
- * @param {Object<string, Object>} - dictionary of POI id to dynamic data object
209
- */
210
- app.bus.on('poi/setDynamicData', async ({ plugin, idValuesMap }) => {
211
- if (plugin !== 'grab') return
212
-
213
- const dynamicPoisPromises = Object.keys(idValuesMap)
214
- .map(id => app.bus.get('poi/getById', { id }));
215
-
216
- return Promise.all(dynamicPoisPromises)
217
- .then(pois =>
218
- state.indexesCreated.then(() =>
219
- state.poiSearch.updateMultiple(pois)))
220
- });
221
-
222
- const runTest = async (initialState, testRoutine) => {
223
- // state = { ...initialState }
224
- await testRoutine();
225
- return state
226
- };
227
-
228
- return {
229
- init,
230
- runTest
231
- }
232
- }
233
-
234
- export { create };
1
+ import*as e from"ramda";import r from"zousan";import{getLocalized as a}from"../../../src/utils/configUtils.js";import{arrayPick as s}from"../../../src/utils/rand.js";import t from"./poiSearch.js";import n from"./searchTypeahead.js";function o(o,i){const c={poiSearch:null,typeahead:null,indexesCreated:new r,defaultSearchTerms:null,specialQueryTerms:{}},u=async()=>{const e=await o.bus.get("poi/getAll");c.poiSearch=t(e,o.i18n().language),c.typeahead=n(e,c.poiSearch.search,o.i18n().language),c.defaultSearchTerms=a(i,"defaultSearchTerms",o.i18n().language),c.indexesCreated.resolve()};async function d(){const r=await o.bus.get("user/getPhysicalLocation"),a=await o.bus.get("poi/getByFloorId",{floorId:r.floorId}),s=Object.values(e.pickBy((e=>-1===e.category.indexOf("portal")&&"element.door"!==e.category),a)),t=await o.bus.get("wayfinder/addPathTimeMultiple",{pois:s,startLocation:r});return e.sortBy(e.prop("distance"),Object.values(t)).slice(0,50)}o.bus.on("search/queryNearby",(async()=>{const e=await d();return o.bus.send("search/showNearby",{pois:e,term:"Nearby"}),e})),o.bus.on("search/queryNearbyAsync",d),o.bus.on("search/queryCategory",(async({category:e,categoryName:r,searchTerm:a})=>{const s=await c.indexesCreated.then((()=>c.poiSearch.search({query:a||e})));return o.bus.send("search/showCategory",{pois:s,category:e,categoryName:r}),s})),o.bus.on("search/query",(({term:e})=>c.indexesCreated.then((()=>{const r=c.poiSearch.search({query:e});return o.bus.send("search/showSearchResults",{results:r,term:e}),r})))),o.bus.on("search/queryAsync",(({term:e})=>c.indexesCreated.then((()=>c.poiSearch.search({query:e}))))),o.bus.on("search/queryWithSpecial",(({term:e})=>{if(c.specialQueryTerms[e]){const{event:r,params:a}=c.specialQueryTerms[e];return o.bus.send(r,a)}return o.bus.get("search/query",{term:e})})),o.bus.on("search/getDefaultSearchTerms",(async({limit:e=5}={})=>{const r=c.defaultSearchTerms,a=r&&r.length?r:await async function(e){const r=(await o.bus.send("poi/getAllCategories"))[0],a=Array.from(new Set(r));return function(e){for(let r=e.length-1;r>0;r--){const a=Math.floor(Math.random()*(r+1));[e[r],e[a]]=[e[a],e[r]]}return e}(a).slice(0,e)}(e);return o.bus.send("search/showDefaultSearchKeywords",{keywords:a}),a})),o.bus.on("search/getDefaultSearchPois",(async({limit:r=5}={})=>{const a=await o.bus.get("poi/getAll"),t=e.pickBy(((e,r)=>e.isNavigable),a);return s(Object.values(t),r)})),o.bus.on("search/registerSpecialQuery",(({term:e,event:r,params:a,addKeyword:s=!0})=>{c.indexesCreated.then((()=>{s&&c.typeahead.addKeyword(e),c.specialQueryTerms[e]={event:r,params:a}}))})),o.bus.on("search/addKeywords",(({keywords:e})=>c.indexesCreated.then((()=>e.forEach((e=>c.typeahead.addKeyword(e))))))),o.bus.on("search/typeahead",(({term:e,limit:r})=>c.indexesCreated.then((()=>{const{keywords:a,pois:s}=c.typeahead.query(e,r);return{keywords:a,pois:s,term:e}})))),o.bus.on("venueData/loadNewVenue",(()=>{c.indexesCreated=new r,u()})),o.bus.on("poi/setDynamicData",(async({plugin:e,idValuesMap:r})=>{if("grab"!==e)return;const a=Object.keys(r).map((e=>o.bus.get("poi/getById",{id:e})));return Promise.all(a).then((e=>c.indexesCreated.then((()=>c.poiSearch.updateMultiple(e)))))}));return{init:u,runTest:async(e,r)=>(await r(),c)}}export{o as create};
@@ -1,63 +1 @@
1
- import { pipe, values, chain, prop, filter, pluck } from 'ramda';
2
- import { getFlexSearchInstance } from './utils.js';
3
-
4
- function createSearchTypeahead (pois, poiSearch, lang) {
5
- const suggestedKeywordsSearch = createSuggestedKeywordsSearch(pois, lang);
6
-
7
- function queryPois (query, limit) {
8
- const matches = poiSearch({ query, limit });
9
- const withSuggestions = poiSearch({ query, suggest: true, limit });
10
- const matchedIds = matches.map(poi => poi.poiId);
11
- const filteredSuggestions = withSuggestions.filter(poi => matchedIds.indexOf(poi.poiId) === -1);
12
- return matches.concat(filteredSuggestions)
13
- }
14
-
15
- const query = (query, limit) => {
16
- const suggestedKeywords = suggestedKeywordsSearch.search({ query, limit });
17
- const queryLengthUnderLimit = query.length < 3;
18
- const shouldQueryPois = !queryLengthUnderLimit && suggestedKeywords.length;
19
- const poisLimit = limit - suggestedKeywords.length;
20
- const pois = shouldQueryPois ? queryPois(query, poisLimit) : [];
21
- return { keywords: suggestedKeywords, pois }
22
- };
23
-
24
- const addKeyword = (keyword) => {
25
- suggestedKeywordsSearch.add(keyword);
26
- };
27
-
28
- return { query, addKeyword }
29
- }
30
-
31
- function createSuggestedKeywordsSearch (pois, lang) {
32
- const categories = extractParentCategories(pois);
33
- const poisKeywords = pipe(
34
- values,
35
- chain(prop('keywords')),
36
- filter(prop('isUserSearchable')),
37
- pluck('name')
38
- )(pois);
39
- const allPotentialKeywords = [...categories, ...poisKeywords];
40
- const keywords = Array.from(new Set([...allPotentialKeywords]));
41
- const index = getFlexSearchInstance({ lang, type: 'typeahead' });
42
-
43
- keywords.forEach((keyword, i) => index.add(i, keyword));
44
-
45
- const search = (queryParams) => {
46
- const ids = index.search(queryParams);
47
- return ids.map(index => keywords[index])
48
- };
49
- const add = (newKeyword) => {
50
- keywords.push(newKeyword);
51
- index.add(keywords.length - 1, newKeyword);
52
- };
53
- return { search, add }
54
- }
55
-
56
- function extractParentCategories (pois) {
57
- return Object.values(pois)
58
- .map(poi => poi.category)
59
- .map(fullCategory => fullCategory.split('.'))
60
- .map(subcategories => subcategories[0])
61
- }
62
-
63
- export default createSearchTypeahead;
1
+ import{pipe as e,values as r,chain as t,prop as a,filter as n,pluck as o}from"ramda";import{getFlexSearchInstance as i}from"./utils.js";function s(s,d,u){const c=function(s,d){const u=function(e){return Object.values(e).map((e=>e.category)).map((e=>e.split("."))).map((e=>e[0]))}(s),c=e(r,t(a("keywords")),n(a("isUserSearchable")),o("name"))(s),m=[...u,...c],p=Array.from(new Set([...m])),l=i({lang:d,type:"typeahead"});p.forEach(((e,r)=>l.add(r,e)));return{search:e=>l.search(e).map((e=>p[e])),add:e=>{p.push(e),l.add(p.length-1,e)}}}(s,u);return{query:(e,r)=>{const t=c.search({query:e,limit:r}),a=!(e.length<3)&&t.length,n=r-t.length;return{keywords:t,pois:a?function(e,r){const t=d({query:e,limit:r}),a=d({query:e,suggest:!0,limit:r}),n=t.map((e=>e.poiId)),o=a.filter((e=>-1===n.indexOf(e.poiId)));return t.concat(o)}(e,n):[]}},addKeyword:e=>{c.add(e)}}}export{s as default};
@@ -1,30 +1 @@
1
- import FlexSearch from 'flexsearch';
2
-
3
- const NON_ASCII_LANGUAGES = ['ko', 'ja', 'zh-Hans', 'zh-Hant'];
4
-
5
- const standardTokenizer = {
6
- profile: 'match'
7
- };
8
-
9
- const typeaheadTokenizer = {
10
- encode: 'advanced'
11
- };
12
-
13
- const fullTokenizer = {
14
- encode: false,
15
- split: /\s+/,
16
- tokenize: 'full'
17
- };
18
-
19
- const TOKENIZERS = {
20
- standard: standardTokenizer,
21
- typeahead: typeaheadTokenizer,
22
- full: fullTokenizer
23
- };
24
-
25
- const getFlexSearchInstance = ({ lang, type = 'standard' }) => {
26
- const tokenizer = NON_ASCII_LANGUAGES.includes(lang) ? fullTokenizer : TOKENIZERS[type];
27
- return new FlexSearch({ ...tokenizer })
28
- };
29
-
30
- export { getFlexSearchInstance };
1
+ import e from"flexsearch";const a=["ko","ja","zh-Hans","zh-Hant"],n={encode:!1,split:/\s+/,tokenize:"full"},t={standard:{profile:"match"},typeahead:{encode:"advanced"},full:n},d=({lang:d,type:o="standard"})=>{const l=a.includes(d)?n:t[o];return new e({...l})};export{d as getFlexSearchInstance};