/post_{flags,appeals}: default to fulltext search for reason field.

This commit is contained in:
evazion
2017-04-16 21:07:12 -05:00
parent 6d693799a0
commit 54b4a2e0c5
4 changed files with 12 additions and 6 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? %>