Class: Algolia::Index::IndexBrowser

Inherits:
Object
  • Object
show all
Defined in:
lib/algolia/index.rb

Instance Method Summary collapse

Constructor Details

#initialize(client, name, params) ⇒ IndexBrowser

Returns a new instance of IndexBrowser.



168
169
170
171
172
173
# File 'lib/algolia/index.rb', line 168

def initialize(client, name, params)
  @client = client
  @name = name
  @params = params
  @cursor = params[:cursor] || params['cursor'] || nil
end

Instance Method Details

#browse(request_options = {}, &block) ⇒ Object



175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/algolia/index.rb', line 175

def browse(request_options = {}, &block)
  loop do
    answer = @client.get(Protocol.browse_uri(@name, @params.merge({ :cursor => @cursor })), :read, request_options)
    answer['hits'].each do |hit|
      if block.arity == 2
        yield hit, @cursor
      else
        yield hit
      end
    end
    @cursor = answer['cursor']
    break if @cursor.nil?
  end
end