Skip to content

Commit 6ad6b82

Browse files
feat: create a materialized view to search beaches without accent
1 parent 7c21015 commit 6ad6b82

File tree

7 files changed

+20
-9
lines changed

7 files changed

+20
-9
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CREATE MATERIALIZED VIEW search_beaches AS
2+
SELECT id,
3+
official_name,
4+
name,
5+
geom,
6+
postcode,
7+
unaccent(name) as unaccent_name,
8+
unaccent(official_name) as unaccent_official_name
9+
from beaches;

backend/src/main/resources/db/testdata/V666.23__insert_beaches.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ INSERT INTO public.beaches
1111
VALUES (2009, '0104000020E610000001000000010100000079AA9E70989C4B40B89C97A0AE0D35C0', 'Plage Des Roches Noires',
1212
'Saint-Paul', '97460', '97415');
1313

14-
14+
REFRESH MATERIALIZED VIEW search_beaches;

backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/repositories/AbstractDBTests.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ abstract class AbstractDBTests {
2323
@JvmStatic
2424
val container: GenericContainer<Nothing> =
2525
GenericContainer<Nothing>(
26-
"ghcr.io/mtes-mct/monitorenv/monitorenv-database:pg17-postgis3.6.1-timescale2.24.0",
26+
"ghcr.io/mtes-mct/monitorenv/monitorenv-database:pg17-postgis3.6.1-timescale2.24.0-contrib",
2727
).apply {
2828
withExposedPorts(5432)
2929
withEnv("POSTGRES_DB", "testdb")

frontend/cypress/mappings/geoserver/beaches-search.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"equalTo": "GetFeature"
1414
},
1515
"typename": {
16-
"equalTo": "monitorenv:beaches"
16+
"equalTo": "monitorenv:search_beaches"
1717
},
1818
"outputFormat": {
1919
"equalTo": "application/json"

frontend/src/api/beachesAPI.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,17 @@ export const getBeachesFromAPI = async (query: string | undefined) => {
2525
const conditions = searchQueries.map(searchQuery => {
2626
const sanitizedQuery = sanitizeQuery(searchQuery)
2727

28-
return `(name ILIKE '%${sanitizedQuery}%' OR official_name ILIKE '%${sanitizedQuery}%' OR postcode ILIKE '%${sanitizedQuery}%')`
28+
return `(unaccent_name ILIKE '%${sanitizedQuery}%' OR unaccent_official_name ILIKE '%${sanitizedQuery}%' OR postcode ILIKE '%${sanitizedQuery}%')`
2929
})
3030
const cqlFilter = conditions.join(' AND ')
3131

3232
return fetch(
3333
`${geoserverURL}/geoserver/wfs?service=WFS&` +
3434
`version=1.1.0&request=GetFeature&typename=${
3535
import.meta.env.FRONTEND_GEOSERVER_NAMESPACE
36-
}:beaches&outputFormat=application/json&srsname=${WSG84_PROJECTION}&CQL_FILTER=${encodeURIComponent(cqlFilter)}`
36+
}:search_beaches&outputFormat=application/json&srsname=${WSG84_PROJECTION}&CQL_FILTER=${encodeURIComponent(
37+
cqlFilter
38+
)}`
3739
)
3840
.then(response => {
3941
if (response.status === OK) {

frontend/src/features/LocateOnMap/SearchLocation.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export function SearchLocation() {
2626
}
2727
let extent: Extent | undefined
2828

29-
if (location.id.startsWith('beaches')) {
29+
if (location.id.startsWith('search_beaches')) {
3030
const selectedBeach = beaches.find(beach => beach.id === location.id)
3131
if (selectedBeach) {
3232
extent = transformExtent(selectedBeach.bbox, WSG84_PROJECTION, OPENLAYERS_PROJECTION)

infra/init/geoserver_init_layers.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -347,9 +347,9 @@ EOF
347347
curl -v -u ${GEOSERVER_ADMIN_USER}:${GEOSERVER_ADMIN_PASSWORD} -X POST http://${GEOSERVER_HOST}:${GEOSERVER_PORT}/geoserver/rest/workspaces/monitorenv/datastores/monitorenv_postgis/featuretypes -H "accept: text/html" -H "content-type: application/json" -d @- << EOF
348348
{
349349
"featureType": {
350-
"name": "beaches",
351-
"nativeName": "beaches",
352-
"title": "beaches",
350+
"name": "search_beaches",
351+
"nativeName": "search_beaches",
352+
"title": "search_beaches",
353353
"nativeCRS": "EPSG:4326",
354354
"srs": "EPSG:4326",
355355
"enabled": true,

0 commit comments

Comments
 (0)