class Sunspot::SessionProxy::ShardingSessionProxy

This is a generic abstract implementation of a session proxy that allows Sunspot to be used with a distributed (sharded) Solr deployment. Concrete subclasses should implement the session_for method, which takes a searchable object and returns a Session that points to the appropriate Solr shard for that object. Subclasses should also implement the all_sessions object, which returns the collection of all sharded Session objects.

The class is initialized with a session that points to the Solr instance used to perform searches. Searches will have the :shards param injected, containing references to the Solr instances returned by all_sessions.

For more on distributed search, see: wiki.apache.org/solr/DistributedSearch

The following methods are not supported (although subclasses may in some cases be able to support them):

Public Instance Methods

all_sessions() click to toggle source

Return all shard sessions.

<strong>Concrete subclasses must implement this method.</strong>

# File lib/sunspot/session_proxy/sharding_session_proxy.rb, line 57
def all_sessions
  raise NotImplementedError
end
commit() click to toggle source

Commit all shards. See Sunspot.commit

# File lib/sunspot/session_proxy/sharding_session_proxy.rb, line 120
def commit
  all_sessions.each { |session| session.commit }
end
commit_if_delete_dirty() click to toggle source

Commit all delete-dirty sessions. Only delete-dirty sessions will be committed.

See Sunspot.commit_if_delete_dirty

# File lib/sunspot/session_proxy/sharding_session_proxy.rb, line 146
def commit_if_delete_dirty
  all_sessions.each { |session| session.commit_if_delete_dirty }
end
commit_if_dirty() click to toggle source

Commit all dirty sessions. Only dirty sessions will be committed.

See Sunspot.commit_if_dirty

# File lib/sunspot/session_proxy/sharding_session_proxy.rb, line 136
def commit_if_dirty
  all_sessions.each { |session| session.commit_if_dirty }
end
delete_dirty?() click to toggle source

True if any shard session is delete-dirty. Note that directly using the commit_if_delete_dirty method is more efficient if that’s what you’re trying to do, since in that case only the delete-dirty sessions are committed.

# File lib/sunspot/session_proxy/sharding_session_proxy.rb, line 205
def delete_dirty?
  all_sessions.any? { |session| session.delete_dirty? }
end
dirty?() click to toggle source

True if any shard session is dirty. Note that directly using the commit_if_dirty method is more efficient if that’s what you’re trying to do, since in that case only the dirty sessions are committed.

See Sunspot.dirty?

# File lib/sunspot/session_proxy/sharding_session_proxy.rb, line 195
def dirty?
  all_sessions.any? { |session| session.dirty? }
end
index(*objects) click to toggle source

See Sunspot.index

# File lib/sunspot/session_proxy/sharding_session_proxy.rb, line 64
def index(*objects)
  using_sharded_session(objects) { |session, group| session.index(group) }
end
index!(*objects) click to toggle source

See Sunspot.index!

# File lib/sunspot/session_proxy/sharding_session_proxy.rb, line 71
def index!(*objects)
  using_sharded_session(objects) { |session, group| session.index!(group) }
end
more_like_this(object, &block) click to toggle source
# File lib/sunspot/session_proxy/sharding_session_proxy.rb, line 179
def more_like_this(object, &block)
  #FIXME should use shards
  new_more_like_this(object, &block).execute
end
new_more_like_this(object, &block) click to toggle source
# File lib/sunspot/session_proxy/sharding_session_proxy.rb, line 184
def new_more_like_this(object, &block)
  @search_session.new_more_like_this(object, &block)
end
optimize() click to toggle source

Optimize all shards. See Sunspot.optimize

# File lib/sunspot/session_proxy/sharding_session_proxy.rb, line 127
def optimize
  all_sessions.each { |session| session.optimize }
end
remove(*objects) click to toggle source

See Sunspot.remove

# File lib/sunspot/session_proxy/sharding_session_proxy.rb, line 78
def remove(*objects)
  using_sharded_session(objects) { |session, group| session.remove(group) }
end
remove!(*objects) click to toggle source

See Sunspot.remove!

# File lib/sunspot/session_proxy/sharding_session_proxy.rb, line 85
def remove!(*objects)
  using_sharded_session(objects) { |session, group| session.remove!(group) }
end
remove_all(clazz = nil) click to toggle source

If no argument is passed, behaves like Sunspot.remove_all

If an argument is passed, will raise NotSupportedError, as the proxy does not know which session(s) to which to delegate this operation.

# File lib/sunspot/session_proxy/sharding_session_proxy.rb, line 95
def remove_all(clazz = nil)
  if clazz
    raise NotSupportedError, "Sharding session proxy does not support remove_all with an argument."
  else
    all_sessions.each { |session| session.remove_all }
  end
end
remove_all!(clazz = nil) click to toggle source

If no argument is passed, behaves like Sunspot.remove_all!

If an argument is passed, will raise NotSupportedError, as the proxy does not know which session(s) to which to delegate this operation.

# File lib/sunspot/session_proxy/sharding_session_proxy.rb, line 109
def remove_all!(clazz = nil)
  if clazz
    raise NotSupportedError, "Sharding session proxy does not support remove_all! with an argument."
  else
    all_sessions.each { |session| session.remove_all! }
  end
end
session_for(object) click to toggle source

Return the appropriate shard session for the object.

<strong>Concrete subclasses must implement this method.</strong>

# File lib/sunspot/session_proxy/sharding_session_proxy.rb, line 48
def session_for(object)
  raise NotImplementedError
end

Public Class Methods

new(search_session = Sunspot.session.new) click to toggle source

search_session is the session that should be used for searching.

# File lib/sunspot/session_proxy/sharding_session_proxy.rb, line 39
def initialize(search_session = Sunspot.session.new)
  @search_session = search_session
end