Improved organization search.
This commit is contained in:
parent
72df345203
commit
27d7172543
2 changed files with 16 additions and 5 deletions
|
@ -21,8 +21,8 @@ class SearchController < ApplicationController
|
|||
|
||||
# do query
|
||||
users = User.search(
|
||||
:query => params[:term],
|
||||
:limit => params[:limit],
|
||||
:query => params[:term],
|
||||
:limit => params[:limit],
|
||||
:current_user => current_user,
|
||||
)
|
||||
user_result = []
|
||||
|
@ -32,10 +32,11 @@ class SearchController < ApplicationController
|
|||
end
|
||||
|
||||
organizations = Organization.search(
|
||||
:query => params[:term],
|
||||
:limit => params[:limit],
|
||||
:query => params[:term],
|
||||
:limit => params[:limit],
|
||||
:current_user => current_user,
|
||||
)
|
||||
|
||||
organizations_data = {}
|
||||
organization_result = []
|
||||
organizations.each do |organization|
|
||||
|
|
|
@ -16,9 +16,19 @@ class Organization < ApplicationModel
|
|||
organizations = Organization.find(
|
||||
:all,
|
||||
:limit => limit,
|
||||
:conditions => ['name LIKE ?', "%#{query}%"],
|
||||
:conditions => ['name LIKE ? OR note LIKE ?', "%#{query}%", "%#{query}%"],
|
||||
:order => 'name'
|
||||
)
|
||||
|
||||
# if only a few organizations are found, search for names of users
|
||||
if organizations.length <= 3
|
||||
organizations = Organization.select('DISTINCT(organizations.id)').joins('LEFT OUTER JOIN users ON users.organization_id = organizations.id').find(
|
||||
:all,
|
||||
:limit => limit,
|
||||
:conditions => ['users.firstname LIKE ? or users.lastname LIKE ? or users.email LIKE ?', "%#{query}%", "%#{query}%", "%#{query}%"],
|
||||
:order => 'organizations.name'
|
||||
)
|
||||
end
|
||||
return organizations
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue