current limit

This commit is contained in:
simon lehericey 2024-12-03 17:18:34 +01:00
parent 08258630ed
commit c6c82579b8
No known key found for this signature in database
GPG key ID: CDE670D827C7B3C5
2 changed files with 9 additions and 7 deletions

View file

@ -27,20 +27,18 @@ class DossierSearchService
end end
def self.dossier_ids_by_full_text(dossiers, search_terms, with_annotations) 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, search_terms, with_annotations:)
dossier_by_full_text(dossiers.visible_by_administration, columns, search_terms)
.pluck('id') .pluck('id')
.uniq .uniq
end end
def self.dossier_by_full_text_for_user(search_terms, dossiers) def self.dossier_by_full_text_for_user(search_terms, dossiers)
columns = 'search_terms' dossier_by_full_text(dossiers.visible_by_user, search_terms)
dossier_by_full_text(dossiers.visible_by_user, columns, search_terms)
end 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_vector = "to_tsvector('french', unaccent(#{columns}))"
ts_query = "to_tsquery('french', unaccent(#{Dossier.connection.quote(to_tsquery(search_terms))}))" ts_query = "to_tsquery('french', unaccent(#{Dossier.connection.quote(to_tsquery(search_terms))}))"

View file

@ -64,6 +64,10 @@ describe DossierSearchService do
# without accent # without accent
expect(searching('helene')).to eq([dossier.id]) expect(searching('helene')).to eq([dossier.id])
# NOT WORKING YET
# with a single faulty character
expect(searching('des pammes')).to eq([])
end end
end end