FIX: Update mapping between locales and Postgres dictionaries. (#7606)

FIX: Update mapping between locales and Postgres dictionaries. (#7606)

diff --git a/lib/search.rb b/lib/search.rb
index 48f54f7..13a3149 100644
--- a/lib/search.rb
+++ b/lib/search.rb
@@ -41,19 +41,22 @@ class Search
     # But it may not appear there based on pg extension configuration.
     # base docker config
     #
-    case locale.to_sym
-    when :da     then 'danish'
-    when :de     then 'german'
-    when :en     then 'english'
-    when :es     then 'spanish'
-    when :fr     then 'french'
-    when :it     then 'italian'
-    when :nl     then 'dutch'
-    when :nb_NO  then 'norwegian'
-    when :pt     then 'portuguese'
-    when :pt_BR  then 'portuguese'
-    when :sv     then 'swedish'
-    when :ru     then 'russian'
+    case locale.split("_")[0].to_sym
+    when :da then 'danish'
+    when :nl then 'dutch'
+    when :en then 'english'
+    when :fi then 'finnish'
+    when :fr then 'french'
+    when :de then 'german'
+    when :hu then 'hungarian'
+    when :it then 'italian'
+    when :nb then 'norwegian'
+    when :pt then 'portuguese'
+    when :ro then 'romanian'
+    when :ru then 'russian'
+    when :es then 'spanish'
+    when :sv then 'swedish'
+    when :tr then 'turkish'
     else 'simple' # use the 'simple' stemmer for other languages
     end
   end
diff --git a/spec/lib/search_spec.rb b/spec/lib/search_spec.rb
new file mode 100644
index 0000000..5108b82
--- /dev/null
+++ b/spec/lib/search_spec.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+require 'rails_helper'
+
+describe Search do
+
+  context "#ts_config" do
+    it "maps locales to correct Postgres dictionaries" do
+      expect(Search.ts_config).to eq("english")
+      expect(Search.ts_config("en")).to eq("english")
+      expect(Search.ts_config("en_US")).to eq("english")
+      expect(Search.ts_config("pt_BR")).to eq("portuguese")
+      expect(Search.ts_config("tr")).to eq("turkish")
+      expect(Search.ts_config("xx")).to eq("simple")
+    end
+  end
+
+end

GitHub sha: 6bd082fe