diff --git a/ruby/lib/jam_ruby/models/search.rb b/ruby/lib/jam_ruby/models/search.rb index b9745984a..5ec766695 100644 --- a/ruby/lib/jam_ruby/models/search.rb +++ b/ruby/lib/jam_ruby/models/search.rb @@ -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 diff --git a/ruby/lib/jam_ruby/models/user.rb b/ruby/lib/jam_ruby/models/user.rb index 0ed32cc68..59b34c405 100644 --- a/ruby/lib/jam_ruby/models/user.rb +++ b/ruby/lib/jam_ruby/models/user.rb @@ -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) : {} diff --git a/web/app/views/api_search/index.rabl b/web/app/views/api_search/index.rabl index 16c1f85fc..fd53ba9c2 100644 --- a/web/app/views/api_search/index.rabl +++ b/web/app/views/api_search/index.rabl @@ -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) diff --git a/web/spec/requests/musician_search_api_spec.rb b/web/spec/requests/musician_search_api_spec.rb index 975712b0b..88b0eec3d 100644 --- a/web/spec/requests/musician_search_api_spec.rb +++ b/web/spec/requests/musician_search_api_spec.rb @@ -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