From 06a71cdf8572bfb5d7f845dae8f601ab5ca326a6 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Tue, 3 Dec 2024 12:49:25 +0100 Subject: [PATCH] search without accent --- app/services/dossier_search_service.rb | 4 ++-- spec/services/dossier_search_service_spec.rb | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/services/dossier_search_service.rb b/app/services/dossier_search_service.rb index dc046ed92..5d4ad7515 100644 --- a/app/services/dossier_search_service.rb +++ b/app/services/dossier_search_service.rb @@ -27,8 +27,8 @@ class DossierSearchService end def self.dossier_by_full_text(dossiers, search_terms, with_annotations) - ts_vector = "to_tsvector('french', #{with_annotations ? 'dossiers.search_terms || dossiers.private_search_terms' : 'dossiers.search_terms'})" - ts_query = "to_tsquery('french', #{Dossier.connection.quote(to_tsquery(search_terms))})" + ts_vector = "to_tsvector('french', unaccent(#{with_annotations ? 'dossiers.search_terms || dossiers.private_search_terms' : 'dossiers.search_terms'}))" + ts_query = "to_tsquery('french', unaccent(#{Dossier.connection.quote(to_tsquery(search_terms))}))" dossiers .visible_by_administration diff --git a/spec/services/dossier_search_service_spec.rb b/spec/services/dossier_search_service_spec.rb index 0970862c8..d431080ef 100644 --- a/spec/services/dossier_search_service_spec.rb +++ b/spec/services/dossier_search_service_spec.rb @@ -58,6 +58,9 @@ describe DossierSearchService do # by singular expect(searching('la pomme')).to eq([dossier.id]) + + # without accent + expect(searching('helene')).to eq([dossier.id]) end end