Sha256: 15a29eca1830919317dfaf5d384b149d5e6d22f45652fc85b24ab808411294f2

Contents?: true

Size: 1.59 KB

Versions: 32

Compression:

Stored size: 1.59 KB

Contents

# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

class Solr::Importer::SolrSource
  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
  
  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
end

Version data entries

32 entries across 32 versions & 6 rubygems

Version Path
honkster-acts_as_solr-0.1.0 lib/solr/importer/solr_source.rb
honkster-acts_as_solr-0.2.0 lib/solr/importer/solr_source.rb
honkster-acts_as_solr-0.2.1 lib/solr/importer/solr_source.rb
honkster-acts_as_solr-0.2.2 lib/solr/importer/solr_source.rb
honkster-acts_as_solr-0.2.3 lib/solr/importer/solr_source.rb
honkster-acts_as_solr-0.2.4 lib/solr/importer/solr_source.rb
honkster-acts_as_solr-0.2.5 lib/solr/importer/solr_source.rb
honkster-acts_as_solr-0.3.4 lib/solr/importer/solr_source.rb
jbasdf-acts_as_solr-0.3.3 lib/solr/importer/solr_source.rb
jbasdf-jbasdf-acts_as_solr-0.4.0 lib/solr/importer/solr_source.rb
jbasdf-muck-solr-0.4.0 lib/solr/importer/solr_source.rb
jbasdf-muck-solr-0.4.1 lib/solr/importer/solr_source.rb
jbasdf-muck-solr-0.4.2 lib/solr/importer/solr_source.rb
acts_as_solr_reloaded-1.6.0 lib/solr/importer/solr_source.rb
muck-solr-3.0.1 lib/solr/importer/solr_source.rb
muck-solr-3.0.0 lib/solr/importer/solr_source.rb
acts_as_solr_reloaded-1.5.0 lib/solr/importer/solr_source.rb
acts_as_solr_reloaded-1.4.0 lib/solr/importer/solr_source.rb
muck-solr-0.4.7 lib/solr/importer/solr_source.rb
acts_as_solr_reloaded-1.3.0 lib/solr/importer/solr_source.rb