From c6c82579b898df550f87922b25a47dafb294f342 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Tue, 3 Dec 2024 17:18:34 +0100 Subject: [PATCH] current limit --- app/services/dossier_search_service.rb | 12 +++++------- spec/services/dossier_search_service_spec.rb | 4 ++++ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/app/services/dossier_search_service.rb b/app/services/dossier_search_service.rb index 98bc3cdfa..17eecece4 100644 --- a/app/services/dossier_search_service.rb +++ b/app/services/dossier_search_service.rb @@ -27,20 +27,18 @@ class DossierSearchService end def self.dossier_ids_by_full_text(dossiers, search_terms, with_annotations) - columns = with_annotations ? 'search_terms || private_search_terms' : 'search_terms' - - dossier_by_full_text(dossiers.visible_by_administration, columns, search_terms) + dossier_by_full_text(dossiers.visible_by_administration, search_terms, with_annotations:) .pluck('id') .uniq end def self.dossier_by_full_text_for_user(search_terms, dossiers) - columns = 'search_terms' - - dossier_by_full_text(dossiers.visible_by_user, columns, search_terms) + dossier_by_full_text(dossiers.visible_by_user, search_terms) end - def self.dossier_by_full_text(dossiers, columns, search_terms) + def self.dossier_by_full_text(dossiers, search_terms, with_annotations: false) + columns = with_annotations ? 'search_terms || private_search_terms' : 'search_terms' + ts_vector = "to_tsvector('french', unaccent(#{columns}))" ts_query = "to_tsquery('french', unaccent(#{Dossier.connection.quote(to_tsquery(search_terms))}))" diff --git a/spec/services/dossier_search_service_spec.rb b/spec/services/dossier_search_service_spec.rb index f5827826d..3c068b640 100644 --- a/spec/services/dossier_search_service_spec.rb +++ b/spec/services/dossier_search_service_spec.rb @@ -64,6 +64,10 @@ describe DossierSearchService do # without accent expect(searching('helene')).to eq([dossier.id]) + + # NOT WORKING YET + # with a single faulty character + expect(searching('des pammes')).to eq([]) end end