module Sunspot # # A Sunspot session encapsulates a connection to Solr and a set of # configuration choices. Though users of Sunspot may manually instantiate # Session objects, in the general case it's easier to use the singleton # stored in the Sunspot module. Since the Sunspot module provides all of # the instance methods of Session as class methods, they are not documented # again here. # class Session class < 0 end # # See Sunspot.commit_if_dirty # def commit_if_dirty commit if dirty? end # # See Sunspot.batch # def batch indexer.start_batch yield indexer.flush_batch end private # # Retrieve the Solr connection for this session, creating one if it does not # already exist. # # ==== Returns # # Solr::Connection:: The connection for this session # def connection @connection ||= begin self.class.connection_class.connect(:url => config.solr.url, :adapter => config.http_client) # connection = self.class.connection_class.new( # RSolr::Adapter::HTTP.new(:url => config.solr.url) # ) # connection.adapter.connector.adapter_name = config.http_client # connection end end # # Retrieve the Solr connection to the master for this session, creating one # if it does not already exist. # # ==== Returns # # Solr::Connection:: The connection for this session # def master_connection @master_connection ||= begin if config.master_solr.url && config.master_solr.url != config.solr.url master_connection = self.class.connection_class.new( RSolr::Adapter::HTTP.new(:url => config.master_solr.url) ) master_connection.adapter.connector.adapter_name = config.http_client master_connection else connection end end end def indexer @indexer ||= Indexer.new(master_connection) end end end