lib/pg_search/features/tsearch.rb in pg_search-0.7.2 vs lib/pg_search/features/tsearch.rb in pg_search-0.7.3

- old
+ new

@@ -52,15 +52,18 @@ tsquery_terms = query_terms.map { |term| tsquery_for_term(term) } tsquery_terms.join(options[:any_word] ? ' || ' : ' && ') end def tsdocument - if options[:tsvector_column] - column_name = connection.quote_column_name(options[:tsvector_column]) - "#{quoted_table_name}.#{column_name}" - else - columns.map do |search_column| + tsdocument_terms = [] + + columns_to_use = options[:tsvector_column] ? + columns.select { |c| c.is_a?(PgSearch::Configuration::ForeignColumn) } : + columns + + if columns_to_use.present? + tsdocument_terms << columns_to_use.map do |search_column| tsvector = Arel::Nodes::NamedFunction.new( "to_tsvector", [dictionary, Arel.sql(normalize(search_column.to_sql))] ).to_sql @@ -69,9 +72,16 @@ else "setweight(#{tsvector}, #{connection.quote(search_column.weight)})" end end.join(" || ") end + + if options[:tsvector_column] + column_name = connection.quote_column_name(options[:tsvector_column]) + tsdocument_terms << "#{quoted_table_name}.#{column_name}" + end + + tsdocument_terms.join(' || ') end # From http://www.postgresql.org/docs/8.3/static/textsearch-controls.html # 0 (the default) ignores the document length # 1 divides the rank by 1 + the logarithm of the document length