Last active
December 18, 2015 16:29
-
-
Save richmolj/5811358 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 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