faster album search
This commit is contained in:
parent
af7277ba82
commit
39f489d3bd
1 changed files with 4 additions and 1 deletions
|
@ -9,7 +9,9 @@ class AlbumsController < ApplicationController
|
|||
#search = params[:q]
|
||||
#search = search.split("AND").map{|q|q.strip}
|
||||
#@albums = Album.find(:all, :select => 'DISTINCT albums.id, albums.title', :limit => 20, :conditions => { :tags => {:title => search}}, :joins => 'LEFT OUTER JOIN photos ON albums.id = photos.album_id LEFT OUTER JOIN photo_tags ON photos.id = photo_tags.photo_id LEFT OUTER JOIN tags ON photo_tags.tag_id = tags.id', :order => "albums.title ASC" )
|
||||
@albums = Album.find(:all, :conditions => [ "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')
|
||||
#@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')
|
||||
photos = 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 => '%' + params[:q] + '%' } ])
|
||||
@albums = Album.find(:all, :conditions => ['title LIKE :q OR description LIKE :q OR id IN (:ids)', { :ids => photos.map{|p|p.album_id}, :q => '%' + params[:q] + '%' }], :order => 'title' )
|
||||
else
|
||||
@albums = Album.find(:all, :order => 'title')
|
||||
end
|
||||
|
@ -45,6 +47,7 @@ class AlbumsController < ApplicationController
|
|||
|
||||
def create
|
||||
@album = Album.new(params[:album])
|
||||
|
||||
if @album.save
|
||||
unless params[:collection_id].empty?
|
||||
@album.collections << Collection.find( params[:collection_id] )
|
||||
|
|
Loading…
Reference in a new issue