Class: SolrCloud::Alias

Inherits:
Collection show all
Defined in:
lib/solr_cloud/alias.rb

Overview

An alias shouldn’t be created directly. Rather, get an existing one with Connection#alias, or from a collection, or create one with Collection#alias_as

Instance Attribute Summary

Attributes inherited from Collection

#connection, #name

Instance Method Summary collapse

Methods inherited from Collection

#==, #add, #alias_as, #alias_as!, #alias_names, #aliased?, #aliases, #alive?, #commit, #configset, #count, #delete, #get, #get_alias, #has_alias?, #healthy?, #initialize, #post, #put

Constructor Details

This class inherits a constructor from SolrCloud::Collection

Instance Method Details

#alias?Boolean

An alias is, shockingly, an alias. Convenience to differentiate aliases from collections.

Returns:

  • (Boolean)

See Also:

  • Connection#get_alias?


13
14
15
# File 'lib/solr_cloud/alias.rb', line 13

def alias?
  true
end

#collectionCollection

Get the collection this alias points to. In real life, Solr will allow an alias to point to more than one collection. Functionality for this might be added at some point

Returns:



34
35
36
# File 'lib/solr_cloud/alias.rb', line 34

def collection
  connection.alias_map[name].collection
end

#delete!Connection

Delete this alias. Will be a no-op if it doesn’t exist.

Returns:



19
20
21
22
23
# File 'lib/solr_cloud/alias.rb', line 19

def delete!
  return connection unless exist?
  connection.get("solr/admin/collections", action: "DELETEALIAS", name: name)
  connection
end

#exist?Boolean

Does this alias still exist?

Returns:

  • (Boolean)


26
27
28
# File 'lib/solr_cloud/alias.rb', line 26

def exist?
  connection.alias_names.include?(name)
end

#infoObject

Get basic information on the underlying collection, so inherited methods that use it (e.g., #healthy?) will work.



60
61
62
# File 'lib/solr_cloud/alias.rb', line 60

def info
  collection.info
end

#inspectObject Also known as: to_s



64
65
66
# File 'lib/solr_cloud/alias.rb', line 64

def inspect
  "<#{self.class} '#{name}' (alias of '#{collection.name}')>"
end

#pretty_print(q) ⇒ Object



70
71
72
# File 'lib/solr_cloud/alias.rb', line 70

def pretty_print(q)
  q.text inspect
end

#switch_collection_to(coll) ⇒ Collection Also known as: collection=

Redefine what collection this alias points to This is equivalent to dropping/re-adding the alias, or calling connection.create_alias with ‘force: true`

Parameters:

  • coll (String, Collection)

    either the name of the collection, or a collection object itself

Returns:

Raises:



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/solr_cloud/alias.rb', line 42

def switch_collection_to(coll)
  collect_name = case coll
  when String
    coll
  when Collection
    coll.name
  else
    raise "Alias#switch_collection_to only takes a name(string) or a collection, not '#{coll}'"
  end
  raise NoSuchCollectionError unless connection.has_collection?(collect_name)
  connection.create_alias(name: name, collection_name: collect_name, force: true)
end