module RSolr
def self.connect(*args)
# direct connection
RSolr.connect :url=>'http://solr.web100.org'
# http connection with custom url
RSolr.connect
# default http connection
Examples:
2. options hash for solr-adapter only (no adapter type as first arg)
1. first argument is solr-adapter type, second arg is options hash for solr-adapter instance.
2 modes of argument operations:
Factory for creating connections.
def self.connect(*args) type = args.first.is_a?(Symbol) ? args.shift : :http opts = args type_class = case type when :http,nil 'HTTP' when :direct 'Direct' else raise "Invalid connection type: #{type} - use :http, :direct or leave nil for :http/default" end adapter_class = RSolr::Connection::Adapter.const_get(type_class) adapter = adapter_class.new(*opts) RSolr::Connection::Base.new(adapter) end