From 772003a55a1fa5cb5ad8fc4c07862694706a71b0 Mon Sep 17 00:00:00 2001 From: Toks Date: Sun, 6 Jul 2014 12:00:08 -0400 Subject: [PATCH] fixes #2217 --- app/controllers/comments_controller.rb | 12 +----------- app/logical/post_query_builder.rb | 6 ++++-- app/models/artist_commentary.rb | 2 +- app/models/comment.rb | 2 +- app/models/note.rb | 2 +- app/views/artist_commentaries/search.html.erb | 2 +- app/views/comments/search.html.erb | 2 +- app/views/notes/search.html.erb | 2 +- 8 files changed, 11 insertions(+), 19 deletions(-) diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index db07823f5..28481b569 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -1,7 +1,7 @@ class CommentsController < ApplicationController respond_to :html, :xml, :json before_filter :member_only, :only => [:update, :create, :edit, :destroy] - rescue_from ActiveRecord::StatementInvalid, :with => :search_error + rescue_from ActiveRecord::StatementInvalid, :with => :rescue_exception def index if params[:group_by] == "comment" @@ -103,14 +103,4 @@ private raise User::PrivilegeError end end - -protected - def search_error(e) - if e.message =~ /syntax error in tsquery/ - @error_message = "Meta-tags are not supported in comment searches by tag" - render :template => "static/error", :status => 500 - else - rescue_exception(e) - end - end end diff --git a/app/logical/post_query_builder.rb b/app/logical/post_query_builder.rb index 0eccc82db..c4ad741f8 100644 --- a/app/logical/post_query_builder.rb +++ b/app/logical/post_query_builder.rb @@ -101,12 +101,14 @@ class PostQueryBuilder relation end - def build + def build(relation = nil) unless query_string.is_a?(Hash) q = Tag.parse_query(query_string) end - relation = Post.where("true") + if relation.nil? + relation = Post.where("true") + end if q[:tag_count].to_i > Danbooru.config.tag_query_limit raise ::Post::SearchError.new("You cannot search for more than #{Danbooru.config.tag_query_limit} tags at a time") diff --git a/app/models/artist_commentary.rb b/app/models/artist_commentary.rb index f4b700af3..0a4760cf7 100644 --- a/app/models/artist_commentary.rb +++ b/app/models/artist_commentary.rb @@ -13,7 +13,7 @@ class ArtistCommentary < ActiveRecord::Base end def post_tags_match(query) - joins(:post).where("posts.tag_index @@ to_tsquery('danbooru', ?)", query.to_escaped_for_tsquery_split) + PostQueryBuilder.new(query).build(self.joins(:post)) end def search(params) diff --git a/app/models/comment.rb b/app/models/comment.rb index 3ed48fece..08c2d0443 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -33,7 +33,7 @@ class Comment < ActiveRecord::Base end def post_tags_match(query) - joins(:post).where("posts.tag_index @@ to_tsquery('danbooru', ?)", query.to_escaped_for_tsquery_split) + PostQueryBuilder.new(query).build(self.joins(:post)) end def for_creator(user_id) diff --git a/app/models/note.rb b/app/models/note.rb index 0d50db1a9..96e290fee 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -29,7 +29,7 @@ class Note < ActiveRecord::Base end def post_tags_match(query) - joins(:post).where("posts.tag_index @@ to_tsquery('danbooru', E?)", query.to_escaped_for_tsquery_split) + PostQueryBuilder.new(query).build(self.joins(:post)) end def for_creator(user_id) diff --git a/app/views/artist_commentaries/search.html.erb b/app/views/artist_commentaries/search.html.erb index cda34ea83..43ecf05f7 100644 --- a/app/views/artist_commentaries/search.html.erb +++ b/app/views/artist_commentaries/search.html.erb @@ -14,7 +14,7 @@ <%= select "search", "translated_present", ["yes", "no"], :include_blank => true %> - <%= search_field "post_tags_match", :label => "Tags", :hint => "Meta-tags not supported" %> + <%= search_field "post_tags_match", :label => "Tags" %> <%= submit_tag "Search" %> <% end %> diff --git a/app/views/comments/search.html.erb b/app/views/comments/search.html.erb index b69f51b6f..f7161309c 100644 --- a/app/views/comments/search.html.erb +++ b/app/views/comments/search.html.erb @@ -7,7 +7,7 @@ <%= search_field "body_matches", :label => "Body" %> <%= search_field "creator_name", :label => "User" %> - <%= search_field "post_tags_match", :label => "Tags", :hint => "Meta-tags not supported" %> + <%= search_field "post_tags_match", :label => "Tags" %> <%= submit_tag "Search" %> <% end %> diff --git a/app/views/notes/search.html.erb b/app/views/notes/search.html.erb index 13b0ebe33..5a2174aa7 100644 --- a/app/views/notes/search.html.erb +++ b/app/views/notes/search.html.erb @@ -7,7 +7,7 @@ <%= search_field "body_matches", :label => "Body" %> <%= search_field "creator_name", :label => "Author" %> - <%= search_field "post_tags_match", :label => "Tags", :hint => "Meta-tags not supported" %> + <%= search_field "post_tags_match", :label => "Tags" %> <%= submit_tag "Search" %> <% end %>