class SearchController < ApplicationController
   def index
   end
   
   def new
   end
 
   def do_search
   
     @search_type = params[:search_type]
     if (@search_type == "author")
     	@search_type = "author"
     elsif (@search_type == "title")
     	@search_type = "audio_file_name"
     else
     	@search_type = "name"
     end
     
     @query = params[:query]
     @results
     
     if not @query.empty?
     	if (@search_type != "name")
     		@results = Song.find(:all, :conditions => ["#{@search_type} like ? ", "%#{@query}%"], :order => "#{@search_type} asc")
     	else
     		@tag = Tag.find(:first, :conditions => ["#{@search_type} like ? ", "%#{@query}%"])
     		@results = @tag.songs.sort_by &:audio_file_name
   
     	end
     else
     	@results = []
     end
     
     @results = @results.paginate :per_page => 20, :page => params[:page]
  end
 
end
