object @search

node :search_type do |ss| ss.search_type end

if @search.is_a?(MusicianSearch)

  node :page_count do |foo|
    @search.page_count
  end

  node :my_audio_latency do |user|
    current_user.last_jam_audio_latency.round if current_user.last_jam_audio_latency
  end
                  
  node :is_blank_filter do |foo|
    @search.is_blank?
  end
         
  node :filter_json do |foo|
    @search.to_json
  end
         
  child(:results => :musicians) {
      attributes :id, :first_name, :last_name, :name, :city, :state, :country, :online, :musician, :photo_url, :biography, :regionname, :score, :full_score

      node :is_friend do |musician|
        @search.is_friend?(musician)
      end

      node :is_following do |musician|
        @search.is_follower?(musician)
      end

      node :pending_friend_request do |musician|
        musician.pending_friend_request?(current_user)
      end

      node :biography do |musician|
        musician.biography.nil? ? "" : musician.biography
      end

      child :musician_instruments => :instruments do
        attributes :instrument_id, :description, :proficiency_level, :priority
      end
      
      child :top_followings => :followings do |uf|
        node :user_id do |uu| uu.id end
        node :photo_url do |uu| uu.photo_url end
        node :name do |uu| uu.name end
      end

      node :follow_count do |musician| @search.follow_count(musician) end
      node :friend_count do |musician| @search.friend_count(musician) end
      node :recording_count do |musician| @search.record_count(musician) end
      node :session_count do |musician| @search.session_count(musician) end

      node :audio_latency do |musician|
        last_jam_audio_latency(musician)
      end
  }
else

if @search.session_invite_search?
  child(:results => :suggestions) {
    node :value do |uu| uu.name end
    node :data do |uu| uu.id end
  }
end

if @search.bands_text_search?
  child(:results => :bands) {
      attributes :id, :name, :location, :photo_url, :logo_url, :website
  }
end

if @search.musicians_text_search?
  child(:results => :musicians) {
      attributes :id, :first_name, :last_name, :name, :location, :photo_url

      node :is_friend do |musician|
        musician.friends?(current_user)
      end

      node :pending_friend_request do |musician|
        musician.pending_friend_request?(current_user)
      end

      child :musician_instruments => :instruments do
        attributes :instrument_id, :description, :proficiency_level, :priority
      end
  }
end

if @search.musicians_filter_search?

  node :page_count do |foo|
    @search.page_count
  end

  node :my_audio_latency do |user|
    current_user.last_jam_audio_latency.round if current_user.last_jam_audio_latency
  end
         
  node :is_blank_filter do |foo|
    @search.is_blank?
  end
         
  node :filter_json do |foo|
    @search.to_json
  end
         
  child(:results => :musicians) {
      attributes :id, :first_name, :last_name, :name, :city, :state, :country, :online, :musician, :photo_url, :biography, :regionname, :score, :full_score

      node :is_friend do |musician|
        @search.is_friend?(musician)
      end

      node :is_following do |musician|
        @search.is_follower?(musician)
      end

      node :pending_friend_request do |musician|
        musician.pending_friend_request?(current_user)
      end

      node :biography do |musician|
        musician.biography.nil? ? "" : musician.biography
      end

      child :musician_instruments => :instruments do
        attributes :instrument_id, :description, :proficiency_level, :priority
      end
      
      child :top_followings => :followings do |uf|
        node :user_id do |uu| uu.id end
        node :photo_url do |uu| uu.photo_url end
        node :name do |uu| uu.name end
      end

      node :follow_count do |musician| @search.follow_count(musician) end
      node :friend_count do |musician| @search.friend_count(musician) end
      node :recording_count do |musician| @search.record_count(musician) end
      node :session_count do |musician| @search.session_count(musician) end

      node :audio_latency do |musician|
        last_jam_audio_latency(musician)
      end
  }
end

if @search.bands_filter_search?
  
  node :page_count do |foo|
    @search.page_count
  end
         
  child(:results => :bands) {
      attributes :id, :name, :city, :state, :country, :photo_url, :biography, :logo_url, :website

      node :is_following do |band|
        @search.is_follower?(band)
      end

      node :biography do |band|
        band.biography.nil? ? "" : band.biography
      end

      child :genres => :genres do
        attributes :genre_id, :description
      end

      child :users => :players do |pl|
        node :user_id do |uu| uu.id end
        node :photo_url do |uu| uu.photo_url end
        node :name do |uu| uu.name end
        node :instruments do |uu| uu.instruments.map(&:id).join(',') end
      end

      node :follow_count do |band| @search.follow_count(band) end
      node :recording_count do |band| @search.record_count(band) end
      node :session_count do |band| @search.session_count(band) end
  }
end

if @search.fans_text_search?
  child(:results => :fans) {
      attributes :id, :first_name, :last_name, :name, :location, :photo_url

      node :is_friend do |fan|
        fan.friends?(current_user)
      end

      node :pending_friend_request do |fan|
        fan.pending_friend_request?(current_user)
      end
  }
end

end
