Merge pull request #2977 from evazion/feat-flag-reason-search
Add full text search for flag/appeal reasons
This commit is contained in:
@@ -12,8 +12,11 @@ class PostAppeal < ActiveRecord::Base
|
|||||||
|
|
||||||
module SearchMethods
|
module SearchMethods
|
||||||
def reason_matches(query)
|
def reason_matches(query)
|
||||||
query = "*#{query}*" unless query =~ /\*/
|
if query =~ /\*/
|
||||||
where("reason ILIKE ? ESCAPE E'\\\\'", query.to_escaped_for_sql_like)
|
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
|
end
|
||||||
|
|
||||||
def post_tags_match(query)
|
def post_tags_match(query)
|
||||||
|
|||||||
@@ -20,8 +20,11 @@ class PostFlag < ActiveRecord::Base
|
|||||||
|
|
||||||
module SearchMethods
|
module SearchMethods
|
||||||
def reason_matches(query)
|
def reason_matches(query)
|
||||||
query = "*#{query}*" unless query =~ /\*/
|
if query =~ /\*/
|
||||||
where("reason ILIKE ? ESCAPE E'\\\\'", query.to_escaped_for_sql_like)
|
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
|
end
|
||||||
|
|
||||||
def post_tags_match(query)
|
def post_tags_match(query)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<%= simple_form_for(:search, url: post_appeals_path, method: :get, defaults: { required: false }, html: { class: "inline-form" }) do |f| %>
|
<%= 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_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 :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] } %>
|
<%= f.input :creator_name, label: "Creator", input_html: { value: params[:search][:creator_name] } %>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<%= simple_form_for(:search, url: post_flags_path, method: :get, defaults: { required: false }, html: { class: "inline-form" }) do |f| %>
|
<%= 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_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 :post_id, label: "Post ID", input_html: { value: params[:search][:post_id] } %>
|
||||||
<% if CurrentUser.is_moderator? %>
|
<% if CurrentUser.is_moderator? %>
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
class AddReasonTsVectorIndexToPostFlagsAndAppeals < ActiveRecord::Migration
|
||||||
|
def up
|
||||||
|
execute "SET statement_timeout = 0"
|
||||||
|
execute "CREATE INDEX index_post_flags_on_reason_tsvector ON post_flags USING gin (to_tsvector('pg_catalog.english', reason))"
|
||||||
|
execute "CREATE INDEX index_post_appeals_on_reason_tsvector ON post_appeals USING gin (to_tsvector('pg_catalog.english', reason))"
|
||||||
|
end
|
||||||
|
|
||||||
|
def down
|
||||||
|
execute "SET statement_timeout = 0"
|
||||||
|
remove_index :post_flags, name: "index_post_flags_on_reason_tsvector"
|
||||||
|
remove_index :post_appeals, name: "index_post_appeals_on_reason_tsvector"
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -6805,7 +6805,7 @@ CREATE INDEX index_pools_on_name ON pools USING btree (name);
|
|||||||
-- Name: index_pools_on_name_trgm; Type: INDEX; Schema: public; Owner: -
|
-- Name: index_pools_on_name_trgm; Type: INDEX; Schema: public; Owner: -
|
||||||
--
|
--
|
||||||
|
|
||||||
CREATE INDEX index_pools_on_name_trgm ON pools USING gin (name gin_trgm_ops);
|
CREATE INDEX index_pools_on_name_trgm ON pools USING gin (lower((name)::text) gin_trgm_ops);
|
||||||
|
|
||||||
|
|
||||||
--
|
--
|
||||||
@@ -6836,6 +6836,13 @@ CREATE INDEX index_post_appeals_on_creator_ip_addr ON post_appeals USING btree (
|
|||||||
CREATE INDEX index_post_appeals_on_post_id ON post_appeals USING btree (post_id);
|
CREATE INDEX index_post_appeals_on_post_id ON post_appeals USING btree (post_id);
|
||||||
|
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Name: index_post_appeals_on_reason_tsvector; Type: INDEX; Schema: public; Owner: -
|
||||||
|
--
|
||||||
|
|
||||||
|
CREATE INDEX index_post_appeals_on_reason_tsvector ON post_appeals USING gin (to_tsvector('english'::regconfig, reason));
|
||||||
|
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Name: index_post_approvals_on_post_id; Type: INDEX; Schema: public; Owner: -
|
-- Name: index_post_approvals_on_post_id; Type: INDEX; Schema: public; Owner: -
|
||||||
--
|
--
|
||||||
@@ -6885,6 +6892,13 @@ CREATE INDEX index_post_flags_on_creator_ip_addr ON post_flags USING btree (crea
|
|||||||
CREATE INDEX index_post_flags_on_post_id ON post_flags USING btree (post_id);
|
CREATE INDEX index_post_flags_on_post_id ON post_flags USING btree (post_id);
|
||||||
|
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Name: index_post_flags_on_reason_tsvector; Type: INDEX; Schema: public; Owner: -
|
||||||
|
--
|
||||||
|
|
||||||
|
CREATE INDEX index_post_flags_on_reason_tsvector ON post_flags USING gin (to_tsvector('english'::regconfig, reason));
|
||||||
|
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Name: index_post_votes_on_post_id; Type: INDEX; Schema: public; Owner: -
|
-- Name: index_post_votes_on_post_id; Type: INDEX; Schema: public; Owner: -
|
||||||
--
|
--
|
||||||
@@ -7581,3 +7595,7 @@ INSERT INTO schema_migrations (version) VALUES ('20170413000209');
|
|||||||
|
|
||||||
INSERT INTO schema_migrations (version) VALUES ('20170414005856');
|
INSERT INTO schema_migrations (version) VALUES ('20170414005856');
|
||||||
|
|
||||||
|
INSERT INTO schema_migrations (version) VALUES ('20170414233426');
|
||||||
|
|
||||||
|
INSERT INTO schema_migrations (version) VALUES ('20170416224142');
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user