2013-06-12 15:59:58 +00:00
|
|
|
# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/
|
|
|
|
|
2013-05-21 22:30:09 +00:00
|
|
|
class SearchController < ApplicationController
|
|
|
|
before_filter :authentication_check
|
|
|
|
|
2013-08-06 22:10:28 +00:00
|
|
|
# GET /api/v1/search
|
2013-05-21 22:30:09 +00:00
|
|
|
def search
|
2013-06-12 15:59:58 +00:00
|
|
|
|
2013-05-21 22:30:09 +00:00
|
|
|
# build result list
|
|
|
|
tickets = Ticket.search(
|
|
|
|
:limit => params[:limit],
|
|
|
|
:query => params[:term],
|
|
|
|
:current_user => current_user,
|
|
|
|
)
|
2013-08-19 06:29:49 +00:00
|
|
|
assets = {}
|
2013-05-21 22:30:09 +00:00
|
|
|
ticket_result = []
|
|
|
|
tickets.each do |ticket|
|
2013-08-19 06:29:49 +00:00
|
|
|
assets = ticket.assets(assets)
|
2013-05-21 22:30:09 +00:00
|
|
|
ticket_result.push ticket.id
|
|
|
|
end
|
|
|
|
|
|
|
|
# do query
|
|
|
|
users = User.search(
|
2013-05-22 01:40:24 +00:00
|
|
|
:query => params[:term],
|
|
|
|
:limit => params[:limit],
|
2013-05-21 22:30:09 +00:00
|
|
|
:current_user => current_user,
|
|
|
|
)
|
|
|
|
user_result = []
|
|
|
|
users.each do |user|
|
|
|
|
user_result.push user.id
|
2013-08-19 06:29:49 +00:00
|
|
|
assets = user.assets(assets)
|
2013-05-21 22:30:09 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
organizations = Organization.search(
|
2013-05-22 01:40:24 +00:00
|
|
|
:query => params[:term],
|
|
|
|
:limit => params[:limit],
|
2013-05-21 22:30:09 +00:00
|
|
|
:current_user => current_user,
|
|
|
|
)
|
2013-05-22 01:40:24 +00:00
|
|
|
|
2013-05-21 22:30:09 +00:00
|
|
|
organization_result = []
|
|
|
|
organizations.each do |organization|
|
|
|
|
organization_result.push organization.id
|
2013-08-19 06:29:49 +00:00
|
|
|
assets = organization.assets(assets)
|
2013-05-21 22:30:09 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
result = []
|
|
|
|
if ticket_result[0]
|
|
|
|
data = {
|
|
|
|
:name => 'Ticket',
|
|
|
|
:ids => ticket_result,
|
|
|
|
}
|
|
|
|
result.push data
|
|
|
|
end
|
|
|
|
if user_result[0]
|
|
|
|
data = {
|
|
|
|
:name => 'User',
|
|
|
|
:ids => user_result,
|
|
|
|
}
|
|
|
|
result.push data
|
|
|
|
end
|
|
|
|
if organization_result[0]
|
|
|
|
data = {
|
|
|
|
:name => 'Organization',
|
|
|
|
:ids => organization_result,
|
|
|
|
}
|
|
|
|
result.push data
|
|
|
|
end
|
|
|
|
|
|
|
|
# return result
|
|
|
|
render :json => {
|
2013-08-19 10:20:26 +00:00
|
|
|
:assets => assets,
|
2013-05-21 22:30:09 +00:00
|
|
|
:result => result,
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|