Add additional advanced search operators
- Tag matches allows a user to search for a single tag -- Since testing for multiple tags would require converting the "tags" string to an array which would most likely fail even for single tags - Is new for quick searching of uploads or not uploads
This commit is contained in:
@@ -32,6 +32,13 @@ class PostVersion < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
def tag_matches(string)
|
||||
tag = string.split(/\S+/)[0]
|
||||
return all if tag.nil?
|
||||
tag = "*#{tag}*" unless tag =~ /\*/
|
||||
where_ilike(:tags, tag)
|
||||
end
|
||||
|
||||
def search(params)
|
||||
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)
|
||||
@@ -40,10 +47,20 @@ class PostVersion < ApplicationRecord
|
||||
q = q.changed_tags_include_all(params[:changed_tags].scan(/[^[:space:]]+/))
|
||||
end
|
||||
|
||||
if params[:tag_matches]
|
||||
q = q.tag_matches(params[:tag_matches])
|
||||
end
|
||||
|
||||
if params[:updater_name].present?
|
||||
q = q.where(updater_id: User.name_to_id(params[:updater_name]))
|
||||
end
|
||||
|
||||
if params[:is_new].to_s.truthy?
|
||||
q = q.where(version: 1)
|
||||
elsif params[:is_new].to_s.falsy?
|
||||
q = q.where("version != 1")
|
||||
end
|
||||
|
||||
q.apply_default_order(params)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -12,7 +12,9 @@
|
||||
<%= f.input :parent_id %>
|
||||
<%= f.input :rating %>
|
||||
<%= f.input :source_ilike, label: "Source", hint: "Use * for wildcard" %>
|
||||
<%= f.input :tag_matches, hint: "Use * for wildcard" %>
|
||||
<%= f.input :version %>
|
||||
<%= f.input :is_new, label: "Include uploads?", collection: [["Yes", nil], ["No", false], ["Only", true]], include_blank: false, hint: "I.e. the 1st versions of posts" %>
|
||||
<%= f.input :rating_changed, as: :select %>
|
||||
<%= f.input :parent_changed, as: :select %>
|
||||
<%= f.input :source_changed, as: :select %>
|
||||
|
||||
Reference in New Issue
Block a user