class Sunspot::SessionProxy::IdShardingSessionProxy

A concrete implementation of ShardingSessionProxy that determines the shard for a given object based on the hash of its class and ID.

<strong>If you change the number of shard sessions that this proxy encapsulates, all objects will point to a different shard.</strong> If you plan on adding more shards over time, consider your own ShardingSessionProxy implementation that does not determine the session using modular arithmetic (e.g., IDs 1-10000 go to shard 1, 10001-20000 go to shard 2, etc.)

This implementation will, on average, yield an even distribution of objects across shards.

Unlike the abstract ShardingSessionProxy, this proxy supports the remove_by_id method.

Attributes

all_sessions[R]

The shard sessions encapsulated by this class.

sessions[R]

The shard sessions encapsulated by this class.

Public Instance Methods

remove_by_id(clazz, *ids) click to toggle source

See Sunspot.remove_by_id

# File lib/sunspot/session_proxy/id_sharding_session_proxy.rb, line 48
def remove_by_id(clazz, *ids)
  ids.flatten!
  ids_by_session(clazz, ids).each do |session, ids|
    session.remove_by_id(clazz, ids)
  end
end
remove_by_id!(clazz, *ids) click to toggle source

See Sunspot.remove_by_id!

# File lib/sunspot/session_proxy/id_sharding_session_proxy.rb, line 58
def remove_by_id!(clazz, *ids)
  ids.flatten!
  ids_by_session(clazz, ids).each do |session, ids|
    session.remove_by_id!(clazz, ids)
  end
end

Public Class Methods

new(search_session, shard_sessions) click to toggle source

Initialize with a search session (see Sunspot::SessionProxy::ShardingSessionProxy.new) and a collection of one or more shard sessions. See note about changing the number of shard sessions in the documentation for this class.

# File lib/sunspot/session_proxy/id_sharding_session_proxy.rb, line 32
def initialize(search_session, shard_sessions)
  super(search_session)
  @sessions = shard_sessions
end