Skip to content

Instantly share code, notes, and snippets.

@bullfight
Created January 30, 2012 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bullfight/1704571 to your computer and use it in GitHub Desktop.
Save bullfight/1704571 to your computer and use it in GitHub Desktop.
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