Solrstice Docs

Introduction

Solrstice is a library for interacting with an Apache Solr cluster Currently version 8 and 9 is supported. The library is written in Rust, and has a wrapper to Python. Both async and blocking are supported in both languages.

Rust

You can install the library by putting this in your Cargo.toml

solrstice = { version = "0.9.0", features = ["blocking"] }

If the blocking feature is not provided, only async will work.

Python

pip install solrstice

Getting started

Creating a client

#![allow(unused)]
fn main() {
 use solrstice::AsyncSolrCloudClient;
 use solrstice::SolrSingleServerHost;
 use solrstice::SolrServerContextBuilder;
 let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).build();
 let client = AsyncSolrCloudClient::new(context);
}

Creating a collection

#![allow(unused)]
fn main() {
 use solrstice::AsyncSolrCloudClient;
 use solrstice::SolrSingleServerHost;
 use solrstice::SolrServerContextBuilder;
 use std::path::Path;
 async fn run() -> Result<(), Box<dyn std::error::Error>> {
 let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("")).build();
 let client = AsyncSolrCloudClient::new(context);
 client
    .upload_config("example_config", Path::new("/path/to/config"))
    .await?;
 client
    .create_collection("example_collection", "example_config", 1, 1)
    .await?;
     Ok(())
  }
}

Indexing data

#![allow(unused)]
fn main() {
 use solrstice::AsyncSolrCloudClient;
 use solrstice::SolrSingleServerHost;
 use solrstice::SolrServerContextBuilder;
 use solrstice::UpdateQuery;
 use serde::{Serialize, Deserialize};

 #[derive(Serialize, Deserialize, Debug)]
 struct TestData {
     id: String,
 }
 async fn run() -> Result<(), Box<dyn std::error::Error>> {
 let docs = vec![TestData {
     id: "example_document".to_string(),
 }];

 let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("")).build();
 let client = AsyncSolrCloudClient::new(context);
 client
     .index(&UpdateQuery::new(), "example_collection", docs.as_slice())
     .await?;
 Ok(())
 }
}

Selecting data

#![allow(unused)]
fn main() {
 use solrstice::AsyncSolrCloudClient;
 use solrstice::SolrSingleServerHost;
 use solrstice::SolrServerContextBuilder;
 use solrstice::SelectQuery;
 use serde::{Serialize, Deserialize};
 async fn run() -> Result<(), Box<dyn std::error::Error>> {
 let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).build();
 let client = AsyncSolrCloudClient::new(context);
 #[derive(Serialize, Deserialize, Debug)]
 struct TestData {
     id: String,
 }
 let docs = client
     .select(
         &SelectQuery::new()
         .fq(["id:example_document"]),
         "example_collection",
     )
 .await?
 .get_docs_response()
 .ok_or("No response provided")?
 .get_docs::<TestData>()?;
 Ok(())
 }
}

Deleting data

#![allow(unused)]
fn main() {
 use solrstice::AsyncSolrCloudClient;
 use solrstice::SolrSingleServerHost;
 use solrstice::SolrServerContextBuilder;
 use solrstice::DeleteQuery;
 async fn run() -> Result<(), Box<dyn std::error::Error>> {
 let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).build();
 let client = AsyncSolrCloudClient::new(context);
 client
     .delete(
         &DeleteQuery::new().ids(["example_document"]),
         "example_collection",
     )
 .await?;
 Ok(())
 }
}