From 1f7e687272e29503ed958bed0dafdcbb091ebabb Mon Sep 17 00:00:00 2001 From: Jeffrey Dowdle Date: Wed, 28 Aug 2024 08:31:52 +1000 Subject: [PATCH] feat(@dpc-sdp/ripple-tide-search): added additional functional needed for KYC map migration --- .../global/TideSearchAddressLookup.vue | 24 +++++- .../utils/rplAddressSuggestionsFn.ts | 81 ++++++++++++++++++- 2 files changed, 99 insertions(+), 6 deletions(-) diff --git a/packages/ripple-tide-search/components/global/TideSearchAddressLookup.vue b/packages/ripple-tide-search/components/global/TideSearchAddressLookup.vue index 269750b182..bb1b310ac3 100644 --- a/packages/ripple-tide-search/components/global/TideSearchAddressLookup.vue +++ b/packages/ripple-tide-search/components/global/TideSearchAddressLookup.vue @@ -36,6 +36,12 @@ variant="dark" class="rpl-u-margin-l-3" /> + @@ -114,7 +120,11 @@ async function submitAction(e: any) { const arcGISAddress = await getAddressFromArcGISMagicKey( item.arcGISMagicKey ) - emit('update', arcGISAddress) + emit('update', { + ...item, + ...(arcGISAddress || {}), + arcGISMagicKey: undefined + }) } else { emit('update', item || null) } @@ -239,7 +249,17 @@ async function centerMapOnLocation( animationDuration: animate ? 800 : 0 }) } - } else if (!location?.postcode) { + + return + } + + if (map && location?.center) { + const zoom = location?.zoomLevel || 16 + centerMap(map, fromLonLat(location?.center), zoom, deadSpace.value, null) + return + } + + if (!location) { // reset back to initial view on empty query fitDefaultExtent(map, deadSpace.value, defaultExtent) } diff --git a/packages/ripple-tide-search/utils/rplAddressSuggestionsFn.ts b/packages/ripple-tide-search/utils/rplAddressSuggestionsFn.ts index 82e4676492..2cfd35424b 100644 --- a/packages/ripple-tide-search/utils/rplAddressSuggestionsFn.ts +++ b/packages/ripple-tide-search/utils/rplAddressSuggestionsFn.ts @@ -1,7 +1,70 @@ import { capitalCase } from 'change-case' +const getLGASuggestions = async (query, args) => { + const suggestionsIndex = args.lgaIndex + + const searchUrl = `/api/tide/app-search/${suggestionsIndex}/elasticsearch/_search` + + const queryDSL = { + query: { + bool: { + should: [ + { + match: { + name: { + query, + operator: 'and' + } + } + }, + { + prefix: { + name: { + value: query, + case_insensitive: true + } + } + }, + { + term: { + postcode: { + value: query + } + } + } + ] + } + } + } + + const test = await $fetch(searchUrl, { + method: 'POST', + body: { + ...queryDSL, + size: args.maxLGASuggestions + } + }) + + return test.hits.hits.map((itm) => { + const areaType = getSingleResultValue(itm._source.area_type) + const rawName = getSingleResultValue(itm._source['name']) + const name = areaType === 'lga' ? `${rawName} Council` : rawName + const tag = + areaType !== 'lga' + ? `${itm._source.lga_official_name} Council` + : undefined + + return { + id: itm._id, + name, + bbox: itm._source.lga_bbox, + tag + } + }) +} + const getSuburbSuggestions = async (query, args) => { - const suggestionsIndex = 'vicpol-postcode-localities' + const suggestionsIndex = args.suburbsIndex const searchUrl = `/api/tide/app-search/${suggestionsIndex}/elasticsearch/_search` @@ -74,15 +137,20 @@ const getAddressSuggestions = async (query, args) => { return { id: item.magicKey, name: capitalCase(item.text), - arcGISMagicKey: item.magicKey + arcGISMagicKey: item.magicKey, + zoomLevel: args?.addressZoomLevel } }) } export default async (query, args) => { const defaultArgs = { + maxLGASuggestions: 0, maxSuburbSuggestions: 0, - maxAddressSuggestions: 10 + maxAddressSuggestions: 10, + suburbsIndex: 'vicpol-postcode-localities', + lgaIndex: 'budget-areas-data', + addressZoomLevel: 12 } const argsWithDefaults = { @@ -91,9 +159,14 @@ export default async (query, args) => { } return [ + ...(args.maxLGASuggestions > 0 + ? await getLGASuggestions(query, argsWithDefaults) + : []), ...(args.maxSuburbSuggestions > 0 ? await getSuburbSuggestions(query, argsWithDefaults) : []), - ...(await getAddressSuggestions(query, argsWithDefaults)) + ...(args.maxAddressSuggestions > 0 + ? await getAddressSuggestions(query, argsWithDefaults) + : []) ] }