Class: Sunspot::Session
- Inherits:
-
Object
- Object
- Sunspot::Session
- Defined in:
- lib/sunspot/session.rb
Overview
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.
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
-
#commit ⇒ Object
See Sunspot.commit!.
-
#index(*objects) ⇒ Object
See Sunspot.index.
-
#index!(*objects) ⇒ Object
See Sunspot.index!.
-
#initialize(config = Configuration.build, connection = nil) {|@config| ... } ⇒ Session
constructor
Sessions are initialized with a Sunspot configuration and a Solr connection.
-
#remove(*objects) ⇒ Object
See Sunspot.remove.
-
#remove_all(*classes) ⇒ Object
See Sunspot.remove_all.
-
#search(*types, &block) ⇒ Object
See Sunspot.search.
Constructor Details
#initialize(config = Configuration.build, connection = nil) {|@config| ... } ⇒ Session
Sessions are initialized with a Sunspot configuration and a Solr connection. Usually you will want to stick with the default arguments when instantiating your own sessions.
18 19 20 21 22 |
# File 'lib/sunspot/session.rb', line 18 def initialize(config = Configuration.build, connection = nil) @config = config yield(@config) if block_given? @connection = connection end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
11 12 13 |
# File 'lib/sunspot/session.rb', line 11 def config @config end |
Instance Method Details
#commit ⇒ Object
See Sunspot.commit!
53 54 55 |
# File 'lib/sunspot/session.rb', line 53 def commit connection.commit end |
#index(*objects) ⇒ Object
See Sunspot.index
35 36 37 38 39 40 |
# File 'lib/sunspot/session.rb', line 35 def index(*objects) objects.flatten! for object in objects setup_for(object).indexer(connection).add(object) end end |
#index!(*objects) ⇒ Object
See Sunspot.index!
45 46 47 48 |
# File 'lib/sunspot/session.rb', line 45 def index!(*objects) index(*objects) commit end |
#remove(*objects) ⇒ Object
See Sunspot.remove
60 61 62 63 64 65 |
# File 'lib/sunspot/session.rb', line 60 def remove(*objects) objects.flatten! for object in objects setup_for(object).indexer(connection).remove(object) end end |
#remove_all(*classes) ⇒ Object
See Sunspot.remove_all
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/sunspot/session.rb', line 70 def remove_all(*classes) classes.flatten! if classes.empty? Indexer.remove_all(connection) else for clazz in classes Setup.for(clazz).indexer(connection).remove_all end end end |