Class: Solr::Importer::SolrSource

Inherits:
Object
  • Object
show all
Defined in:
lib/solr/importer/solr_source.rb

Instance Method Summary collapse

Constructor Details

#initialize(solr_url, query, filter_queries = nil, options = {}) ⇒ SolrSource

Returns a new instance of SolrSource.



16
17
18
19
20
21
22
23
# File 'lib/solr/importer/solr_source.rb', line 16

def initialize(solr_url, query, filter_queries=nil, options={})
  @connection = Solr::Connection.new(solr_url)
  @query = query
  @filter_queries = filter_queries

  @page_size = options[:page_size] || 1000
  @field_list = options[:field_list] || ["*"]
end

Instance Method Details

#eachObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/solr/importer/solr_source.rb', line 25

def each
  done = false
  start = 0
  until done do
    # request N documents from a starting point
    request = Solr::Request::Standard.new(:query => @query,
                                          :rows => @page_size,
                                          :start => start,
                                          :field_list => @field_list,
                                          :filter_queries => @filter_queries)
    response = @connection.send(request)
    response.each do |doc|
      yield doc  # TODO: perhaps convert to HashWithIndifferentAccess.new(doc), so stringify_keys isn't necessary
    end
    done = start + @page_size >= response.total_hits
    start = start + @page_size
  end
end