From b508d99ead6c0d59767aed3a6837c7f88aa605b4 Mon Sep 17 00:00:00 2001 From: Nicolas Florentin Date: Thu, 7 Dec 2023 09:33:07 +0100 Subject: [PATCH 1/2] makes tag searches accent insensitive --- app/models/concerns/taggable.rb | 3 ++- spec/models/taggable_spec.rb | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/models/concerns/taggable.rb b/app/models/concerns/taggable.rb index 70f1c0ab..4dba82ec 100644 --- a/app/models/concerns/taggable.rb +++ b/app/models/concerns/taggable.rb @@ -42,7 +42,8 @@ def tag_cloud end def find_like_tag(pattern) - all_tags.uniq.select { |t| t =~ /#{pattern}/i } + transliterated_pattern = pattern.present? ? ActiveSupport::Inflector.transliterate(pattern) : "" + all_tags.uniq.select { |t| ActiveSupport::Inflector.transliterate(t) =~ /#{transliterated_pattern}/i } end # Builds a hash where the keys are the capital letters of the tags and the diff --git a/spec/models/taggable_spec.rb b/spec/models/taggable_spec.rb index 542c1a3d..167e40c0 100644 --- a/spec/models/taggable_spec.rb +++ b/spec/models/taggable_spec.rb @@ -1,7 +1,7 @@ RSpec.describe Taggable do let(:organization) { Fabricate(:organization) } - let(:tags) { %w(foo bar baz) } - let(:more_tags) { %w(foo baz qux) } + let(:tags) { %w(foo bar baz test) } + let(:more_tags) { %w(foo baz qux têst) } let!(:offer) do Fabricate( :offer, @@ -30,6 +30,8 @@ expect(Offer.find_like_tag("foo")).to eq ["foo"] expect(Offer.find_like_tag("Foo")).to eq ["foo"] expect(Offer.find_like_tag("none")).to eq [] + expect(Offer.find_like_tag("test")).to match_array ["test", "têst"] + expect(Offer.find_like_tag("têst")).to match_array ["test", "têst"] end describe '.alphabetical_grouped_tags' do From 78d0fb001532507826fedb3def4fe17d2e7c17f1 Mon Sep 17 00:00:00 2001 From: Nicolas Florentin Date: Thu, 7 Dec 2023 09:33:56 +0100 Subject: [PATCH 2/2] makes member searches accent insensitive --- app/views/users/index.html.erb | 2 +- app/views/users/manage.html.erb | 2 +- config/initializers/ransack.rb | 8 ++++++++ spec/controllers/users_controller_spec.rb | 12 +++++++----- 4 files changed, 17 insertions(+), 7 deletions(-) create mode 100644 config/initializers/ransack.rb diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index 47b7322e..bf73c674 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -11,7 +11,7 @@
<%= search_form_for(@search, class: "navbar-form navbar-left", url: users_path) do |f| %>
- <%= f.search_field :member_search_cont, value: params.dig(:q, :member_search_cont), class: "form-control" %> + <%= f.search_field :member_search_unaccent_cont, value: params.dig(:q, :member_search_unaccent_cont), class: "form-control" %>