From 3811c559cc3450810a44c540671a2c8f8cf8170b Mon Sep 17 00:00:00 2001 From: bruehlca Date: Fri, 21 Feb 2025 14:27:20 +0100 Subject: [PATCH 1/3] add custom search --- packages/clients/bgw/src/addPlugins.ts | 6 +++++- packages/clients/bgw/src/mapConfiguration.ts | 2 +- .../bgw/src/utils/badestellenSearch.ts | 20 +++++++++++++++++-- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/packages/clients/bgw/src/addPlugins.ts b/packages/clients/bgw/src/addPlugins.ts index 73f5cff32..5b3a8cc08 100644 --- a/packages/clients/bgw/src/addPlugins.ts +++ b/packages/clients/bgw/src/addPlugins.ts @@ -13,7 +13,10 @@ import Scale from '@polar/plugin-scale' import Toast from '@polar/plugin-toast' import Zoom from '@polar/plugin-zoom' import merge from 'lodash.merge' -import { badestellenSearchResult } from './utils/badestellenSearch' +import { + badestellenSearch, + badestellenSearchResult, +} from './utils/badestellenSearch' const defaultOptions = { displayComponent: true, @@ -75,6 +78,7 @@ export default (core) => { merge({}, defaultOptions, { addLoading: 'plugin/loadingIndicator/addLoadingKey', removeLoading: 'plugin/loadingIndicator/removeLoadingKey', + customSearchMethods: { badestellenSearch }, customSelectResult: { badestellen: badestellenSearchResult }, }) ), diff --git a/packages/clients/bgw/src/mapConfiguration.ts b/packages/clients/bgw/src/mapConfiguration.ts index 142a84642..693e4e5f0 100644 --- a/packages/clients/bgw/src/mapConfiguration.ts +++ b/packages/clients/bgw/src/mapConfiguration.ts @@ -126,7 +126,7 @@ const mapConfig = { { groupId: 'badestellenSearch', categoryId: 'badestellen', - type: 'wfs', + type: 'badestellenSearch', url: 'https://umweltgeodienste.schleswig-holstein.de/WFS_BGW', queryParameters: { srsName: 'EPSG:25832', diff --git a/packages/clients/bgw/src/utils/badestellenSearch.ts b/packages/clients/bgw/src/utils/badestellenSearch.ts index a93a1157d..875af7bfa 100644 --- a/packages/clients/bgw/src/utils/badestellenSearch.ts +++ b/packages/clients/bgw/src/utils/badestellenSearch.ts @@ -1,10 +1,26 @@ -import { SelectResultFunction } from '@polar/lib-custom-types' +import { Feature } from 'geojson' +import { + CoreGetters, + CoreState, + PolarStore, + SelectResultFunction, +} from '@polar/lib-custom-types' import { SearchResultSymbols, AddressSearchGetters, AddressSearchState, } from '@polar/plugin-address-search' -import { Feature } from 'geojson' +import { WfsParameters, getWfsFeatures } from '@polar/lib-get-features' + +export function badestellenSearch( + this: PolarStore, + signal: AbortSignal, + url: string, + inputValue: string, + queryParameters: WfsParameters +) { + return getWfsFeatures(signal, url, inputValue.toUpperCase(), queryParameters) +} export const badestellenSearchResult: SelectResultFunction< AddressSearchState, From a6bc8224870041699b4d7ff082c95bdbcd67345f Mon Sep 17 00:00:00 2001 From: bruehlca Date: Fri, 21 Feb 2025 14:49:05 +0100 Subject: [PATCH 2/3] use wildcards for inputvalue for better search results --- packages/clients/bgw/src/utils/badestellenSearch.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/clients/bgw/src/utils/badestellenSearch.ts b/packages/clients/bgw/src/utils/badestellenSearch.ts index 875af7bfa..cea22f4b9 100644 --- a/packages/clients/bgw/src/utils/badestellenSearch.ts +++ b/packages/clients/bgw/src/utils/badestellenSearch.ts @@ -19,7 +19,8 @@ export function badestellenSearch( inputValue: string, queryParameters: WfsParameters ) { - return getWfsFeatures(signal, url, inputValue.toUpperCase(), queryParameters) + const searchString = inputValue.toUpperCase() as string + return getWfsFeatures(signal, url, `*${searchString}*`, queryParameters) } export const badestellenSearchResult: SelectResultFunction< From 32fb7f8782ce962734fb506ef05d390b2c0cf2c2 Mon Sep 17 00:00:00 2001 From: bruehlca Date: Fri, 21 Feb 2025 15:30:13 +0100 Subject: [PATCH 3/3] convert umlauts in search string --- packages/clients/bgw/src/utils/badestellenSearch.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/clients/bgw/src/utils/badestellenSearch.ts b/packages/clients/bgw/src/utils/badestellenSearch.ts index cea22f4b9..79b31e57f 100644 --- a/packages/clients/bgw/src/utils/badestellenSearch.ts +++ b/packages/clients/bgw/src/utils/badestellenSearch.ts @@ -12,6 +12,14 @@ import { } from '@polar/plugin-address-search' import { WfsParameters, getWfsFeatures } from '@polar/lib-get-features' +function replaceUmlauts(input: string): string { + return input + .replace(/Ä/g, 'AE') + .replace(/Ö/g, 'OE') + .replace(/Ü/g, 'UE') + .replace(/ß/g, 'SS') +} + export function badestellenSearch( this: PolarStore, signal: AbortSignal, @@ -19,7 +27,7 @@ export function badestellenSearch( inputValue: string, queryParameters: WfsParameters ) { - const searchString = inputValue.toUpperCase() as string + const searchString = replaceUmlauts(inputValue.toUpperCase()) return getWfsFeatures(signal, url, `*${searchString}*`, queryParameters) }