get score from Search.musician_filter into json sent to client

This commit is contained in:
Scott Comer 2014-05-29 13:03:33 -05:00
parent ebfe72e11d
commit 3b3776f065
4 changed files with 21 additions and 10 deletions

View File

@ -123,16 +123,16 @@ module JamRuby
# produce a list of musicians (users where musician is true)
# params:
# instrument - instrument to search for or blank
# score_limit - score must be <= this to be included in the result
# score_limit - score must be <= this to be included in the result (this is a test against the raw score)
# handled by relation_pagination:
# page - page number to fetch (origin 1)
# per_page - number of entries per page
# handled by order_param:
# orderby - ??? (followed, plays, playing)
# handled by where_latlng:
# distance - defunct
# city - defunct
# remote_ip - defunct
# orderby - what sort of search, also defines order (followed, plays, playing)
# previously handled by where_latlng:
# distance - defunct!
# city - defunct!
# remote_ip - defunct!
def self.musician_filter(params={}, user=nil, conn=nil)
# puts "================ params #{params.inspect}"
# puts "================ user #{user.inspect}"
@ -178,10 +178,10 @@ module JamRuby
case ordering
when :plays # FIXME: double counting?
# sel_str = "COUNT(records)+COUNT(sessions) AS play_count, #{sel_str}"
rel = rel.select('COUNT(records.id)+COUNT(sessions.id) AS play_count')
rel = rel.select('COUNT(records.id)+COUNT(sessions.id) AS search_play_count')
rel = rel.joins("LEFT JOIN music_sessions AS sessions ON sessions.user_id = users.id")
rel = rel.joins("LEFT JOIN recordings AS records ON records.owner_id = users.id")
rel = rel.order("play_count DESC")
rel = rel.order("search_play_count DESC")
when :followed
rel = rel.joins('left outer join follows on follows.followable_id = users.id')
rel = rel.select('count(follows.user_id) as search_follow_count')
@ -201,9 +201,13 @@ module JamRuby
rel, page = self.relation_pagination(rel, params)
rel = rel.includes([:instruments, :followings, :friends])
# puts "======================== sql #{rel.to_sql}"
objs = rel.all
# puts "======================== objs #{objs.inspect}"
# if objs.length > 0
# puts "======================== attributes #{objs[0].attributes}"
# puts "======================== score #{objs[0].score}"
# end
srch = Search.new
srch.search_type = :musicians_filter

View File

@ -290,6 +290,11 @@ module JamRuby
self.music_sessions.size
end
def joined_score
nil unless has_attribute?(:score)
read_attribute(:score).to_i
end
# mods comes back as text; so give ourselves a parsed version
def mods_json
@mods_json ||= mods ? JSON.parse(mods, symbolize_names: true) : {}

View File

@ -43,7 +43,7 @@ if @search.musicians_filter_search?
end
child(:results => :musicians) {
attributes :id, :first_name, :last_name, :name, :city, :state, :country, :email, :online, :musician, :photo_url, :biography
attributes :id, :first_name, :last_name, :name, :city, :state, :country, :email, :online, :musician, :photo_url, :biography, :joined_score
node :is_friend do |musician|
@search.is_friend?(musician)

View File

@ -45,6 +45,8 @@ describe "Musician Search API", :type => :api do
get_query
good_response
expect(json['musicians'].count).to be [Search::M_PER_PAGE, User.musicians_geocoded.count].min
puts json.inspect
end
context 'score filtering' do