Module: SolrCloud::Connection::AliasAdmin
- Included in:
- SolrCloud::Connection
- Defined in:
- lib/solr_cloud/connection/alias_admin.rb
Overview
methods having to do with aliases, to be included by the connection object. These are split out only to make it easier to deal with them.
Defined Under Namespace
Classes: AliasCollectionPair
Instance Method Summary collapse
-
#alias_map ⇒ Hash<String,Alias>
Get the aliases and create a map of the form AliasName -> AliasObject.
-
#alias_names ⇒ Array<String>
List of alias names.
-
#aliases ⇒ Array<SolrCloud::Alias>
List of alias objects.
-
#create_alias(name:, collection_name:, force: false) ⇒ Alias
Create an alias for the given collection name.
-
#get_alias(name) ⇒ Alias?
Get an alias object for the given name, erroring out if not found.
-
#get_alias!(name) ⇒ SolrCloud::Alias
Get an alias object for the given name, erroring out if not found.
-
#has_alias?(name) ⇒ Boolean
Is there an alias with this name?.
-
#raw_alias_map ⇒ Hash<String, String>
The “raw” alias map, which just maps alias names to collection names.
Instance Method Details
#alias_map ⇒ Hash<String,Alias>
Get the aliases and create a map of the form AliasName -> AliasObject
69 70 71 72 73 74 75 |
# File 'lib/solr_cloud/connection/alias_admin.rb', line 69 def alias_map raw_alias_map.keys.each_with_object({}) do |alias_name, h| a = Alias.new(name: alias_name, connection: self) c = Collection.new(name: raw_alias_map[alias_name], connection: self) h[alias_name] = AliasCollectionPair.new(a, c) end end |
#alias_names ⇒ Array<String>
List of alias names
46 47 48 |
# File 'lib/solr_cloud/connection/alias_admin.rb', line 46 def alias_names alias_map.keys end |
#aliases ⇒ Array<SolrCloud::Alias>
List of alias objects
40 41 42 |
# File 'lib/solr_cloud/connection/alias_admin.rb', line 40 def aliases alias_map.values.map(&:alias) end |
#create_alias(name:, collection_name:, force: false) ⇒ Alias
Create an alias for the given collection name.
In general, prefer SolrCloud::Collection#alias_as instead of running everything through the connection object.
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/solr_cloud/connection/alias_admin.rb', line 20 def create_alias(name:, collection_name:, force: false) unless legal_solr_name?(name) raise IllegalNameError.new("'#{name}' is not a valid solr alias name. Use only ASCII letters/numbers, dash, and underscore") end raise NoSuchCollectionError.new("Can't find collection #{collection_name}") unless has_collection?(collection_name) if has_alias?(name) && !force raise WontOverwriteError.new("Alias '#{name}' already points to collection '#{get_alias(name).collection.name}'; won't overwrite without force: true") end connection.get("solr/admin/collections", action: "CREATEALIAS", name: name, collections: collection_name) get_alias(name) end |
#get_alias(name) ⇒ Alias?
Get an alias object for the given name, erroring out if not found
53 54 55 56 |
# File 'lib/solr_cloud/connection/alias_admin.rb', line 53 def get_alias(name) return nil unless has_alias?(name) alias_map[name].alias end |
#get_alias!(name) ⇒ SolrCloud::Alias
Get an alias object for the given name, erroring out if not found
62 63 64 65 |
# File 'lib/solr_cloud/connection/alias_admin.rb', line 62 def get_alias!(name) raise NoSuchAliasError unless has_alias?(name) get_alias(name) end |
#has_alias?(name) ⇒ Boolean
Is there an alias with this name?
34 35 36 |
# File 'lib/solr_cloud/connection/alias_admin.rb', line 34 def has_alias?(name) alias_names.include? name end |
#raw_alias_map ⇒ Hash<String, String>
The “raw” alias map, which just maps alias names to collection names
79 80 81 |
# File 'lib/solr_cloud/connection/alias_admin.rb', line 79 def raw_alias_map connection.get("solr/admin/collections", action: "LISTALIASES").body["aliases"] end |