From 2d669899a476aeb905fd6a717514c4b9ea7f6931 Mon Sep 17 00:00:00 2001 From: BrokenEagle Date: Fri, 6 Mar 2020 06:42:05 +0000 Subject: [PATCH] Add tags overlap field This information is already available, so there's no extra processing. To avoid conflicting with the current tags field, it was made into its own field, and it uses a hash so that values can be quickly looked up. --- app/logical/related_tag_query.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/logical/related_tag_query.rb b/app/logical/related_tag_query.rb index 2a46d985e..d755e3524 100644 --- a/app/logical/related_tag_query.rb +++ b/app/logical/related_tag_query.rb @@ -26,6 +26,14 @@ class RelatedTagQuery end end + def tags_overlap + if query =~ /\*/ + {} + else + tags.map { |v| [v.name, v.overlap_count] }.to_h + end + end + # Returns the top 20 most frequently added tags within the last 20 edits made by the user in the last hour. def recent_tags(since: 1.hour.ago, max_edits: 20, max_tags: 20) return [] unless user.present? && PostVersion.enabled? @@ -78,6 +86,7 @@ class RelatedTagQuery query: query, category: category, tags: tags_with_categories(tags.map(&:name)), + tags_overlap: tags_overlap, wiki_page_tags: tags_with_categories(wiki_page_tags), other_wikis: other_wiki_pages.map { |wiki| [wiki.title, tags_with_categories(wiki.tags)] }.to_h }