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
70 71 72 73 74 75 76 |
# File 'lib/solr_cloud/connection/alias_admin.rb', line 70 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
47 48 49 |
# File 'lib/solr_cloud/connection/alias_admin.rb', line 47 def alias_names alias_map.keys end |
#aliases ⇒ Array<SolrCloud::Alias>
List of alias objects
41 42 43 |
# File 'lib/solr_cloud/connection/alias_admin.rb', line 41 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.
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/solr_cloud/connection/alias_admin.rb', line 21 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 '#{self.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
54 55 56 57 |
# File 'lib/solr_cloud/connection/alias_admin.rb', line 54 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
63 64 65 66 |
# File 'lib/solr_cloud/connection/alias_admin.rb', line 63 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?
35 36 37 |
# File 'lib/solr_cloud/connection/alias_admin.rb', line 35 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
80 81 82 |
# File 'lib/solr_cloud/connection/alias_admin.rb', line 80 def raw_alias_map connection.get("solr/admin/collections", action: "LISTALIASES").body["aliases"] end |