Skip to content

Commit

Permalink
feat(@dpc-sdp/ripple-tide-search): added additional functional needed…
Browse files Browse the repository at this point in the history
… for KYC map migration
  • Loading branch information
jeffdowdle committed Aug 27, 2024
1 parent 32fe253 commit 1f7e687
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@
variant="dark"
class="rpl-u-margin-l-3"
/>
<RplTag
v-else-if="option?.tag"
:label="option?.tag"
variant="dark"
class="rpl-u-margin-l-3"
/>
</template>
</RplSearchBar>
</div>
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down
81 changes: 77 additions & 4 deletions packages/ripple-tide-search/utils/rplAddressSuggestionsFn.ts
Original file line number Diff line number Diff line change
@@ -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`

Expand Down Expand Up @@ -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 = {
Expand All @@ -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)
: [])
]
}

0 comments on commit 1f7e687

Please sign in to comment.