Skip to content

Instantly share code, notes, and snippets.

@joeljunstrom
Created May 17, 2010 21:37
Show Gist options
  • Save joeljunstrom/404261 to your computer and use it in GitHub Desktop.
Save joeljunstrom/404261 to your computer and use it in GitHub Desktop.
apps_controller:
def search
@query = params[:query]
@search = App.search(@query)
respond_with(@search)
end
app.rb:
class << self
def search(query)
query = query.strip.downcase
result = Sunspot.search(App) do |search|
search.keywords query
end
if result.total != 0
qualifier = { :value => query, :searchable_type => self.name }
search_query = SearchQuery.where(qualifier).first || SearchQuery.new(qualifier.merge(:searches => 1))
!search_query.new_record? ? search_query.increment!(:searches) : search_query.save
end
result
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment