Module: RSolr::Response::PaginatedDocSet

Defined in:
lib/rsolr/response.rb

Overview

A response module which gets mixed into the solr [“response”] array.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#page_startObject Also known as: start

Returns the value of attribute page_start.



17
18
19
# File 'lib/rsolr/response.rb', line 17

def page_start
  @page_start
end

#page_totalObject Also known as: total

Returns the value of attribute page_total.



17
18
19
# File 'lib/rsolr/response.rb', line 17

def page_total
  @page_total
end

#per_pageObject

Returns the value of attribute per_page.



17
18
19
# File 'lib/rsolr/response.rb', line 17

def per_page
  @per_page
end

Instance Method Details

#current_pageObject

Returns the current page calculated from ‘rows’ and ‘start’



26
27
28
29
30
# File 'lib/rsolr/response.rb', line 26

def current_page
  return 1 if start < 1
  per_page_normalized = per_page < 1 ? 1 : per_page
  @current_page ||= (start / per_page_normalized).ceil + 1
end

#has_next?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/rsolr/response.rb', line 47

def has_next?
  current_page < total_pages
end

#has_previous?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/rsolr/response.rb', line 51

def has_previous?
  current_page > 1
end

#next_pageObject

returns the next page number or the last



43
44
45
# File 'lib/rsolr/response.rb', line 43

def next_page
  @next_page ||= (current_page == total_pages) ? total_pages : current_page+1
end

#previous_pageObject

returns the previous page number or 1



38
39
40
# File 'lib/rsolr/response.rb', line 38

def previous_page
  @previous_page ||= (current_page > 1) ? current_page - 1 : 1
end

#total_pagesObject

Calcuates the total pages from ‘numFound’ and ‘rows’



33
34
35
# File 'lib/rsolr/response.rb', line 33

def total_pages
  @total_pages ||= per_page > 0 ? (total / per_page.to_f).ceil : 1
end