Class: Stellr::Server
- Inherits:
-
Object
- Object
- Stellr::Server
- Includes:
- Utils::Shutdown
- Defined in:
- lib/stellr/server.rb
Instance Attribute Summary collapse
-
#collections ⇒ Object
readonly
Returns the value of attribute collections.
-
#config ⇒ Object
Returns the value of attribute config.
Instance Method Summary collapse
- #add_record(collection_name, record, boost = nil) ⇒ Object (also: #<<)
- #collection(name) ⇒ Object
- #delete_record(collection_name, record) ⇒ Object
-
#initialize(config) ⇒ Server
constructor
A new instance of Server.
-
#register(name, options = {}) ⇒ Object
Initialize a collection.
-
#register_multi_collection(names, options = {}) ⇒ Object
Initializes a read-only virtual collection that may be used to search across multiple physical collections.
- #size(collection_name) ⇒ Object
Methods included from Utils::Shutdown
Constructor Details
#initialize(config) ⇒ Server
Returns a new instance of Server.
11 12 13 14 15 16 17 18 |
# File 'lib/stellr/server.rb', line 11 def initialize( config ) @config = config create_directories @logger = Logger.new File.join(config.log_dir, 'stellr.log') @logger.level = Logger.const_get config.log_level.to_s.upcase @collections = {} @collections.extend MonitorMixin end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object (protected)
pass through commands to collection
106 107 108 109 110 111 112 |
# File 'lib/stellr/server.rb', line 106 def method_missing(method, *args) if args.size >= 1 collection_name = args.shift return collection( collection_name ).send( method, *args ) end super end |
Instance Attribute Details
#collections ⇒ Object (readonly)
Returns the value of attribute collections.
9 10 11 |
# File 'lib/stellr/server.rb', line 9 def collections @collections end |
#config ⇒ Object
Returns the value of attribute config.
8 9 10 |
# File 'lib/stellr/server.rb', line 8 def config @config end |
Instance Method Details
#add_record(collection_name, record, boost = nil) ⇒ Object Also known as: <<
20 21 22 |
# File 'lib/stellr/server.rb', line 20 def add_record( collection_name, record, boost = nil ) collection( collection_name ).add_record record, boost end |
#collection(name) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/stellr/server.rb', line 91 def collection( name ) @collections.synchronize do if @collections.has_key?( name ) return @collections[name] else @logger.info "trying to initialize collection #{name} from stored configuration..." return @collections[name] = create_collection( name, nil ) end end raise "UnknownCollection #{name}" end |
#delete_record(collection_name, record) ⇒ Object
25 26 27 |
# File 'lib/stellr/server.rb', line 25 def delete_record( collection_name, record ) collection( collection_name ).delete_record record end |
#register(name, options = {}) ⇒ Object
Initialize a collection.
Before anything can be done with a collection, it has to be registered through this method. When called for a non-existing collection, this will also create the empty physical index. The given options are saved to a yml file so they can be loaded again later on.
Calling register for an existing collection will update the saved index configuration from the options given, unless the options hash is nil. An already existing physical index won’t be touched and used as is. Remember that changing Ferret options like analyzers or field configuration requires an index rebuild to be effective for existing content. Stellr doesn’t take care of this.
If you access the server through the Stellr::Client class you don’t need to call register
explicitly as the client will do it when connecting.
Name is the name of the collection to create.
Options is a hash, consisting of:
collection
-
The collection implementation to use, may be one of :static or :rsync (default)
strategy
-
The strategy implementation to use (optional, atm there is only :queueing)
fields
-
hash
(see ferret.davebalmain.com/api/classes/Ferret/Index/FieldInfo.html) recreate
-
Recreate the index (defaults to
false
). A true value will lead to the deletion of any already indexed data. analyzer
-
The class name (String) of the Analyzer to use for this collection. By default, Ferret’s StandardAnalyzer will be used.
field_defaults
-
Default setting for unconfigured fields
Example
register 'standard_index', { :recreate => false,
:fields => { :author => { :index => :untokenized,
:store => :no,
:term_vector => :with_offsets,
:boost => 2.0 },
:content => { :index => :tokenized } }
}
70 71 72 73 74 75 76 77 |
# File 'lib/stellr/server.rb', line 70 def register( name, = {} ) untaint_collection_name name @collections.synchronize do collection = (@collections[name] ||= create_collection( name, )) save_collection_config name, unless .nil? or .empty? collection end end |
#register_multi_collection(names, options = {}) ⇒ Object
Initializes a read-only virtual collection that may be used to search across multiple physical collections.
Returns the name of the collection to be used with further calls.
83 84 85 86 87 88 89 |
# File 'lib/stellr/server.rb', line 83 def register_multi_collection( names, = {} ) key = ".multi_#{names.join '_'}" # '.' is not allowed for regular collection names, so we are safe from name collisions @collections.synchronize do @collections[key] ||= create_multi_collection( key, names.map{ |name| collection(name) }, ) end return key end |
#size(collection_name) ⇒ Object
29 30 31 |
# File 'lib/stellr/server.rb', line 29 def size( collection_name ) collection( collection_name ).size end |