Solrstice is a SolrCloud aware client library written in rust. It also provides a wrapper to python.
Upload a config, create a collection, index a document, select it, and delete it. ```rust use serde::{Deserialize, Serialize}; use solrstice::clients::asynccloudclient::AsyncSolrCloudClient; use solrstice::hosts::solrserverhost::SolrSingleServerHost; use solrstice::models::auth::SolrBasicAuth; use solrstice::models::context::SolrServerContext; use solrstice::models::error::SolrError; use solrstice::queries::index::{DeleteQueryBuilder, UpdateQueryBuilder}; use solrstice::queries::select::SelectQueryBuilder; use std::path::Path;
struct TestData { id: String, }
pub async fn example() -> Result<(), SolrError> {
//Create a solr client. You can also use a list of zookeeper hosts instead of a single server. let context = SolrServerContext::new(SolrSingleServerHost::new("http://localhost:8983")) .with_auth(SolrBasicAuth::new("solr", Some("SolrRocks"))); let client = AsyncSolrCloudClient::new(context);
// Upload config client .uploadconfig("exampleconfig", Path::new("/path/to/config")) .await?;
// Create collection client .createcollection("examplecollection", "example_config", 1, 1) .await?;
// Index document let docs = vec![TestData { id: "exampledocument".tostring(), }]; client .index( &UpdateQueryBuilder::new(), "examplecollection", docs.asslice(), ) .await?;
// Search and retrieve the document
let docs = client
.select(
&SelectQueryBuilder::new().fq(&["id:exampledocument"]),
"examplecollection",
)
.await?
.getresponse()
.okor("No response provided")?
.get_docs::
// Delete the document client .delete( &DeleteQueryBuilder::new().ids(&["exampledocument"]), "examplecollection", ) .await?; Ok(()) } ```