Created
January 30, 2012 14:11
-
-
Save bullfight/1704571 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Search | |
attr_accessor :params, :locale, :results | |
def initialize(params, locale) | |
return if params[:search].blank? | |
@params = params | |
@params[:page] ||= "1" | |
@params[:per_page] ||= "10" | |
@locale = Localized::Config.locale_to_site_map[locale].to_s #Hacktastic, should work with locale.to_s | |
self.send(@params[:filter]) | |
end | |
def to_s | |
@results ||= [] | |
end | |
def articles | |
@results = Article.search( @params[:search], | |
page: @params[:page], | |
field_weights: { title: 20, body: 15 }, | |
with: { published_at: 0..Time.now.utc.to_i }, | |
conditions: { :locale => @locale }, | |
per_page: @params[:per_page] ) | |
end | |
def artists | |
@results = Artist.search( @params[:search], | |
page: @params[:page], | |
conditions: { :locale => @locale }, | |
per_page: @params[:per_page] ) | |
end | |
def promotions | |
@results = Promotion.search( @params[:search], | |
page: @params[:page], | |
with: { published_at: 0..Time.now.utc.to_i }, | |
conditions: { :locale => @locale }, | |
per_page: @params[:per_page] ) | |
end | |
def media | |
@results = ThinkingSphinx.search( @params[:search], | |
classes: [Photo, Video], | |
field_weights: { :title => 20, :summary => 18, :body => 15 }, | |
page: @params[:page], | |
per_page: @params[:per_page] ) | |
end | |
def site | |
@results = ThinkingSphinx.search( @params[:search], | |
classes: [Article, Artist, Photo, Video], | |
field_weights: { :title => 20, :name => 20, :summary => 18, :body => 15 }, | |
with: { published_at: 0..Time.now.utc.to_i }, | |
condition: { :locale => @locale }, | |
page: @params[:page], | |
per_page: @params[:per_page] ) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment