This repository has been archived by the owner on Dec 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modification de la recherche des établissements:
- ignore les accents
- Loading branch information
1 parent
0d91655
commit 10d5746
Showing
7 changed files
with
112 additions
and
12 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
database/migrations/29_alter_indexes_etablissements.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
CREATE OR REPLACE FUNCTION f_unaccent(text) | ||
RETURNS text AS | ||
$func$ | ||
SELECT public.unaccent('public.unaccent', $1) -- schema-qualify function and dictionary | ||
$func$ LANGUAGE sql IMMUTABLE; | ||
|
||
DROP INDEX trgm_idx_etablissments_nom; | ||
CREATE INDEX trgm_idx_etablissments_nom ON etablissements USING gin (f_unaccent(nom) gin_trgm_ops); | ||
DROP INDEX trgm_idx_etablissments_raison; | ||
CREATE INDEX trgm_idx_etablissments_raison ON etablissements USING gin (f_unaccent(raison) gin_trgm_ops); | ||
DROP INDEX trgm_idx_etablissments_adresse1; | ||
CREATE INDEX trgm_idx_etablissments_adresse1 ON etablissements USING gin (f_unaccent(adresse1) gin_trgm_ops); | ||
DROP INDEX trgm_idx_etablissments_adresse2; | ||
CREATE INDEX trgm_idx_etablissments_adresse2 ON etablissements USING gin (f_unaccent(adresse2) gin_trgm_ops); | ||
DROP INDEX trgm_idx_etablissments_commune; | ||
CREATE INDEX trgm_idx_etablissments_commune ON etablissements USING gin (f_unaccent(commune) gin_trgm_ops); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package integration | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/MTES-MCT/filharmonic-api/domain" | ||
"github.com/MTES-MCT/filharmonic-api/models" | ||
|
||
"github.com/MTES-MCT/filharmonic-api/tests" | ||
) | ||
|
||
func TestSearchEtablissements(t *testing.T) { | ||
assert, application, close := tests.InitService(t) | ||
defer close() | ||
|
||
ctxInspecteur := &domain.UserContext{ | ||
User: &models.User{ | ||
Id: 3, | ||
Profile: models.ProfilInspecteur, | ||
}, | ||
} | ||
etablissementsInput := []models.Etablissement{ | ||
models.Etablissement{ | ||
Nom: "Équipement de pression", | ||
}, | ||
models.Etablissement{ | ||
Nom: "equipement de pression", | ||
}, | ||
models.Etablissement{ | ||
Nom: "pression", | ||
}, | ||
} | ||
assert.NoError(application.DB.Insert(&etablissementsInput)) | ||
filter := domain.ListEtablissementsFilter{ | ||
Nom: "équipement", | ||
} | ||
etablissements, err := application.Service.ListEtablissements(ctxInspecteur, filter) | ||
assert.NoError(err) | ||
assert.Equal(2, etablissements.Total) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package util | ||
|
||
import ( | ||
"unicode" | ||
|
||
"golang.org/x/text/runes" | ||
"golang.org/x/text/transform" | ||
"golang.org/x/text/unicode/norm" | ||
) | ||
|
||
func Normalize(value string) string { | ||
t := transform.Chain(norm.NFD, runes.Remove(runes.In(unicode.Mn)), norm.NFC) | ||
s, _, _ := transform.String(t, value) | ||
return s | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package util | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestNormalize(t *testing.T) { | ||
assert := require.New(t) | ||
assert.Equal("equipement", Normalize("équipement")) | ||
assert.Equal("Equipement", Normalize("Équipement")) | ||
assert.Equal("hotel", Normalize("hôtel")) | ||
assert.Equal("A Nantes", Normalize("À Nantes")) | ||
assert.Equal("A-Nantes", Normalize("À-Nantes")) | ||
assert.Equal("A_Nantes", Normalize("À_Nantes")) | ||
} |