RSolr

A Solr client for Rust.

Rsolr provides capabilities to manipulate and form requests to the Solr server, and contains some shorthands for them, with support for some facet features and query builder. It uses the blocking version of the reqwest http client.

## Select

You can retrieve documents as types with implemented Clone and Deserialize.

```rust use serdejson::Value; use rsolr::Client; use rsolr::error::RSolrError; use rsolr::solrresult::SolrResponse;

fn queryall() -> Result, RSolrError> { let result = Client::new("http://solr:8983", "collection") .select("*:*") .run::(); match result { Ok(solrresult) => Ok(solr_result.expect("Request is OK, but no response; in select it's a failure on Solr side.")), Err(e) => Err(e) } } ```

## Create

You can use types with implemented Clone and Serialize.

```rust

use serde::Serialize; use serde_json::Value; use rsolr::Client;

#[derive(Serialize, Clone)] struct SimpleDocument { field: Vec }

fn create() { let document = SimpleDocument { field: vec!("nice".tostring(), "document".tostring()) }; Client::new("http://solr:8983", "collection") .create(document) .run::().expect("panic, request failed."); } ``` ## Delete

rust use serde_json::Value; use rsolr::Client; fn delete() { Client::new("http://solr:8983", "collection") .delete("delete:query") .run::<Value>().expect("panic, request failed."); }

## Custom handler with params

You can define any handlers as well.

```rust

use serdejson::Value; use rsolr::Client; use rsolr::error::RSolrError; use rsolr::solrresult::SolrResponse; fn morelikethis() -> Result, RSolrError> { let result = Client::new("http://solr:8983", "collection") .requesthandler("mlt") .addqueryparam("mlt.fl", "similarityfield") .addqueryparam("mlt.mintf", "4") .addqueryparam("mlt.minwl", "3") .run::(); match result { Ok(solrresult) => Ok(solrresult.expect("Request is OK, but no response; in select it's a failure on Solr side.")), Err(e) => Err(e) } } ```

Development

I use Cargo Run Script to setup and manage a Solr locally. You'll also need a Docker. After checkout you should run

cargo run-script solr-start
cargo run-script solr-provision

Now you can reach your local Solr on http://localhost:8983. For testing I created a default collection without any schema def. Practically it means every value will be multivalue by default.