bug fixes

This commit is contained in:
albert
2013-03-06 01:39:25 -05:00
parent 93ac6601aa
commit 31927b54d7
2 changed files with 8 additions and 4 deletions

View File

@@ -1,6 +1,11 @@
class PostQueryBuilder
attr_accessor :query_string, :has_constraints
def self.escape_string_for_tsquery(token)
escaped_token = token.gsub(/\\|'/, '\0\0\0\0').gsub("?", "\\\\77").gsub("%", "\\\\37")
"''" + escaped_token + "''"
end
def initialize(query_string)
@query_string = query_string
@has_constraint = false
@@ -48,8 +53,7 @@ class PostQueryBuilder
def escape_string_for_tsquery(array)
array.map do |token|
escaped_token = token.gsub(/\\|'/, '\0\0\0\0').gsub("?", "\\\\77").gsub("%", "\\\\37")
"''" + escaped_token + "''"
PostQueryBuilder.escape_string_for_tsquery(token)
end
end

View File

@@ -938,8 +938,8 @@ class Post < ActiveRecord::Base
end
def raw_tag_match(tag)
tag = tag.gsub("(", '\\\\\\\\(')
where("posts.tag_index @@ to_tsquery('danbooru', E?)", tag)
tag = PostQueryBuilder.escape_string_for_tsquery(tag)
where("posts.tag_index @@ to_tsquery('danbooru', E'" + tag + "')")
end
def tag_match(query)