Class ActsAsFerret::SearchResults
In: lib/search_results.rb
Parent: ActsAsFerret::BlankSlate

decorator that adds a total_hits accessor and will_paginate compatible paging support to search result arrays

Methods

External Aliases

total_hits -> total_entries
total_pages -> page_count

Attributes

current_page  [R] 
per_page  [R] 
total_hits  [R] 
total_pages  [R] 

Public Class methods

[Source]

    # File lib/search_results.rb, line 11
11:     def initialize(results, total_hits, current_page = 1, per_page = nil)
12:       @results = results
13:       @total_hits = total_hits
14:       @current_page = current_page
15:       @per_page = (per_page || total_hits)
16:       @total_pages   = @per_page > 0 ? (@total_hits / @per_page.to_f).ceil : 0
17:     end

Public Instance methods

[Source]

    # File lib/search_results.rb, line 19
19:     def method_missing(symbol, *args, &block)
20:       @results.send(symbol, *args, &block)
21:     end

current_page + 1 or nil if there is no next page

[Source]

    # File lib/search_results.rb, line 45
45:     def next_page
46:       current_page < total_pages ? (current_page + 1) : nil
47:     end

Current offset of the paginated collection. If we‘re on the first page, it is always 0. If we‘re on the 2nd page and there are 30 entries per page, the offset is 30. This property is useful if you want to render ordinals besides your records: simply start with offset + 1.

[Source]

    # File lib/search_results.rb, line 35
35:     def offset
36:       (current_page - 1) * per_page
37:     end

current_page - 1 or nil if there is no previous page

[Source]

    # File lib/search_results.rb, line 40
40:     def previous_page
41:       current_page > 1 ? (current_page - 1) : nil
42:     end

[Source]

    # File lib/search_results.rb, line 23
23:     def respond_to?(name)
24:       methods.include?(name.to_s) || @results.respond_to?(name)
25:     end

[Validate]