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
|
||||||
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)
|
def search(params)
|
||||||
q = super
|
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)
|
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:]]+/))
|
q = q.changed_tags_include_all(params[:changed_tags].scan(/[^[:space:]]+/))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if params[:tag_matches]
|
||||||
|
q = q.tag_matches(params[:tag_matches])
|
||||||
|
end
|
||||||
|
|
||||||
if params[:updater_name].present?
|
if params[:updater_name].present?
|
||||||
q = q.where(updater_id: User.name_to_id(params[:updater_name]))
|
q = q.where(updater_id: User.name_to_id(params[:updater_name]))
|
||||||
end
|
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)
|
q.apply_default_order(params)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -12,7 +12,9 @@
|
|||||||
<%= f.input :parent_id %>
|
<%= f.input :parent_id %>
|
||||||
<%= f.input :rating %>
|
<%= f.input :rating %>
|
||||||
<%= f.input :source_ilike, label: "Source", hint: "Use * for wildcard" %>
|
<%= f.input :source_ilike, label: "Source", hint: "Use * for wildcard" %>
|
||||||
|
<%= f.input :tag_matches, hint: "Use * for wildcard" %>
|
||||||
<%= f.input :version %>
|
<%= 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 :rating_changed, as: :select %>
|
||||||
<%= f.input :parent_changed, as: :select %>
|
<%= f.input :parent_changed, as: :select %>
|
||||||
<%= f.input :source_changed, as: :select %>
|
<%= f.input :source_changed, as: :select %>
|
||||||
|
|||||||
Reference in New Issue
Block a user