@albums=Album.find(:all,:conditions=>["id IN ( SELECT DISTINCT photos.album_id FROM photos WHERE photos.id IN ( SELECT photo_id FROM photo_tags WHERE photo_tags.tag_id = :q) )",{:q=>Tag.find(params[:tag_id]).id}],:order=>'title')
#@albums = Album.find(:all, :select => 'DISTINCT album_id', :conditions => [ "title LIKE :q OR description LIKE :q OR id IN ( SELECT DISTINCT photos.album_id FROM photos WHERE photos.description LIKE :q OR photos.title LIKE :q OR photos.id IN ( SELECT photo_id FROM photo_tags LEFT OUTER JOIN tags ON photo_tags.tag_id = tags.id WHERE tags.title LIKE :q) )", { :q => '%' + params[:q] + '%' } ], :order => 'title')
qphotos=Photo.find(:all,:select=>'DISTINCT album_id',:conditions=>["description LIKE :q OR title LIKE :q OR id IN ( SELECT photo_id FROM photo_tags LEFT OUTER JOIN tags ON photo_tags.tag_id = tags.id WHERE tags.title LIKE :q)",{:q=>'%'+q+'%'}])
qalbums=Album.find(:all,:conditions=>['title LIKE :q OR description LIKE :q OR id IN (:ids)',{:ids=>qphotos.map{|p|p.album_id},:q=>'%'+q+'%'}],:order=>'title')