From 54b4a2e0c59420155c221839e136a5c11a07f435 Mon Sep 17 00:00:00 2001 From: evazion Date: Sun, 16 Apr 2017 21:07:12 -0500 Subject: [PATCH] /post_{flags,appeals}: default to fulltext search for reason field. --- app/models/post_appeal.rb | 7 +++++-- app/models/post_flag.rb | 7 +++++-- app/views/post_appeals/_search.html.erb | 2 +- app/views/post_flags/_search.html.erb | 2 +- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/app/models/post_appeal.rb b/app/models/post_appeal.rb index 12f9119da..611044661 100644 --- a/app/models/post_appeal.rb +++ b/app/models/post_appeal.rb @@ -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) diff --git a/app/models/post_flag.rb b/app/models/post_flag.rb index e29ab64f6..1bd137f1e 100644 --- a/app/models/post_flag.rb +++ b/app/models/post_flag.rb @@ -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) diff --git a/app/views/post_appeals/_search.html.erb b/app/views/post_appeals/_search.html.erb index 1f6a5e285..cc1a98dd0 100644 --- a/app/views/post_appeals/_search.html.erb +++ b/app/views/post_appeals/_search.html.erb @@ -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] } %> diff --git a/app/views/post_flags/_search.html.erb b/app/views/post_flags/_search.html.erb index b70d5d207..2745c213f 100644 --- a/app/views/post_flags/_search.html.erb +++ b/app/views/post_flags/_search.html.erb @@ -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? %>