From 4a5e20929693f20997ac38ba83934783b54f58bb Mon Sep 17 00:00:00 2001 From: stephanie-warmenhoven Date: Thu, 23 Apr 2020 16:21:16 -0700 Subject: [PATCH] [#1713] Added uniq to tags and cleaned code --- app/controllers/moments_controller.rb | 4 ++-- app/services/moment_keywords.rb | 3 +-- app/services/resource_recommendations.rb | 15 +++++++-------- app/views/moments/show.html.erb | 2 -- 4 files changed, 10 insertions(+), 14 deletions(-) diff --git a/app/controllers/moments_controller.rb b/app/controllers/moments_controller.rb index b0f54cec2b..b612f37a3f 100644 --- a/app/controllers/moments_controller.rb +++ b/app/controllers/moments_controller.rb @@ -28,10 +28,10 @@ def show @resources = ResourceRecommendations.new(@moment).call @matched_tags = ResourceRecommendations.new(@moment).matched_tags @moment_keywords = MomentKeywords.new(@moment).call - @filter_tags = @matched_tags.map do |t| + @filter_tags = @matched_tags.uniq.map do |t| "filter[]=#{t}&" end - @filter_tags = @filter_tags.join() + @filter_tags = @filter_tags.join end # GET /moments/new diff --git a/app/services/moment_keywords.rb b/app/services/moment_keywords.rb index a376a4f990..b7b43a5903 100644 --- a/app/services/moment_keywords.rb +++ b/app/services/moment_keywords.rb @@ -15,7 +15,7 @@ def call extract(@moment.fix)) remove_special_chars downcase_keywords - @moment_keywords = @moment_keywords.uniq.join(' ') + @moment_keywords = @moment_keywords.join(' ') end private @@ -37,7 +37,6 @@ def extract(array) def remove_special_chars @moment_keywords = @moment_keywords.flatten.each do |keyword| - # keyword.gsub!(/[\-_]/, ' ') keyword.gsub!(/[^\p{Alpha} -]/, '') end end diff --git a/app/services/resource_recommendations.rb b/app/services/resource_recommendations.rb index 0b91b1d3f9..de53445f41 100644 --- a/app/services/resource_recommendations.rb +++ b/app/services/resource_recommendations.rb @@ -10,25 +10,24 @@ def call @moment_keywords = MomentKeywords.new(@moment).call all_resources.select do |resource| resource['tags'].any? do |tag| - @moment_keywords.match?(tag) + @moment_keywords.match?(tag) end end end def matched_tags @moment_keywords = MomentKeywords.new(@moment).call - resource_tags = all_resources.flat_map do |resource| - resource['tags'].select do |tag| - @moment_keywords.match?(tag) - end - end - resource_tags + resource_tags = all_resources.flat_map do |resource| + resource['tags'].select do |tag| + @moment_keywords.match?(tag) + end + end + resource_tags end private def all_resources - # JSON.parse(File.read(Rails.root.join('doc', 'pages', 'resources.json'))) resources = JSON.parse(File.read('doc/pages/resources.json')) resources.each do |item| item['tags'].map! { |tag| I18n.t("pages.resources.tags.#{tag}") } diff --git a/app/views/moments/show.html.erb b/app/views/moments/show.html.erb index d137b09f0c..22fb1edc5e 100644 --- a/app/views/moments/show.html.erb +++ b/app/views/moments/show.html.erb @@ -53,8 +53,6 @@
  • <%= link_to 'More...', "/resources?#{@filter_tags}" %>
  • - <%= @filter_tags %> - <%= "Moment keywords:" "#{@moment_keywords}" %> <% end %>