Class: ROM::Solr::SelectCursor

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/rom/solr/select_cursor.rb

Overview

Wraps a DocumentsDataset to provide pagination with a cursor.

Instance Method Summary collapse

Constructor Details

#initialize(dataset) ⇒ SelectCursor

Returns a new instance of SelectCursor.



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/rom/solr/select_cursor.rb', line 10

def initialize(dataset)
  params = { cursorMark: '*' }

  # Sort must include a sort on unique key (id).
  sort = dataset.params[:sort]
  unless /\bid\b/ =~ sort
    params[:sort] = Array.wrap(sort).append('id ASC').join(',')
  end

  super dataset.add_params(params)
end

Instance Method Details

#cursor_markObject



34
35
36
# File 'lib/rom/solr/select_cursor.rb', line 34

def cursor_mark
  params[:cursorMark]
end

#each(&block) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/rom/solr/select_cursor.rb', line 22

def each(&block)
  return to_enum unless block_given?

  while true
    __getobj__.each(&block)

    break if last_page?

    move_cursor
  end
end

#last_page?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/rom/solr/select_cursor.rb', line 42

def last_page?
  cursor_mark == next_cursor_mark
end

#move_cursorObject



46
47
48
# File 'lib/rom/solr/select_cursor.rb', line 46

def move_cursor
  __setobj__(next_page)
end

#next_cursor_markObject



38
39
40
# File 'lib/rom/solr/select_cursor.rb', line 38

def next_cursor_mark
  response[:nextCursorMark]
end

#next_pageObject



50
51
52
# File 'lib/rom/solr/select_cursor.rb', line 50

def next_page
  __getobj__.add_params(cursorMark: next_cursor_mark)
end