Class: Feedcellar::GroongaSearcher

Inherits:
Object
  • Object
show all
Defined in:
lib/feedcellar/groonga_searcher.rb

Class Method Summary collapse

Class Method Details

.latest(database) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/feedcellar/groonga_searcher.rb', line 35

def latest(database)
  latest_feeds = []

  feeds = database.feeds
  feeds.group("resource.xmlUrl", :max_n_sub_records => 1).each do |group|
    latest_feed = group.sub_records[0]
    next unless latest_feed
    next unless latest_feed.title
    latest_feeds << latest_feed
  end

  latest_feeds
end

.search(database, words, options = {}) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/feedcellar/groonga_searcher.rb', line 22

def search(database, words, options={})
  feeds = database.feeds
  selected_feeds = select_feeds(feeds, words, options)

  order = options[:reverse] ? "ascending" : "descending"
  sorted_feeds = selected_feeds.sort([{
                                        :key => "date",
                                        :order => order,
                                      }])

  sorted_feeds
end