Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SD-102] Added additional features needed for KYC map migration #1306

Merged
merged 1 commit into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
: [])
]
}