2012-11-08 01:13:35 +00:00
|
|
|
module JamRuby
|
2014-01-11 14:59:09 +00:00
|
|
|
|
2014-01-11 12:26:40 +00:00
|
|
|
# not a active_record model; just a search result container
|
2012-11-08 01:13:35 +00:00
|
|
|
class Search
|
2014-01-11 15:27:56 +00:00
|
|
|
attr_accessor :results, :search_type
|
2014-01-11 14:59:09 +00:00
|
|
|
attr_accessor :user_counters, :page_num, :page_count
|
|
|
|
|
|
2013-01-14 04:50:38 +00:00
|
|
|
LIMIT = 10
|
2013-10-28 14:22:06 +00:00
|
|
|
|
2014-01-11 12:26:40 +00:00
|
|
|
SEARCH_TEXT_TYPES = [:musicians, :bands, :fans]
|
|
|
|
|
SEARCH_TEXT_TYPE_ID = :search_text_type
|
2012-11-08 01:13:35 +00:00
|
|
|
|
2014-01-11 12:26:40 +00:00
|
|
|
def self.band_search(txt, user = nil)
|
|
|
|
|
self.text_search({ SEARCH_TEXT_TYPE_ID => :bands, :query => txt }, user)
|
|
|
|
|
end
|
2012-11-08 01:13:35 +00:00
|
|
|
|
2014-01-11 12:26:40 +00:00
|
|
|
def self.fan_search(txt, user = nil)
|
|
|
|
|
self.text_search({ SEARCH_TEXT_TYPE_ID => :fans, :query => txt }, user)
|
|
|
|
|
end
|
2013-06-22 23:35:42 +00:00
|
|
|
|
2014-01-11 12:50:51 +00:00
|
|
|
def self.musician_search(txt, user = nil)
|
2014-01-11 12:26:40 +00:00
|
|
|
self.text_search({ SEARCH_TEXT_TYPE_ID => :musicians, :query => txt }, user)
|
2013-01-21 05:51:31 +00:00
|
|
|
end
|
|
|
|
|
|
2014-01-11 12:26:40 +00:00
|
|
|
def self.text_search(params, user = nil)
|
2014-01-11 14:59:09 +00:00
|
|
|
srch = Search.new
|
|
|
|
|
unless (params.blank? || params[:query].blank? || 2 > params[:query].length)
|
|
|
|
|
srch.text_search(params, user)
|
|
|
|
|
end
|
|
|
|
|
srch
|
|
|
|
|
end
|
2014-01-11 12:26:40 +00:00
|
|
|
|
2014-01-11 14:59:09 +00:00
|
|
|
def text_search(params, user = nil)
|
2014-01-11 12:26:40 +00:00
|
|
|
tsquery = Search.create_tsquery(params[:query])
|
|
|
|
|
return [] if tsquery.blank?
|
|
|
|
|
|
2014-01-11 12:50:51 +00:00
|
|
|
rel = case params[SEARCH_TEXT_TYPE_ID].to_s
|
2014-01-11 12:26:40 +00:00
|
|
|
when 'bands'
|
2014-01-11 14:59:09 +00:00
|
|
|
@search_type = :bands
|
|
|
|
|
Band.scoped
|
2014-01-11 12:26:40 +00:00
|
|
|
when 'fans'
|
2014-01-11 14:59:09 +00:00
|
|
|
@search_type = :fans
|
|
|
|
|
User.fans
|
2014-01-11 12:26:40 +00:00
|
|
|
else
|
2014-01-11 14:59:09 +00:00
|
|
|
@search_type = :musicians
|
|
|
|
|
User.musicians
|
2014-01-11 12:26:40 +00:00
|
|
|
end
|
2014-01-11 15:27:56 +00:00
|
|
|
@results = rel.where("(name_tsv @@ to_tsquery('jamenglish', ?))", tsquery).limit(10)
|
2014-01-12 05:34:23 +00:00
|
|
|
@results
|
2014-01-11 12:26:40 +00:00
|
|
|
end
|
2013-06-22 23:35:42 +00:00
|
|
|
|
2013-11-05 14:49:31 +00:00
|
|
|
def initialize(search_results=nil)
|
2014-01-11 15:27:56 +00:00
|
|
|
@results = []
|
2014-01-11 12:26:40 +00:00
|
|
|
self
|
2012-11-08 01:13:35 +00:00
|
|
|
end
|
2013-01-14 04:50:38 +00:00
|
|
|
|
|
|
|
|
def self.create_tsquery(query)
|
2014-01-11 15:27:56 +00:00
|
|
|
return nil if query.blank?
|
2013-01-14 04:50:38 +00:00
|
|
|
|
|
|
|
|
search_terms = query.split
|
2014-01-11 12:26:40 +00:00
|
|
|
return nil if search_terms.length == 0
|
2013-01-14 04:50:38 +00:00
|
|
|
|
|
|
|
|
args = nil
|
|
|
|
|
search_terms.each do |search_term|
|
|
|
|
|
if args == nil
|
|
|
|
|
args = search_term
|
|
|
|
|
else
|
|
|
|
|
args = args + " & " + search_term
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
args = args + ":*"
|
2014-01-11 12:26:40 +00:00
|
|
|
args
|
2013-01-14 04:50:38 +00:00
|
|
|
end
|
|
|
|
|
|
2013-11-23 12:16:40 +00:00
|
|
|
PARAM_MUSICIAN = :srch_m
|
2013-11-30 00:34:00 +00:00
|
|
|
PARAM_BAND = :srch_b
|
2014-01-22 02:56:35 +00:00
|
|
|
PARAM_FEED = :srch_f
|
2013-11-06 13:50:34 +00:00
|
|
|
|
2014-01-22 02:56:35 +00:00
|
|
|
F_PER_PAGE = B_PER_PAGE = M_PER_PAGE = 10
|
2013-11-23 12:16:40 +00:00
|
|
|
M_MILES_DEFAULT = 500
|
2013-11-30 00:34:00 +00:00
|
|
|
B_MILES_DEFAULT = 0
|
2013-11-06 13:50:34 +00:00
|
|
|
|
|
|
|
|
M_ORDER_FOLLOWS = ['Most Followed', :followed]
|
|
|
|
|
M_ORDER_PLAYS = ['Most Plays', :plays]
|
|
|
|
|
M_ORDER_PLAYING = ['Playing Now', :playing]
|
2013-12-09 13:15:59 +00:00
|
|
|
ORDERINGS = B_ORDERINGS = M_ORDERINGS = [M_ORDER_FOLLOWS, M_ORDER_PLAYS, M_ORDER_PLAYING]
|
2013-11-30 00:34:00 +00:00
|
|
|
B_ORDERING_KEYS = M_ORDERING_KEYS = M_ORDERINGS.collect { |oo| oo[1] }
|
|
|
|
|
|
2013-12-09 13:15:59 +00:00
|
|
|
DISTANCE_OPTS = B_DISTANCE_OPTS = M_DISTANCE_OPTS = [['Any', 0], [1000.to_s, 1000], [500.to_s, 500], [250.to_s, 250], [100.to_s, 100], [50.to_s, 50], [25.to_s, 25]]
|
2013-11-06 13:50:34 +00:00
|
|
|
|
2014-01-22 02:56:35 +00:00
|
|
|
F_SORT_RECENT = ['Most Recent', :recent]
|
|
|
|
|
F_SORT_OLDEST = ['Ending Soonest', :ending_soon]
|
|
|
|
|
F_SORT_LENGTH = ['Session Length', :session_length]
|
|
|
|
|
F_SORT_OPTS = [F_SORT_RECENT, F_SORT_LENGTH, F_SORT_OLDEST]
|
|
|
|
|
|
|
|
|
|
SHOW_BOTH = ['Both', :both]
|
|
|
|
|
SHOW_SESSIONS = ['Sessions', :sessions]
|
|
|
|
|
SHOW_RECORDINGS = ['Recordings', :recordings]
|
|
|
|
|
SHOW_OPTS = [SHOW_BOTH, SHOW_SESSIONS, SHOW_RECORDINGS]
|
|
|
|
|
|
|
|
|
|
DATE_OPTS = [['Today', 0], ['This week', 7], ['Past 2 weeks', 14], ['This month', 30], ['Past year', 365], ['All', -1]]
|
|
|
|
|
|
2013-12-09 13:15:59 +00:00
|
|
|
def self.order_param(params, keys=M_ORDERING_KEYS)
|
2013-11-06 13:50:34 +00:00
|
|
|
ordering = params[:orderby]
|
2013-12-09 13:15:59 +00:00
|
|
|
ordering.blank? ? keys[0] : keys.detect { |oo| oo.to_s == ordering }
|
2013-11-06 13:50:34 +00:00
|
|
|
end
|
|
|
|
|
|
2014-01-11 12:26:40 +00:00
|
|
|
def self.musician_filter(params={}, current_user=nil)
|
2013-11-25 21:56:54 +00:00
|
|
|
rel = User.musicians
|
2013-11-06 13:50:34 +00:00
|
|
|
unless (instrument = params[:instrument]).blank?
|
|
|
|
|
rel = rel.joins("RIGHT JOIN musicians_instruments AS minst ON minst.user_id = users.id")
|
|
|
|
|
.where(['minst.instrument_id = ? AND users.id IS NOT NULL', instrument])
|
|
|
|
|
end
|
|
|
|
|
|
2013-12-09 13:15:59 +00:00
|
|
|
rel = MaxMindGeo.where_latlng(rel, params, current_user)
|
2013-11-28 04:32:13 +00:00
|
|
|
|
2013-11-06 13:50:34 +00:00
|
|
|
sel_str = 'users.*'
|
2013-12-09 13:15:59 +00:00
|
|
|
case ordering = self.order_param(params)
|
2013-11-25 21:56:54 +00:00
|
|
|
when :plays # FIXME: double counting?
|
2013-11-15 22:35:55 +00:00
|
|
|
sel_str = "COUNT(records)+COUNT(sessions) AS play_count, #{sel_str}"
|
|
|
|
|
rel = rel.joins("LEFT JOIN music_sessions AS sessions ON sessions.user_id = users.id")
|
2013-11-28 04:32:13 +00:00
|
|
|
.joins("LEFT JOIN recordings AS records ON records.owner_id = users.id")
|
|
|
|
|
.group("users.id")
|
|
|
|
|
.order("play_count DESC, users.created_at DESC")
|
2013-11-06 13:50:34 +00:00
|
|
|
when :followed
|
|
|
|
|
sel_str = "COUNT(follows) AS search_follow_count, #{sel_str}"
|
|
|
|
|
rel = rel.joins("LEFT JOIN users_followers AS follows ON follows.user_id = users.id")
|
2013-11-28 04:32:13 +00:00
|
|
|
.group("users.id")
|
|
|
|
|
.order("COUNT(follows) DESC, users.created_at DESC")
|
2013-11-06 13:50:34 +00:00
|
|
|
when :playing
|
2013-11-15 22:35:55 +00:00
|
|
|
rel = rel.joins("LEFT JOIN connections ON connections.user_id = users.id")
|
2013-11-28 04:32:13 +00:00
|
|
|
.where(['connections.music_session_id IS NOT NULL AND connections.aasm_state != ?',
|
2013-11-15 22:35:55 +00:00
|
|
|
'expired'])
|
|
|
|
|
.order("users.created_at DESC")
|
2013-11-06 13:50:34 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
rel = rel.select(sel_str)
|
2013-12-09 17:41:35 +00:00
|
|
|
rel, page = self.relation_pagination(rel, params)
|
2013-11-28 04:32:13 +00:00
|
|
|
rel = rel.includes([:instruments, :followings, :friends])
|
2013-11-06 13:50:34 +00:00
|
|
|
|
2013-11-28 04:32:13 +00:00
|
|
|
objs = rel.all
|
2013-11-06 13:50:34 +00:00
|
|
|
srch = Search.new
|
2014-01-12 07:48:15 +00:00
|
|
|
srch.search_type = :musicians_filter
|
2013-11-28 04:32:13 +00:00
|
|
|
srch.page_num, srch.page_count = page, objs.total_pages
|
|
|
|
|
srch.musician_results_for_user(objs, current_user)
|
2013-11-06 13:50:34 +00:00
|
|
|
end
|
|
|
|
|
|
2013-12-09 17:41:35 +00:00
|
|
|
def self.relation_pagination(rel, params)
|
|
|
|
|
perpage = [(params[:per_page] || M_PER_PAGE).to_i, 100].min
|
|
|
|
|
page = [params[:page].to_i, 1].max
|
|
|
|
|
[rel.paginate(:page => page, :per_page => perpage), page]
|
|
|
|
|
end
|
|
|
|
|
|
2013-11-05 14:49:31 +00:00
|
|
|
RESULT_FOLLOW = :follows
|
|
|
|
|
RESULT_FRIEND = :friends
|
|
|
|
|
|
2013-11-06 13:50:34 +00:00
|
|
|
COUNT_FRIEND = :count_friend
|
|
|
|
|
COUNT_FOLLOW = :count_follow
|
|
|
|
|
COUNT_RECORD = :count_record
|
|
|
|
|
COUNT_SESSION = :count_session
|
|
|
|
|
COUNTERS = [COUNT_FRIEND, COUNT_FOLLOW, COUNT_RECORD, COUNT_SESSION]
|
|
|
|
|
|
2014-01-11 15:27:56 +00:00
|
|
|
def musician_results_for_user(_results, user)
|
|
|
|
|
@results = _results
|
2013-11-05 14:49:31 +00:00
|
|
|
if user
|
2014-01-11 15:27:56 +00:00
|
|
|
@user_counters = @results.inject({}) { |hh,val| hh[val.id] = []; hh }
|
|
|
|
|
mids = "'#{@results.map(&:id).join("','")}'"
|
2013-11-28 04:32:13 +00:00
|
|
|
|
|
|
|
|
# this gets counts for each search result on friends/follows/records/sessions
|
2014-01-11 15:27:56 +00:00
|
|
|
@results.each do |uu|
|
2013-11-06 13:50:34 +00:00
|
|
|
counters = { }
|
|
|
|
|
counters[COUNT_FRIEND] = Friendship.where(:user_id => uu.id).count
|
|
|
|
|
counters[COUNT_FOLLOW] = UserFollowing.where(:user_id => uu.id).count
|
2013-11-14 17:56:20 +00:00
|
|
|
counters[COUNT_RECORD] = ClaimedRecording.where(:user_id => uu.id).count
|
2013-11-06 13:50:34 +00:00
|
|
|
counters[COUNT_SESSION] = MusicSession.where(:user_id => uu.id).count
|
|
|
|
|
@user_counters[uu.id] << counters
|
|
|
|
|
end
|
2013-11-05 14:49:31 +00:00
|
|
|
|
2013-11-28 04:32:13 +00:00
|
|
|
# this section determines follow/like/friend status for each search result
|
|
|
|
|
# so that action links can be activated or not
|
2013-11-05 15:07:02 +00:00
|
|
|
rel = User.select("users.id AS uid")
|
2013-11-05 14:49:31 +00:00
|
|
|
rel = rel.joins("LEFT JOIN users_followers AS follows ON follows.follower_id = '#{user.id}'")
|
|
|
|
|
rel = rel.where(["users.id IN (#{mids}) AND follows.user_id = users.id"])
|
2013-11-06 13:50:34 +00:00
|
|
|
rel.all.each { |val| @user_counters[val.uid] << RESULT_FOLLOW }
|
2013-11-05 14:49:31 +00:00
|
|
|
|
2013-11-05 15:07:02 +00:00
|
|
|
rel = User.select("users.id AS uid")
|
2013-11-05 14:49:31 +00:00
|
|
|
rel = rel.joins("LEFT JOIN friendships AS friends ON friends.friend_id = '#{user.id}'")
|
|
|
|
|
rel = rel.where(["users.id IN (#{mids}) AND friends.user_id = users.id"])
|
2013-11-06 13:50:34 +00:00
|
|
|
rel.all.each { |val| @user_counters[val.uid] << RESULT_FRIEND }
|
2013-11-06 10:16:47 +00:00
|
|
|
|
2013-11-05 14:49:31 +00:00
|
|
|
else
|
2013-11-06 13:50:34 +00:00
|
|
|
@user_counters = {}
|
2013-11-05 14:49:31 +00:00
|
|
|
end
|
|
|
|
|
self
|
|
|
|
|
end
|
|
|
|
|
|
2013-11-25 21:56:54 +00:00
|
|
|
private
|
|
|
|
|
|
2013-11-06 13:50:34 +00:00
|
|
|
def _count(musician, key)
|
|
|
|
|
if mm = @user_counters[musician.id]
|
|
|
|
|
return mm.detect { |ii| ii.is_a?(Hash) }[key]
|
2013-11-15 19:52:53 +00:00
|
|
|
end if @user_counters
|
2013-11-06 13:50:34 +00:00
|
|
|
0
|
|
|
|
|
end
|
|
|
|
|
|
2013-11-25 21:56:54 +00:00
|
|
|
public
|
|
|
|
|
|
2014-01-11 15:12:26 +00:00
|
|
|
def musicians_text_search?
|
2014-01-11 14:59:09 +00:00
|
|
|
:musicians == @search_type
|
|
|
|
|
end
|
|
|
|
|
|
2014-01-11 15:12:26 +00:00
|
|
|
def fans_text_search?
|
2014-01-11 14:59:09 +00:00
|
|
|
:fans == @search_type
|
|
|
|
|
end
|
|
|
|
|
|
2014-01-11 15:12:26 +00:00
|
|
|
def bands_text_search?
|
2014-01-11 14:59:09 +00:00
|
|
|
:bands == @search_type
|
|
|
|
|
end
|
|
|
|
|
|
2014-01-11 15:12:26 +00:00
|
|
|
def musicians_filter_search?
|
|
|
|
|
:musicians_filter == @search_type
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def bands_filter_search?
|
|
|
|
|
:band_filter == @search_type
|
2014-01-11 14:59:09 +00:00
|
|
|
end
|
|
|
|
|
|
2013-11-06 13:50:34 +00:00
|
|
|
def follow_count(musician)
|
|
|
|
|
_count(musician, COUNT_FOLLOW)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def friend_count(musician)
|
|
|
|
|
_count(musician, COUNT_FRIEND)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def record_count(musician)
|
|
|
|
|
_count(musician, COUNT_RECORD)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def session_count(musician)
|
|
|
|
|
_count(musician, COUNT_SESSION)
|
|
|
|
|
end
|
|
|
|
|
|
2013-11-05 14:49:31 +00:00
|
|
|
def is_friend?(musician)
|
2013-11-06 13:50:34 +00:00
|
|
|
if mm = @user_counters[musician.id]
|
2013-11-05 14:49:31 +00:00
|
|
|
return mm.include?(RESULT_FRIEND)
|
2013-11-15 19:52:53 +00:00
|
|
|
end if @user_counters
|
2013-11-05 14:49:31 +00:00
|
|
|
false
|
|
|
|
|
end
|
|
|
|
|
def is_follower?(musician)
|
2013-11-06 13:50:34 +00:00
|
|
|
if mm = @user_counters[musician.id]
|
2013-11-05 14:49:31 +00:00
|
|
|
return mm.include?(RESULT_FOLLOW)
|
2013-11-15 19:52:53 +00:00
|
|
|
end if @user_counters
|
2013-11-05 14:49:31 +00:00
|
|
|
false
|
|
|
|
|
end
|
|
|
|
|
|
2013-11-26 06:03:42 +00:00
|
|
|
def self.new_musicians(usr, since_date=Time.now - 1.week, max_count=50, radius=M_MILES_DEFAULT)
|
|
|
|
|
rel = User.musicians
|
|
|
|
|
.where(['created_at >= ? AND users.id != ?', since_date, usr.id])
|
|
|
|
|
.within(radius, :origin => [usr.lat, usr.lng])
|
|
|
|
|
.order('created_at DESC')
|
|
|
|
|
.limit(max_count)
|
2013-11-26 09:08:22 +00:00
|
|
|
objs = rel.all.to_a
|
2013-11-26 14:40:06 +00:00
|
|
|
if block_given?
|
|
|
|
|
yield(objs) if 0 < objs.count
|
|
|
|
|
else
|
|
|
|
|
return objs
|
|
|
|
|
end
|
2013-11-17 23:29:23 +00:00
|
|
|
end
|
|
|
|
|
|
2014-01-11 12:26:40 +00:00
|
|
|
def self.band_filter(params={}, current_user=nil)
|
2013-12-09 13:15:59 +00:00
|
|
|
rel = Band.scoped
|
|
|
|
|
|
|
|
|
|
unless (genre = params[:genre]).blank?
|
2013-12-09 17:41:35 +00:00
|
|
|
rel = Band.joins("RIGHT JOIN bands_genres AS bgenres ON bgenres.band_id = bands.id")
|
2013-12-09 13:15:59 +00:00
|
|
|
.where(['bgenres.genre_id = ? AND bands.id IS NOT NULL', genre])
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
rel = MaxMindGeo.where_latlng(rel, params, current_user)
|
|
|
|
|
|
|
|
|
|
sel_str = 'bands.*'
|
|
|
|
|
case ordering = self.order_param(params)
|
|
|
|
|
when :plays # FIXME: double counting?
|
|
|
|
|
sel_str = "COUNT(records)+COUNT(sessions) AS play_count, #{sel_str}"
|
2013-12-09 17:41:35 +00:00
|
|
|
rel = rel.joins("LEFT JOIN music_sessions AS sessions ON sessions.band_id = bands.id")
|
|
|
|
|
.joins("LEFT JOIN recordings AS records ON records.band_id = bands.id")
|
|
|
|
|
.group("bands.id")
|
|
|
|
|
.order("play_count DESC, bands.created_at DESC")
|
2013-12-09 13:15:59 +00:00
|
|
|
when :followed
|
|
|
|
|
sel_str = "COUNT(follows) AS search_follow_count, #{sel_str}"
|
|
|
|
|
rel = rel.joins("LEFT JOIN bands_followers AS follows ON follows.band_id = bands.id")
|
|
|
|
|
.group("bands.id")
|
|
|
|
|
.order("COUNT(follows) DESC, bands.created_at DESC")
|
|
|
|
|
when :playing
|
2013-12-09 17:41:35 +00:00
|
|
|
rel = rel.joins("LEFT JOIN music_sessions_history AS msh ON msh.band_id = bands.id")
|
|
|
|
|
.where('msh.music_session_id IS NOT NULL AND msh.session_removed_at IS NULL')
|
|
|
|
|
.order("bands.created_at DESC")
|
2013-12-09 13:15:59 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
rel = rel.select(sel_str)
|
2013-12-09 17:41:35 +00:00
|
|
|
rel, page = self.relation_pagination(rel, params)
|
2013-12-16 18:23:02 +00:00
|
|
|
rel = rel.includes([{ :users => :instruments }, :genres ])
|
2013-12-09 13:15:59 +00:00
|
|
|
|
|
|
|
|
objs = rel.all
|
|
|
|
|
srch = Search.new
|
2014-01-12 07:48:15 +00:00
|
|
|
srch.search_type = :band_filter
|
2013-12-09 13:15:59 +00:00
|
|
|
srch.page_num, srch.page_count = page, objs.total_pages
|
|
|
|
|
srch.band_results_for_user(objs, current_user)
|
|
|
|
|
end
|
|
|
|
|
|
2014-01-11 15:27:56 +00:00
|
|
|
def band_results_for_user(_results, user)
|
|
|
|
|
@results = _results
|
2013-12-09 13:15:59 +00:00
|
|
|
if user
|
2014-01-11 15:27:56 +00:00
|
|
|
@user_counters = @results.inject({}) { |hh,val| hh[val.id] = []; hh }
|
|
|
|
|
mids = "'#{@results.map(&:id).join("','")}'"
|
2013-12-09 13:15:59 +00:00
|
|
|
|
|
|
|
|
# this gets counts for each search result
|
2014-01-11 15:27:56 +00:00
|
|
|
@results.each do |bb|
|
2013-12-09 13:15:59 +00:00
|
|
|
counters = { }
|
|
|
|
|
counters[COUNT_FOLLOW] = BandFollowing.where(:band_id => bb.id).count
|
2013-12-09 17:41:35 +00:00
|
|
|
counters[COUNT_RECORD] = Recording.where(:band_id => bb.id).count
|
|
|
|
|
counters[COUNT_SESSION] = MusicSession.where(:band_id => bb.id).count
|
2013-12-09 13:15:59 +00:00
|
|
|
@user_counters[bb.id] << counters
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# this section determines follow/like/friend status for each search result
|
|
|
|
|
# so that action links can be activated or not
|
|
|
|
|
|
|
|
|
|
rel = Band.select("bands.id AS bid")
|
|
|
|
|
rel = rel.joins("LEFT JOIN bands_followers AS follows ON follows.follower_id = '#{user.id}'")
|
|
|
|
|
rel = rel.where(["bands.id IN (#{mids}) AND follows.band_id = bands.id"])
|
|
|
|
|
rel.all.each { |val| @user_counters[val.bid] << RESULT_FOLLOW }
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
@user_counters = {}
|
|
|
|
|
end
|
|
|
|
|
self
|
|
|
|
|
end
|
|
|
|
|
|
2012-11-08 01:13:35 +00:00
|
|
|
end
|
2013-04-25 06:50:52 +00:00
|
|
|
end
|