私はこのモデルを持っています
class Post < ActiveRecord::Base
attr_accessible :content, :title, :user_id
belongs_to :user
def self.text_search(query)
if query.present?
rank = <<-RANK
ts_rank(to_tsvector(title), plainto_tsquery(#{sanitize(query)})) +
ts_rank(to_tsvector(content), plainto_tsquery(#{sanitize(query)}))
RANK
where("to_tsvector('english', title) @@ :q or
to_tsvector('english', content) @@ :q", q: sanitize(query)).order("#{rank} desc")
else
scoped
end
end
end
そして、私はこのメソッド呼び出しを持っています
Post.text_search("Where is the safest place")
質問: SQL で呼び出されたときにクエリが二重引用符をエスケープしないのはなぜですか? ここに示すように:
Post Load (2.4ms) SELECT "posts".* FROM "posts" WHERE (to_tsvector('english', title) @@ '''Where is the safest place''' or
to_tsvector('english', content) @@ '''Where is the safest place''') ORDER BY ts_rank(to_tsvector(title), plainto_tsquery('Where is the safest place')) +
ts_rank(to_tsvector(content), plainto_tsquery('Where is the safest place'))