Module: SolrCloud::Connection::CollectionAdmin
- Included in:
- SolrCloud::Connection
- Defined in:
- lib/solr_cloud/connection/collection_admin.rb
Overview
methods having to do with collections, to be included by the connection object. These are split out only to make it easier to deal with them.
For almost everything in here, we treat aliases like collections – calls to #collections, #has_collection?, #collection, etc. will respond to, and return, and alias if there is one. The idea is that you shouldn’t need to know if something is an alias or a collection until it’s relevant
Instance Method Summary collapse
-
#collection_names ⇒ Array<String>
A list of the names of existing collections and aliases.
-
#collections ⇒ Array<Collection, Alias>
Get a list of collections (and aliases).
-
#create_collection(name:, configset:, shards: 1, replication_factor: 1) ⇒ Collection
Create and return a new collection.
-
#get_collection(collection_name) ⇒ Collection, ...
Get a collection object specifically for the named collection.
-
#get_collection!(collection_name) ⇒ Collection, Alias
Get a connection/alias object, throwing an error if it’s not found.
-
#has_collection?(name) ⇒ Boolean
Whether a collection with the passed name exists.
-
#only_collection_names ⇒ Array<String>
The names of only connections (and not aliases).
-
#only_collections ⇒ Object
Get a list of only collections, as opposed to the mix of collections and aliases we usually do.
Instance Method Details
#collection_names ⇒ Array<String>
A list of the names of existing collections and aliases
67 68 69 |
# File 'lib/solr_cloud/connection/collection_admin.rb', line 67 def collection_names collections.map(&:name) end |
#collections ⇒ Array<Collection, Alias>
Get a list of collections (and aliases)
61 62 63 |
# File 'lib/solr_cloud/connection/collection_admin.rb', line 61 def collections only_collections.union(aliases) end |
#create_collection(name:, configset:, shards: 1, replication_factor: 1) ⇒ Collection
Create and return a new collection.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/solr_cloud/connection/collection_admin.rb', line 22 def create_collection(name:, configset:, shards: 1, replication_factor: 1) unless legal_solr_name?(name) raise IllegalNameError.new("'#{name}' is not a valid solr name. Use only ASCII letters/numbers, dash, and underscore") end configset_name = case configset when Configset configset.name else configset.to_s end raise WontOverwriteError.new("Collection #{name} already exists") if has_collection?(name) raise NoSuchConfigSetError.new("Configset '#{configset_name}' doesn't exist") unless has_configset?(configset_name) args = { :action => "CREATE", :name => name, :numShards => shards, :replicationFactor => replication_factor, "collection.configName" => configset_name } connection.get("solr/admin/collections", args) get_collection(name) end |
#get_collection(collection_name) ⇒ Collection, ...
Get a collection object specifically for the named collection
80 81 82 83 84 85 86 87 |
# File 'lib/solr_cloud/connection/collection_admin.rb', line 80 def get_collection(collection_name) return nil unless has_collection?(collection_name) if only_collection_names.include?(collection_name) Collection.new(name: collection_name, connection: self) else get_alias(collection_name) end end |
#get_collection!(collection_name) ⇒ Collection, Alias
Get a connection/alias object, throwing an error if it’s not found
93 94 95 96 |
# File 'lib/solr_cloud/connection/collection_admin.rb', line 93 def get_collection!(collection_name) raise NoSuchCollectionError.new("Collection '#{collection_name}' not found") unless has_collection?(collection_name) get_collection(collection_name) end |
#has_collection?(name) ⇒ Boolean
Returns Whether a collection with the passed name exists.
73 74 75 |
# File 'lib/solr_cloud/connection/collection_admin.rb', line 73 def has_collection?(name) collection_names.include? name end |
#only_collection_names ⇒ Array<String>
The names of only connections (and not aliases). Useful as a utility.
55 56 57 |
# File 'lib/solr_cloud/connection/collection_admin.rb', line 55 def only_collection_names only_collections.map(&:name) end |
#only_collections ⇒ Object
Get a list of only collections, as opposed to the mix of collections and aliases we usually do.
49 50 51 |
# File 'lib/solr_cloud/connection/collection_admin.rb', line 49 def only_collections connection.get("api/collections").body["collections"].map { |c| Collection.new(name: c, connection: self) } end |