Sha256: b9690d54db6fb6d6c4c4564dbbe4ba994664b5fbd0491ddd5d051578d3d9c8b5

Contents?: true

Size: 1.56 KB

Versions: 15

Compression:

Stored size: 1.56 KB

Contents

require File.join(File.dirname(__FILE__), 'abstract_session_proxy')

module Sunspot
  module SessionProxy
    # 
    # This session proxy implementation allows Sunspot to be used with a
    # master/slave Solr deployment. All write methods are delegated to a master
    # session, and read methods are delegated to a slave session.
    #
    class MasterSlaveSessionProxy < AbstractSessionProxy
      #
      # The session that connects to the master Solr instance.
      #
      attr_reader :master_session
      # 
      # The session that connects to the slave Solr instance.
      #
      attr_reader :slave_session

      delegate :batch, :commit, :commit_if_delete_dirty, :commit_if_dirty,
               :config, :delete_dirty?, :dirty?, :index, :index!, :optimize, :remove,
               :remove!, :remove_all, :remove_all!, :remove_by_id, :remove_by_id!,
               :atomic_update, :atomic_update!, :to => :master_session
      delegate :new_search, :search, :new_more_like_this, :more_like_this, :to => :slave_session

      def initialize(master_session, slave_session)
        @master_session, @slave_session = master_session, slave_session
      end

      # 
      # By default, return the configuration for the master session. If the
      # +delegate+ param is +:slave+, then return config for the slave session.
      #
      def config(delegate = :master)
        case delegate
        when :master then @master_session.config
        when :slave then  @slave_session.config
        else raise(ArgumentError, "Expected :master or :slave")
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 2 rubygems

Version Path
sunspot-2.7.1 lib/sunspot/session_proxy/master_slave_session_proxy.rb
sunspot-2.7.0 lib/sunspot/session_proxy/master_slave_session_proxy.rb
sunspot-2.6.0 lib/sunspot/session_proxy/master_slave_session_proxy.rb
sunspot-2.5.0 lib/sunspot/session_proxy/master_slave_session_proxy.rb
sunspot-2.4.0 lib/sunspot/session_proxy/master_slave_session_proxy.rb
sunspot-2.3.0 lib/sunspot/session_proxy/master_slave_session_proxy.rb
sunspot-2.2.8 lib/sunspot/session_proxy/master_slave_session_proxy.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/sunspot-2.2.7/lib/sunspot/session_proxy/master_slave_session_proxy.rb
sunspot-2.2.7 lib/sunspot/session_proxy/master_slave_session_proxy.rb
sunspot-2.2.6 lib/sunspot/session_proxy/master_slave_session_proxy.rb
sunspot-2.2.5 lib/sunspot/session_proxy/master_slave_session_proxy.rb
sunspot-2.2.4 lib/sunspot/session_proxy/master_slave_session_proxy.rb
sunspot-2.2.3 lib/sunspot/session_proxy/master_slave_session_proxy.rb
sunspot-2.2.2 lib/sunspot/session_proxy/master_slave_session_proxy.rb
sunspot-2.2.1 lib/sunspot/session_proxy/master_slave_session_proxy.rb