Merge pull request #2977 from evazion/feat-flag-reason-search

Add full text search for flag/appeal reasons
This commit is contained in:
Albert Yi
2017-04-17 13:10:28 -07:00
committed by GitHub
6 changed files with 44 additions and 7 deletions

View File

@@ -12,8 +12,11 @@ class PostAppeal < ActiveRecord::Base
module SearchMethods
def reason_matches(query)
query = "*#{query}*" unless query =~ /\*/
where("reason ILIKE ? ESCAPE E'\\\\'", query.to_escaped_for_sql_like)
if query =~ /\*/
where("post_appeals.reason ILIKE ? ESCAPE E'\\\\'", query.to_escaped_for_sql_like)
else
where("to_tsvector('english', post_appeals.reason) @@ plainto_tsquery(?)", query.to_escaped_for_tsquery)
end
end
def post_tags_match(query)

View File

@@ -20,8 +20,11 @@ class PostFlag < ActiveRecord::Base
module SearchMethods
def reason_matches(query)
query = "*#{query}*" unless query =~ /\*/
where("reason ILIKE ? ESCAPE E'\\\\'", query.to_escaped_for_sql_like)
if query =~ /\*/
where("post_flags.reason ILIKE ? ESCAPE E'\\\\'", query.to_escaped_for_sql_like)
else
where("to_tsvector('english', post_flags.reason) @@ plainto_tsquery(?)", query.to_escaped_for_tsquery)
end
end
def post_tags_match(query)

View File

@@ -1,5 +1,5 @@
<%= simple_form_for(:search, url: post_appeals_path, method: :get, defaults: { required: false }, html: { class: "inline-form" }) do |f| %>
<%= f.input :reason_matches, label: "Reason", input_html: { value: params[:search][:reason_matches] } %>
<%= f.input :reason_matches, label: "Reason", hint: "Use * for wildcard searches", input_html: { value: params[:search][:reason_matches] } %>
<%= f.input :post_tags_match, label: "Tags", input_html: { value: params[:search][:post_tags_match] } %>
<%= f.input :post_id, label: "Post ID", input_html: { value: params[:search][:post_id] } %>
<%= f.input :creator_name, label: "Creator", input_html: { value: params[:search][:creator_name] } %>

View File

@@ -1,5 +1,5 @@
<%= simple_form_for(:search, url: post_flags_path, method: :get, defaults: { required: false }, html: { class: "inline-form" }) do |f| %>
<%= f.input :reason_matches, label: "Reason", input_html: { value: params[:search][:reason_matches] } %>
<%= f.input :reason_matches, label: "Reason", hint: "Use * for wildcard searches", input_html: { value: params[:search][:reason_matches] } %>
<%= f.input :post_tags_match, label: "Tags", input_html: { value: params[:search][:post_tags_match] } %>
<%= f.input :post_id, label: "Post ID", input_html: { value: params[:search][:post_id] } %>
<% if CurrentUser.is_moderator? %>