2012-11-07 13:36:00 +00:00
|
|
|
class ApiSearchController < ApiController
|
|
|
|
|
|
|
|
|
|
# have to be signed in currently to see this screen
|
2015-08-02 07:31:58 +00:00
|
|
|
before_filter :api_signed_in_user, :except => :jam_tracks
|
2012-11-07 13:36:00 +00:00
|
|
|
|
|
|
|
|
respond_to :json
|
|
|
|
|
|
2023-01-04 16:11:57 +00:00
|
|
|
#include LatencyHelper
|
2021-08-26 17:23:24 +00:00
|
|
|
|
2012-11-07 13:36:00 +00:00
|
|
|
def index
|
2014-01-11 12:27:05 +00:00
|
|
|
if 1 == params[Search::PARAM_MUSICIAN].to_i || 1 == params[Search::PARAM_BAND].to_i
|
2015-09-22 01:01:39 +00:00
|
|
|
query = params.clone
|
2013-11-04 14:47:30 +00:00
|
|
|
query[:remote_ip] = request.remote_ip
|
2014-05-20 14:46:45 +00:00
|
|
|
if 1 == query[Search::PARAM_MUSICIAN].to_i
|
2014-09-22 19:20:58 +00:00
|
|
|
@search = Search.musician_filter(query, current_user)
|
2014-01-11 12:27:05 +00:00
|
|
|
else
|
|
|
|
|
@search = Search.band_filter(query, current_user)
|
|
|
|
|
end
|
2013-12-16 18:29:16 +00:00
|
|
|
respond_with @search, responder: ApiResponder, :status => 200
|
2014-02-16 07:15:24 +00:00
|
|
|
elsif 1 == params[Search::PARAM_SESSION_INVITE].to_i
|
|
|
|
|
@search = Search.session_invite_search(params[:query], current_user)
|
2013-11-04 14:47:30 +00:00
|
|
|
else
|
2014-01-11 12:27:05 +00:00
|
|
|
@search = Search.text_search(params, current_user)
|
2013-11-04 14:47:30 +00:00
|
|
|
end
|
2012-11-07 13:36:00 +00:00
|
|
|
end
|
2015-03-02 09:41:53 +00:00
|
|
|
|
|
|
|
|
def musicians
|
|
|
|
|
if request.get?
|
2015-04-04 14:55:41 +00:00
|
|
|
if params[:results]
|
|
|
|
|
@search = MusicianSearch.user_search_filter(current_user).search_results_page
|
|
|
|
|
respond_with @search, responder: ApiResponder, status: 201, template: 'api_search/index'
|
|
|
|
|
else
|
|
|
|
|
render :json => MusicianSearch.search_filter_json(current_user), :status => 200
|
|
|
|
|
end
|
2015-03-02 09:41:53 +00:00
|
|
|
|
|
|
|
|
elsif request.post?
|
2015-05-18 04:00:12 +00:00
|
|
|
sobj = MusicianSearch.user_search_filter(current_user)
|
2015-04-04 14:55:41 +00:00
|
|
|
filter = params[:filter]
|
|
|
|
|
if filter == 'reset'
|
2015-05-18 04:00:12 +00:00
|
|
|
@search = sobj.reset_search_results
|
2015-04-04 14:55:41 +00:00
|
|
|
else
|
|
|
|
|
json = JSON.parse(filter, :create_additions => false)
|
2015-05-18 04:00:12 +00:00
|
|
|
@search = sobj.search_results_page(json, [params[:page].to_i, 1].max)
|
|
|
|
|
end
|
|
|
|
|
respond_with @search, responder: ApiResponder, status: 201, template: 'api_search/index'
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def bands
|
|
|
|
|
if request.get?
|
|
|
|
|
if params[:results]
|
|
|
|
|
@search = BandSearch.user_search_filter(current_user).search_results_page(params[:subtype])
|
|
|
|
|
respond_with @search, responder: ApiResponder, status: 201, template: 'api_search/index'
|
|
|
|
|
else
|
|
|
|
|
render :json => BandSearch.search_filter_json(current_user, params[:subtype]), :status => 200
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
elsif request.post?
|
|
|
|
|
sobj = BandSearch.user_search_filter(current_user)
|
|
|
|
|
filter = params[:filter]
|
|
|
|
|
if filter == 'reset'
|
|
|
|
|
@search = sobj.reset_search_results(params[:subtype])
|
|
|
|
|
else
|
|
|
|
|
json = JSON.parse(filter, :create_additions => false)
|
2015-05-21 06:42:27 +00:00
|
|
|
@search = sobj.search_results_page(params[:subtype], json, [params[:page].to_i, 1].max)
|
2015-04-04 14:55:41 +00:00
|
|
|
end
|
2015-04-02 14:52:16 +00:00
|
|
|
respond_with @search, responder: ApiResponder, status: 201, template: 'api_search/index'
|
2015-03-02 09:41:53 +00:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2015-08-01 22:24:41 +00:00
|
|
|
def jam_tracks
|
|
|
|
|
if request.get?
|
2015-09-19 21:19:27 +00:00
|
|
|
if params[:iso639]
|
2017-05-25 01:44:08 +00:00
|
|
|
render(json: JamTrackSearch.all_languages.to_json, status: 200)
|
|
|
|
|
|
|
|
|
|
elsif params[:indexed]
|
|
|
|
|
fname = "#{Rails.root}/tmp/jtx_indices.json"
|
|
|
|
|
|
|
|
|
|
unless File.exists?(fname) && File.size(fname) > 0
|
|
|
|
|
SampleApp::Application.load_tasks
|
|
|
|
|
Rake::Task["mobile:jam_tracks_json"].invoke
|
|
|
|
|
end
|
2018-03-05 04:24:48 +00:00
|
|
|
json = JSON.parse(File.read(fname))
|
|
|
|
|
render(json: json, status: 200)
|
2017-05-25 01:44:08 +00:00
|
|
|
|
2015-09-19 21:19:27 +00:00
|
|
|
else
|
2018-03-05 04:24:48 +00:00
|
|
|
render(json: {})
|
2015-09-19 21:19:27 +00:00
|
|
|
end
|
2017-05-25 01:44:08 +00:00
|
|
|
|
2015-08-01 22:24:41 +00:00
|
|
|
elsif request.post?
|
2015-09-19 21:19:27 +00:00
|
|
|
jts = JamTrackSearch.new
|
|
|
|
|
filter = request.params[:api_search]
|
|
|
|
|
result = jts.search_results_page(filter)
|
2017-05-25 01:44:08 +00:00
|
|
|
render(json: result.to_json, status: 200)
|
2015-08-01 22:24:41 +00:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2023-01-04 16:11:57 +00:00
|
|
|
# def filter
|
2021-12-11 04:54:05 +00:00
|
|
|
|
2023-01-04 16:11:57 +00:00
|
|
|
# latency_good = ActiveRecord::Type::Boolean.new.type_cast_from_user(params[:latency_good])
|
|
|
|
|
# latency_fair = ActiveRecord::Type::Boolean.new.type_cast_from_user(params[:latency_fair])
|
|
|
|
|
# latency_high = ActiveRecord::Type::Boolean.new.type_cast_from_user(params[:latency_high])
|
|
|
|
|
# offset = [params[:offset].to_i, 0].max
|
|
|
|
|
# limit = [params[:limit].to_i, 20].max
|
|
|
|
|
# filter_params = {}
|
2021-08-09 14:18:10 +00:00
|
|
|
|
2023-01-04 16:11:57 +00:00
|
|
|
# filter_params.merge!(from_location: params[:from_location] ? '1' : '0')
|
2022-02-08 15:25:00 +00:00
|
|
|
|
2023-01-04 16:11:57 +00:00
|
|
|
# genres = params[:genres]
|
|
|
|
|
# filter_params.merge!(genres: genres) if genres
|
|
|
|
|
# # if genres && genres.any?
|
|
|
|
|
# # genres.map!{|genre| {id: genre} }
|
|
|
|
|
# # filter_params.merge!(genres: genres)
|
|
|
|
|
# # end
|
2022-02-08 15:25:00 +00:00
|
|
|
|
2023-01-04 16:11:57 +00:00
|
|
|
# beginner = ActiveRecord::Type::Boolean.new.type_cast_from_user(params[:proficiency_beginner])
|
|
|
|
|
# intermediate = ActiveRecord::Type::Boolean.new.type_cast_from_user(params[:proficiency_intermediate])
|
|
|
|
|
# expert = ActiveRecord::Type::Boolean.new.type_cast_from_user(params[:proficiency_expert])
|
|
|
|
|
|
|
|
|
|
# proficiency_levels = []
|
|
|
|
|
# proficiency_levels.push(1) if beginner
|
|
|
|
|
# proficiency_levels.push(2) if intermediate
|
|
|
|
|
# proficiency_levels.push(3) if expert
|
2022-02-08 15:25:00 +00:00
|
|
|
|
2023-01-04 16:11:57 +00:00
|
|
|
# instruments = params[:instruments]
|
2022-02-08 15:25:00 +00:00
|
|
|
|
2023-01-04 16:11:57 +00:00
|
|
|
# #debugger
|
2022-02-08 15:25:00 +00:00
|
|
|
|
2023-01-04 16:11:57 +00:00
|
|
|
# if instruments && instruments.any? && proficiency_levels.any?
|
|
|
|
|
# inst = []
|
|
|
|
|
# instruments.each do |ii|
|
|
|
|
|
# proficiency_levels.each do |pl|
|
|
|
|
|
# inst << { id: ii[:value], proficiency: pl}
|
|
|
|
|
# end
|
|
|
|
|
# end
|
|
|
|
|
# filter_params.merge!(instruments: inst)
|
|
|
|
|
# end
|
2022-02-08 15:25:00 +00:00
|
|
|
|
2023-01-04 16:11:57 +00:00
|
|
|
# filter_params.merge!(joined_within_days: params[:joined_within_days]) unless params[:joined_within_days].blank?
|
|
|
|
|
# filter_params.merge!(active_within_days: params[:active_within_days]) unless params[:active_within_days].blank?
|
2022-02-08 15:25:00 +00:00
|
|
|
|
2023-01-04 16:11:57 +00:00
|
|
|
# @latency_data = []
|
|
|
|
|
# begin
|
2022-02-08 15:25:00 +00:00
|
|
|
|
2023-01-04 16:11:57 +00:00
|
|
|
# #bm = Benchmark.measure do
|
|
|
|
|
# result = JamRuby::MusicianFilter.users_latency_data(current_user, request.remote_ip, latency_good, latency_fair, latency_high, filter_params, offset, limit)
|
|
|
|
|
# @latency_data = result[:data]
|
|
|
|
|
# @nextOffset = result[:next]
|
2022-03-18 13:57:48 +00:00
|
|
|
|
2023-01-04 16:11:57 +00:00
|
|
|
# user_ids = @latency_data.map{ |l_data| l_data[:user_id] }
|
|
|
|
|
# #end
|
2021-12-18 17:04:34 +00:00
|
|
|
|
2023-01-04 16:11:57 +00:00
|
|
|
# # Bugsnag.notify("search_users_benchmark") do |report|
|
|
|
|
|
# # report.severity = "info"
|
|
|
|
|
# # report.add_tab(:benchmark, benchmark: bm.to_s)
|
|
|
|
|
# # end if Rails.env.production?
|
|
|
|
|
|
|
|
|
|
# sobj = MusicianSearch.user_search_filter(current_user)
|
|
|
|
|
# #@search = sobj.search_results_page(filter_params, page, user_ids)
|
|
|
|
|
# debugger
|
|
|
|
|
# @search = sobj.user_search_results(user_ids)
|
2021-08-09 14:18:10 +00:00
|
|
|
|
2023-01-04 16:11:57 +00:00
|
|
|
# respond_with @search, responder: ApiResponder, status: 201, template: 'api_search/filter'
|
|
|
|
|
|
|
|
|
|
# rescue => exception
|
|
|
|
|
# logger.debug("Latency exception: #{exception.message}")
|
|
|
|
|
# Bugsnag.notify(exception) do |report|
|
|
|
|
|
# report.severity = "error"
|
|
|
|
|
# report.add_tab(:latency, {
|
|
|
|
|
# params: params,
|
|
|
|
|
# user_id: current_user.id,
|
|
|
|
|
# name: current_user.name,
|
|
|
|
|
# url: filter_latency_url,
|
|
|
|
|
# })
|
|
|
|
|
# end
|
|
|
|
|
# render json: {}, status: 500
|
|
|
|
|
# end
|
|
|
|
|
|
|
|
|
|
# end
|
2021-08-09 14:18:10 +00:00
|
|
|
|
2023-01-04 16:11:57 +00:00
|
|
|
def filter
|
|
|
|
|
begin
|
|
|
|
|
@search, @latency_data, @nextOffset = JamRuby::MusicianFilter.filter(current_user, request.remote_ip, params)
|
|
|
|
|
respond_with @search, responder: ApiResponder, status: 201, template: 'api_search/filter'
|
2023-12-14 06:04:42 +00:00
|
|
|
rescue => ex
|
2024-10-22 02:58:56 +00:00
|
|
|
Rails.logger.debug("EXCEPTION : #{ex.message}")
|
2021-12-13 14:16:07 +00:00
|
|
|
render json: {}, status: 500
|
2023-01-04 16:11:57 +00:00
|
|
|
end
|
2021-08-09 14:18:10 +00:00
|
|
|
end
|
|
|
|
|
|
2012-11-07 13:36:00 +00:00
|
|
|
end
|