lib/pg_search/features/tsearch.rb in pg_search-0.5.4 vs lib/pg_search/features/tsearch.rb in pg_search-0.5.5
- old
+ new
@@ -3,14 +3,14 @@
module PgSearch
module Features
class TSearch < Feature
delegate :connection, :quoted_table_name, :to => :'@model'
- def initialize(query, options, columns, model, normalizer)
+ def initialize(*args)
super
- if @options[:prefix] && @model.connection.send(:postgresql_version) < 80400
+ if options[:prefix] && model.connection.send(:postgresql_version) < 80400
raise PgSearch::NotSupportedForPostgresqlVersion.new(<<-MESSAGE.gsub /^\s*/, '')
Sorry, {:using => {:tsearch => {:prefix => true}}} only works in PostgreSQL 8.4 and above.")
MESSAGE
end
end
@@ -24,11 +24,11 @@
end
private
def interpolations
- {:query => @query.to_s, :dictionary => dictionary.to_s}
+ {:query => query.to_s, :dictionary => dictionary.to_s}
end
DISALLOWED_TSQUERY_CHARACTERS = /['?\\:]/
def tsquery_for_term(term)
@@ -40,29 +40,29 @@
# 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])
+ (connection.quote(':*') if options[:prefix])
].compact.join(" || ")
"to_tsquery(:dictionary, #{tsquery_sql})"
end
def tsquery
- return "''" if @query.blank?
- query_terms = @query.split(" ").compact
+ return "''" if query.blank?
+ query_terms = query.split(" ").compact
tsquery_terms = query_terms.map { |term| tsquery_for_term(term) }
- tsquery_terms.join(@options[:any_word] ? ' || ' : ' && ')
+ tsquery_terms.join(options[:any_word] ? ' || ' : ' && ')
end
def tsdocument
- if @options[:tsvector_column]
- column_name = connection.quote_column_name(@options[:tsvector_column])
+ if options[:tsvector_column]
+ column_name = connection.quote_column_name(options[:tsvector_column])
"#{quoted_table_name}.#{column_name}"
else
- @columns.map do |search_column|
+ columns.map do |search_column|
tsvector = "to_tsvector(:dictionary, #{normalize(search_column.to_sql)})"
if search_column.weight.nil?
tsvector
else
"setweight(#{tsvector}, #{connection.quote(search_column.weight)})"
@@ -79,18 +79,18 @@
# 8 divides the rank by the number of unique words in document
# 16 divides the rank by 1 + the logarithm of the number of unique words in document
# 32 divides the rank by itself + 1
# The integer option controls several behaviors, so it is a bit mask: you can specify one or more behaviors
def normalization
- @options[:normalization] || 0
+ options[:normalization] || 0
end
def tsearch_rank
["ts_rank((#{tsdocument}), (#{tsquery}), #{normalization})", interpolations]
end
def dictionary
- @options[:dictionary] || :simple
+ options[:dictionary] || :simple
end
end
end
end