quick and dirty support for AND in search
This commit is contained in:
parent
39f489d3bd
commit
a556234117
|
@ -10,8 +10,15 @@ class AlbumsController < ApplicationController
|
|||
#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, :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' )
|
||||
params[:q].split(" AND ").each {|q|
|
||||
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' )
|
||||
if @albums
|
||||
@albums = @albums & qalbums
|
||||
else
|
||||
@albums = qalbums
|
||||
end
|
||||
}
|
||||
else
|
||||
@albums = Album.find(:all, :order => 'title')
|
||||
end
|
||||
|
|
|
@ -13,7 +13,14 @@ class PhotosController < ApplicationController
|
|||
#search = params[:q]
|
||||
#search = search.split("AND").map{|q|q.strip}
|
||||
#@photos = Photo.find(:all, :select => 'DISTINCT photos.id, photos.album_id, photos.title, photos.path', :limit => 20, :conditions => { :tags => {:title => search}}, :joins => 'LEFT OUTER JOIN photo_tags ON photos.id = photo_tags.photo_id LEFT OUTER JOIN tags ON photo_tags.tag_id = tags.id', :include => [:album], :order => "photos.title ASC" )
|
||||
@photos = Photo.find(:all, :limit => 20, :conditions => [ "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 = :t) ", { :q => '%' + params[:q] + '%', :t => params[:q] } ], :include => :album, :order => "photos.id ASC" )
|
||||
params[:q].split(" AND ").each {|q|
|
||||
qphotos = Photo.find(:all, :limit => 20, :conditions => [ "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 = :t) ", { :q => '%' + q + '%', :t => q } ], :include => :album, :order => "photos.id ASC" )
|
||||
if @photos
|
||||
@photos = @photos & qphotos
|
||||
else
|
||||
@photos = qphotos
|
||||
end
|
||||
}
|
||||
else
|
||||
@photos = Photo.find(:all, :order => "photos.id ASC")
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue