Sha256: e82c7340bfca2621e76be6524d343e90a0ad0c719d553dca1dd3227cebf1e873

Contents?: true

Size: 1.48 KB

Versions: 6

Compression:

Stored size: 1.48 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!, :remove,
               :remove!, :remove_all, :remove_all!, :remove_by_id,
               :remove_by_id!, :to => :master_session
      delegate :new_search, :search, :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

6 entries across 6 versions & 1 rubygems

Version Path
sunspot-1.0.5 lib/sunspot/session_proxy/master_slave_session_proxy.rb
sunspot-1.0.4 lib/sunspot/session_proxy/master_slave_session_proxy.rb
sunspot-1.0.3 lib/sunspot/session_proxy/master_slave_session_proxy.rb
sunspot-1.0.2 lib/sunspot/session_proxy/master_slave_session_proxy.rb
sunspot-1.0.1 lib/sunspot/session_proxy/master_slave_session_proxy.rb
sunspot-1.0.0 lib/sunspot/session_proxy/master_slave_session_proxy.rb