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.
The shard sessions encapsulated by this class.
The shard sessions encapsulated by this class.
# 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
# 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
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