lib/pg_search/features/tsearch.rb in pg_search-0.7.8 vs lib/pg_search/features/tsearch.rb in pg_search-0.7.9

- old
+ new

@@ -27,17 +27,24 @@ private DISALLOWED_TSQUERY_CHARACTERS = /['?\\:]/ def tsquery_for_term(unsanitized_term) + if options[:negation] && unsanitized_term.start_with?("!") + unsanitized_term[0] = '' + negated = true + end + 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. + # If :prefix is true, then the term will have :* appended to the end. + # If :negated is true, then the term will have ! prepended to the front. terms = [ + (Compatibility.build_quoted('!') if negated), Compatibility.build_quoted("' "), term_sql, Compatibility.build_quoted(" '"), (Compatibility.build_quoted(":*") if options[:prefix]) ].compact @@ -63,11 +70,16 @@ tsdocument_terms = (columns_to_use || []).map do |search_column| column_to_tsvector(search_column) end if options[:tsvector_column] - column_name = connection.quote_column_name(options[:tsvector_column]) - tsdocument_terms << "#{quoted_table_name}.#{column_name}" + tsvector_columns = Array.wrap(options[:tsvector_column]) + + tsdocument_terms << tsvector_columns.map do |tsvector_column| + column_name = connection.quote_column_name(tsvector_column) + + "#{quoted_table_name}.#{column_name}" + end end tsdocument_terms.join(' || ') end