Skip to content

Instantly share code, notes, and snippets.

@richmolj
Last active December 18, 2015 16:29
Show Gist options
  • Save richmolj/5811358 to your computer and use it in GitHub Desktop.
Save richmolj/5811358 to your computer and use it in GitHub Desktop.
class Post
def initialize(searcher, alarm_handler, stats_collector, should_order_posts)
@searcher = searcher
@alarm_handler = alarm_handler
@status_collector = stats_collector
@should_order_posts = should_order_posts
end
def search(keywords)
search = @searcher.search(keywords, should_order_posts)
@alarm_handler.raise('empty!') if search.results.empty?
@stats_collector.register_event(:post_search, keywords)
search.results
end
end
class SunspotSearcher
def search(keywords, should_order)
Sunspot.search do
fulltext keywords
order_by :published_at, :desc if should_order
end
end
end
alarm_handler = AlarmHandler.new(:post_search)
stats_collector = StatsCollector.new
Post.new(Searcher.new, alarm_handler, stats_collector, env['should_order'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment