SolrCloud::Connection
Common usage
server = SolrCloud::Connection.new(url: url, user: user, password: pass)
cfg = server.create_configset(name: "my_cfg", confdir: "/path/to/my/conf")
cars_v1 = server.create_collection(name: "cars_v1", configset: "my_cfg")
cars = cars_v1.alias_as("cars")
Basic functionality / Roadmap
Do basic administrative tasks on a running Solr cloud instance
In almost all cases, you can treat an alias to a collection like the underlying collection.
A note about deleting things
Collections, aliases, and configsets all have a #delete!
method. Keep in mind that solr
enforces a rule that nothing in-use can be deleted. This gem will throw appropriate errors
if you try to delete a configset that's being used by a collection, or try to delete
a collections that's pointed to by an alias.
Caveats
- At this point the API is unstable
- Solr has no sense of an atomic action and plenty of other ways
(e.g, the admin interface) to mess with things, so nothing is cached.
This means that individual actions can involve several round-trips to solr. If you're doing so much admin
that this becomes a bottleneck, you're well outside this gem's target case.
- While solr aliases can point to more than one collection at a time, this gem enforces one collection
per alias (although many aliases can point to the same collection)
Usage
The code below covers all the basics. See the docs for full sets of parameters, which errors are
thrown, etc.
Create a connection to the server
url = "http://localhost:9090/"
user = "solr"
password = "SolrRocks"
config_directory = "/path/to/myconfig/conf"
require "solr_cloud/connection"
server = SolrCloud::Connection.new(url: url, user: user, password: pass)
server.version_string
server.cloud?
server.mode
Configsets
server.configsets
server.configset_names
cset = server.create_configset(name: "horseless", confdir: config_directory)
server.configset_names
cset.delete!
cset = server.create_configset(name: "cars_cfg", confdir: config_directory)
server.configsets
server.create_configset(name: "cars_cfg", confdir: config_directory)
server.create_configset(name: "cars_cfg", confdir: config_directory, force: true)
cfg = server.get_configset("cars_cfg")
cfg.in_use?
Collections
cars_v1 = server.create_collection(name: "cars_v1", configset: "cars_cfg")
server.collections
server.collection_names
cars_v1.alive?
cars_v1.healthy?
cars_v1.count
cars_v1.aliased?
cars_v1.aliases
cars_v1.configset
cars_v1.commit
cfg.delete!
Aliases
cars = cars_v1.alias_as("cars")
cars_v1.alias?
cars_v1.aliased?
cars_v1.has_alias?("cars")
cars_v1.alias_as("autos")
cars_v1.aliases
cars_v1.get_alias("autos").delete!
cars_v1.aliases
cars_v2 = server.create_collection(name: "cars_v2", configset: "cars_cfg")
cars = server.get_alias("cars")
cars.collection
cars.switch_collection_to("cars_v2")
cars.collection
cars_v1.aliases
cars_v2.aliases
cars_v1.alias_as("cars")
cars_v2.alias_as!("cars")
cars.switch_collection_to("cars_v1")
server.collection_names
cars
cars == cars_v1
cars == cars_v2
server.only_collection_names
cars.alias?
cars_v1.alias?
cars.collection
Accessing objects from other objects
cv1 = server.get_collection("cars_v1")
cars = server.get_collection("cars")
typo = "cars_V1"
server.has_collection?(typo)
dne = server.get_collection(typo)
dne = server.get_collection!(typo)
cars.collection
cars_v1.collection
cars_v1.aliases
cars = cars_v1.get_alias("cars")
cfg = cars.configset
cfg.collections
Documentation
Run bundle exec rake docs
to generate the documentation in docs/
Installation
Install the gem and add to the application's Gemfile by executing:
$ bundle add solr_cloud-connection
If bundler is not being used to manage dependencies, install the gem by executing:
$ gem install solr_cloud-connection
Testing
This repository is set up to run tests under docker.
- docker compose build
- docker compose run app bundle install
- docker compose up
- docker compose run app bundle exec rspec
Contributing
Bugs, functionality suggestions, API suggestions, feature requests, etc. all welcome
on GitHub at https://github.com/mlibrary/solr_cloud-connection.