Merge pull request #4563 from BrokenEagle/add-postver-search

Add search for a list of any changed tags
This commit is contained in:
evazion
2020-08-07 10:03:24 -05:00
committed by GitHub
3 changed files with 14 additions and 4 deletions

View File

@@ -32,6 +32,10 @@ class PostVersion < ApplicationRecord
end
end
def changed_tags_include_any(tags)
where_array_includes_any(:added_tags, tags).or(where_array_includes_any(:removed_tags, tags))
end
def tag_matches(string)
tag = string.match(/\S+/)[0]
return all if tag.nil?
@@ -43,8 +47,12 @@ class PostVersion < ApplicationRecord
q = super
q = q.search_attributes(params, :updater_id, :post_id, :tags, :added_tags, :removed_tags, :rating, :rating_changed, :parent_id, :parent_changed, :source, :source_changed, :version)
if params[:changed_tags]
q = q.changed_tags_include_all(params[:changed_tags].scan(/[^[:space:]]+/))
if params[:all_changed_tags]
q = q.changed_tags_include_all(params[:all_changed_tags].scan(/[^[:space:]]+/))
end
if params[:any_changed_tags]
q = q.changed_tags_include_any(params[:any_changed_tags].scan(/[^[:space:]]+/))
end
if params[:tag_matches]