Skip to content

Commit

Permalink
separete tokenize_query as module_function
Browse files Browse the repository at this point in the history
  • Loading branch information
moro committed Sep 2, 2008
1 parent 907486e commit 584390f
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lib/acts_as_searchable/utils.rb
@@ -0,0 +1,19 @@

module ActsAsSearchable
module Utils
MULTIBYTE_SPACE = [0x3000].pack("U")
PRESERVED_QUERY_WORDS_RE = /(AND|OR|ANDNOT)/

def tokenize_query(query)
tokens = query.scan(/'([^']*)'|"([^"]*)"|([^\s#{MULTIBYTE_SPACE}]*)/).flatten.reject(&:blank?)
tokens.map do |token|
token.gsub!(PRESERVED_QUERY_WORDS_RE, $1.downcase) if token =~ PRESERVED_QUERY_WORDS_RE
token.gsub!(/\A['"]|['"]\z/, '') # strip quatos
token
end.join(" AND ")
end

module_function :tokenize_query
end
end

0 comments on commit 584390f

Please sign in to comment.