@digitransit-search-util/digitransit-search-util-execute-search-immidiate 2.0.3 → 3.0.1

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 (2) hide show
  1. package/index.js +56 -66
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -167,9 +167,12 @@ function getBackSuggestion() {
167
167
  ]);
168
168
  }
169
169
 
170
- function filterFavouriteStops(stopsAndStations, input) {
171
- return stopsAndStations.then(stops => {
172
- return filterMatchingToInput(stops, input, [
170
+ function filterFavouriteStops(stopsAndStations, input, useStops, useStations) {
171
+ return stopsAndStations.then(stopsStations => {
172
+ const candidates = stopsStations.filter(s =>
173
+ s.type === 'stop' ? useStops : useStations,
174
+ );
175
+ return filterMatchingToInput(candidates, input, [
173
176
  'properties.name',
174
177
  'properties.name',
175
178
  'properties.address',
@@ -229,9 +232,12 @@ const routeLayers = [
229
232
  'route-FERRY',
230
233
  'route-SUBWAY',
231
234
  'route-AIRPLANE',
235
+ 'route-FUNICULAR',
232
236
  ];
233
- const locationLayers = ['favouritePlace', 'venue', 'address', 'street'];
237
+ const locationLayers = ['venue', 'address', 'street'];
234
238
  const parkingLayers = ['carpark', 'bikepark'];
239
+ const stopLayers = ['stop', 'station'];
240
+
235
241
  /**
236
242
  * Executes the search
237
243
  *
@@ -323,16 +329,17 @@ export function getSearchResults(
323
329
  }
324
330
 
325
331
  if (allSources || sources.includes('Datasource')) {
326
- const geocodingLayers = ['station', 'venue', 'address', 'street'];
327
- const feedis = feedIDs.map(v => `gtfs${v}`);
328
- const geosources = geocodingSources.concat(feedis).join(',');
332
+ const geocodingLayers = ['venue', 'address', 'street'];
333
+ if (targets.includes('Stations')) {
334
+ geocodingLayers.push('station'); // search stations from OSM
335
+ }
329
336
  searchComponents.push(
330
337
  getGeocodingResults(
331
338
  input,
332
339
  searchParams,
333
340
  language,
334
341
  focusPoint,
335
- geosources,
342
+ geocodingSources.join(','),
336
343
  URL_PELIAS,
337
344
  minimalRegexp,
338
345
  geocodingLayers,
@@ -341,18 +348,10 @@ export function getSearchResults(
341
348
  }
342
349
  if (allSources || sources.includes('History')) {
343
350
  const locationHistory = getOldSearches(context, 'endpoint');
344
- const dropLayers = [
345
- 'currentPosition',
346
- 'selectFromMap',
347
- 'futureRoute',
348
- 'ownLocations',
349
- 'vehicleRentalStation',
350
- 'bikepark',
351
- 'carpark',
352
- 'stop',
353
- 'back',
354
- ];
351
+ const dropLayers = ['bikestation'];
352
+ dropLayers.push(...stopLayers);
355
353
  dropLayers.push(...routeLayers);
354
+ dropLayers.push(...parkingLayers);
356
355
  searchComponents.push(
357
356
  filterOldSearches(locationHistory, input, dropLayers),
358
357
  );
@@ -386,25 +385,18 @@ export function getSearchResults(
386
385
  }
387
386
  if (allSources || sources.includes('History')) {
388
387
  const history = getOldSearches(context);
389
- const dropLayers = [
390
- 'currentPosition',
391
- 'selectFromMap',
392
- 'futureRoute',
393
- 'ownLocations',
394
- 'favouritePlace',
395
- 'bikestation',
396
- 'vehicleRentalStation',
397
- 'back',
398
- 'stop',
399
- 'station',
400
- ];
388
+ const dropLayers = ['bikestation'];
389
+ dropLayers.push(...stopLayers);
401
390
  dropLayers.push(...routeLayers);
402
391
  dropLayers.push(...locationLayers);
403
392
  searchComponents.push(filterOldSearches(history, input, dropLayers));
404
393
  }
405
394
  }
406
395
 
407
- if (allTargets || targets.includes('Stops')) {
396
+ const useStops = targets.includes('Stops');
397
+ const useStations = targets.includes('Stations');
398
+
399
+ if (allTargets || useStops || useStations) {
408
400
  if (sources.includes('Favourite')) {
409
401
  const favouriteStops = getFavouriteStops(context);
410
402
  let stopsAndStations;
@@ -430,10 +422,18 @@ export function getSearchResults(
430
422
  return results;
431
423
  });
432
424
  }
433
- searchComponents.push(filterFavouriteStops(stopsAndStations, input));
425
+ searchComponents.push(
426
+ filterFavouriteStops(stopsAndStations, input, useStops, useStations),
427
+ );
434
428
  }
435
429
  if (allSources || sources.includes('Datasource')) {
436
- const geocodingLayers = ['stop', 'station'];
430
+ const geocodingLayers = [];
431
+ if (useStops) {
432
+ geocodingLayers.push('stop');
433
+ }
434
+ if (useStations) {
435
+ geocodingLayers.push('station');
436
+ }
437
437
  const searchParams =
438
438
  geocodingSize && geocodingSize !== 10 ? { size: geocodingSize } : {};
439
439
  if (geocodingSearchParams && geocodingSearchParams['boundary.country']) {
@@ -445,14 +445,14 @@ export function getSearchResults(
445
445
  if (allTargets || targets.includes('Locations')) {
446
446
  searchParams.dedupestops = 1;
447
447
  }
448
- const feedis = feedIDs.map(v => `gtfs${v}`).join(',');
448
+ const feeds = feedIDs.map(v => `gtfs${v}`).join(',');
449
449
  searchComponents.push(
450
450
  getGeocodingResults(
451
451
  input,
452
452
  searchParams,
453
453
  language,
454
454
  focusPoint,
455
- feedis,
455
+ feeds,
456
456
  URL_PELIAS,
457
457
  minimalRegexp,
458
458
  geocodingLayers,
@@ -471,23 +471,17 @@ export function getSearchResults(
471
471
  }
472
472
  return true;
473
473
  });
474
- const dropLayers = [
475
- 'currentPosition',
476
- 'selectFromMap',
477
- 'futureRoute',
478
- 'ownLocations',
479
- 'favouritePlace',
480
- 'vehicleRentalStation',
481
- 'back',
482
- ];
474
+ const dropLayers = ['bikestation'];
483
475
  dropLayers.push(...routeLayers);
484
476
  dropLayers.push(...locationLayers);
485
477
  dropLayers.push(...parkingLayers);
478
+ if (!useStops) {
479
+ dropLayers.push('stop');
480
+ }
481
+ if (!useStations) {
482
+ dropLayers.push('station');
483
+ }
486
484
  if (transportMode) {
487
- if (transportMode !== 'route-CITYBIKE') {
488
- dropLayers.push('vehicleRentalStation');
489
- dropLayers.push('bikestation');
490
- }
491
485
  searchComponents.push(
492
486
  filterOldSearches(stopHistory, input, dropLayers).then(result =>
493
487
  filterResults ? filterResults(result, mode) : result,
@@ -500,7 +494,6 @@ export function getSearchResults(
500
494
  }
501
495
  }
502
496
  }
503
-
504
497
  if (allTargets || targets.includes('Routes')) {
505
498
  if (sources.includes('Favourite')) {
506
499
  const favouriteRoutes = getFavouriteRoutes(context);
@@ -518,26 +511,14 @@ export function getSearchResults(
518
511
  );
519
512
  if (allSources || sources.includes('History')) {
520
513
  const routeHistory = getOldSearches(context);
521
- const dropLayers = [
522
- 'currentPosition',
523
- 'selectFromMap',
524
- 'futureRoute',
525
- 'favouritePlace',
526
- 'stop',
527
- 'station',
528
- 'bikepark',
529
- 'carpark',
530
- 'ownLocations',
531
- 'back',
532
- ];
514
+ const dropLayers = ['bikestation'];
533
515
  if (transportMode) {
534
- if (transportMode !== 'route-CITYBIKE') {
535
- dropLayers.push('vehicleRentalStation');
536
- dropLayers.push('bikestation');
537
- }
538
516
  dropLayers.push(...routeLayers.filter(i => !(i === transportMode)));
539
517
  }
518
+ dropLayers.push(...stopLayers);
540
519
  dropLayers.push(...locationLayers);
520
+ dropLayers.push(...parkingLayers);
521
+
541
522
  searchComponents.push(
542
523
  filterOldSearches(routeHistory, input, dropLayers).then(results =>
543
524
  filterResults ? filterResults(results, mode, 'Routes') : results,
@@ -578,6 +559,15 @@ export function getSearchResults(
578
559
  }),
579
560
  );
580
561
  }
562
+ if (allSources || sources.includes('History')) {
563
+ const history = getOldSearches(context);
564
+ const dropLayers = [...stopLayers];
565
+ dropLayers.push(...routeLayers);
566
+ dropLayers.push(...locationLayers);
567
+ dropLayers.push(...parkingLayers);
568
+
569
+ searchComponents.push(filterOldSearches(history, input, dropLayers));
570
+ }
581
571
  }
582
572
 
583
573
  const searchResultsPromise = Promise.all(searchComponents)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digitransit-search-util/digitransit-search-util-execute-search-immidiate",
3
- "version": "2.0.3",
3
+ "version": "3.0.1",
4
4
  "description": "digitransit-search-util execute-search-immidiate module",
5
5
  "main": "index.js",
6
6
  "publishConfig": {
@@ -27,5 +27,5 @@
27
27
  "@digitransit-search-util/digitransit-search-util-helpers": "2.0.0",
28
28
  "lodash": "4.17.21"
29
29
  },
30
- "gitHead": "ec8983842715dc421b7f806fc943f1c729ac42c3"
30
+ "gitHead": "d47e439a2d01ec41702a85ac226a7bc1ccaaa47c"
31
31
  }