This commit is contained in:
albert
2013-02-26 22:56:16 -08:00
parent 533e06415b
commit cf2250a17f
2 changed files with 3 additions and 2 deletions

View File

@@ -225,7 +225,8 @@ class Artist < ActiveRecord::Base
def any_name_matches(name)
stripped_name = normalize_name(name).to_escaped_for_sql_like
where("(name LIKE ? ESCAPE E'\\\\' OR other_names_index @@ to_tsquery('danbooru', ?))", stripped_name, normalize_name(name))
name_for_tsquery = normalize_name(name).gsub(/\(/, "\\(").gsub(/\)/, "\\)")
where("(name LIKE ? ESCAPE E'\\\\' OR other_names_index @@ to_tsquery('danbooru', ?))", stripped_name, name_for_tsquery)
end
def search(params)

View File

@@ -2,7 +2,7 @@ module Danbooru
module Extensions
module String
def to_escaped_for_sql_like
return self.gsub(/\\/, '\0\0').gsub(/%/, '\\%').gsub(/_/, '\\_').gsub(/\*/, '%')
return self.gsub(/\\/, '\0\0').gsub(/(%|_)/, '\\\\\\1').gsub(/_/, '\\_').gsub(/\*/, '%')
end
def to_escaped_js