Permalink
Browse files

Use Arel to remove some calls to connection.quote

  • Loading branch information...
1 parent e0d7409 commit 4c04674ca580561c5a92c69f28c415cc035a95dd @nertzy nertzy committed Apr 2, 2013
Showing with 7 additions and 8 deletions.
  1. +7 −8 lib/pg_search/features/tsearch.rb
@@ -30,20 +30,19 @@ def rank
def tsquery_for_term(term)
sanitized_term = term.gsub(DISALLOWED_TSQUERY_CHARACTERS, " ")
- term_sql = normalize(connection.quote(sanitized_term))
+ term_sql = Arel.sql(normalize(connection.quote(sanitized_term)))
# After this, the SQL expression evaluates to a string containing the term surrounded by single-quotes.
# If :prefix is true, then the term will also have :* appended to the end.
- tsquery_sql = [
- connection.quote("' "),
- term_sql,
- connection.quote(" '"),
- (connection.quote(':*') if options[:prefix])
- ].compact.join(" || ")
+ terms = ["' ", term_sql, " '", (':*' if options[:prefix])].compact
+
+ tsquery_sql = terms.inject do |memo, term|
+ Arel::Nodes::InfixOperation.new("||", memo, term)
+ end
Arel::Nodes::NamedFunction.new(
"to_tsquery",
- [dictionary, Arel.sql(tsquery_sql)]
+ [dictionary, tsquery_sql]
).to_sql
end

0 comments on commit 4c04674

Please sign in to comment.