downcase query string for search
This commit is contained in:
parent
16bd3e4c2f
commit
2b550906fc
1 changed files with 5 additions and 1 deletions
|
|
@ -45,6 +45,8 @@ class Person < ActiveRecord::Base
|
|||
scope :searchable, joins(:profile).where(:profiles => {:searchable => true})
|
||||
|
||||
def self.search_query_string(query)
|
||||
query = query.downcase
|
||||
|
||||
if postgres?
|
||||
where_clause = <<-SQL
|
||||
profiles.full_name ILIKE ? OR
|
||||
|
|
@ -57,7 +59,7 @@ class Person < ActiveRecord::Base
|
|||
SQL
|
||||
end
|
||||
|
||||
q_tokens = query.to_s.strip.gsub(/(\s|$|^)/) { "%#{$1}" }
|
||||
q_tokens = query.to_s.strip.gsub(/(\s|$)/) { "%#{$1}" }
|
||||
[where_clause, [q_tokens, q_tokens]]
|
||||
end
|
||||
|
||||
|
|
@ -66,6 +68,8 @@ class Person < ActiveRecord::Base
|
|||
|
||||
sql, tokens = self.search_query_string(query)
|
||||
|
||||
pp tokens
|
||||
|
||||
Person.searchable.where(sql, *tokens).joins(
|
||||
"LEFT OUTER JOIN contacts ON contacts.user_id = #{user.id} AND contacts.person_id = people.id"
|
||||
).includes(:profile
|
||||
|
|
|
|||
Loading…
Reference in a new issue