Method: WordTree::DB::Librarian#search

Defined in:
lib/wordtree/db/librarian.rb

#search(params, page = 1, per_page = 20) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/wordtree/db/librarian.rb', line 28

def search(params, page=1, per_page=20)
  conditions = match_list(params,
                 [:id, :title, :author, :source, :status],
                 [:year, :size_bytes])
  cursor = @r.table('books').
             order_by(:index => 'year').
             filter(&conditions).
             skip((page-1)*per_page).
             limit(per_page).
             run(@rdb)
  if !(results = cursor.to_a).empty?
    results.map{ |result| Book.new(result) }
  else
    nil
  end
end