lib/pg_search/features/tsearch.rb in pg_search-0.7.6 vs lib/pg_search/features/tsearch.rb in pg_search-0.7.7

- old
+ new

@@ -1,5 +1,6 @@ +require "pg_search/compatibility" require "active_support/core_ext/module/delegation" module PgSearch module Features class TSearch < Feature @@ -25,21 +26,26 @@ private DISALLOWED_TSQUERY_CHARACTERS = /['?\\:]/ - def tsquery_for_term(term) - sanitized_term = term.gsub(DISALLOWED_TSQUERY_CHARACTERS, " ") + def tsquery_for_term(unsanitized_term) + sanitized_term = unsanitized_term.gsub(DISALLOWED_TSQUERY_CHARACTERS, " ") 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. - terms = ["' ", term_sql, " '", (':*' if options[:prefix])].compact + terms = [ + Compatibility.build_quoted("' "), + term_sql, + Compatibility.build_quoted(" '"), + (Compatibility.build_quoted(":*") if options[:prefix]) + ].compact tsquery_sql = terms.inject do |memo, term| - Arel::Nodes::InfixOperation.new("||", memo, term) + Arel::Nodes::InfixOperation.new("||", memo, Compatibility.build_quoted(term)) end Arel::Nodes::NamedFunction.new( "to_tsquery", [dictionary, tsquery_sql] @@ -82,10 +88,10 @@ def tsearch_rank "ts_rank((#{tsdocument}), (#{tsquery}), #{normalization})" end def dictionary - options[:dictionary] || :simple + Compatibility.build_quoted(options[:dictionary] || :simple) end def arel_wrap(sql_string) Arel::Nodes::Grouping.new(Arel.sql(sql_string)) end