1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
//! # Stellr //! //! `Stellr` is a solr client library. //! //! It is still under active development, and definitely in an "alpha" state. //! //! The crate is heavily dependent on the reqwest and serde crates. The dependence on reqwest means //! stellr does not support the async-std/smol async runtime, but tokio is supported. //! //! The crate supports both non-Cloud and Cloud solr clients, and has non-Cloud and Cloud helper //! methods for both types of client. Output from requests can be structured with a user-defined //! type, or unstructured (using serde_json::Value instead). //! //! Stellr makes use of extension traits, so you will need to use the prelude for it to work. //! //! ## Examples //! //! Here is an example of a structured cloud request on a direct client //! //! ```no_run //! # use tokio::runtime::Runtime; //! # use std::error::Error; //! use stellr::prelude::*; //! use stellr::DirectSolrClient; //! use stellr::response_types::SolrSelectType; //! use serde::Deserialize; //! //! # fn main() -> Result<(), Box<dyn Error>> { //! #[allow(non_snake_case)] //! #[derive(Debug,Deserialize)] //! struct MatchingData { //! id: String, //! popularity: Option<u32>, //! inStock: bool, //! } //! //! let solr_client = DirectSolrClient::new("http://localhost:8983")?; //! let solr_request = solr_client //! .select("techproducts")? //! .rows(10) //! .q("id:SP251*") //! .fl("id,popularity,inStock"); //! //! # let mut rt = Runtime::new().unwrap(); //! let solr_response = //! # rt.block_on(async { //! solr_request //! .call::<SolrSelectType<MatchingData>>() //! .await //! # }) //! ?; //! //! assert_eq!(solr_response.response.docs.len(), 1); //! assert_eq!(solr_response.response.docs[0].popularity, Some(6)); //! # Ok(()) //! # } //! ``` //! //! and here's an example of an unstructured request on a cloud client //! //! ```no_run //! # use tokio::runtime::Runtime; //! # use std::error::Error; //! use stellr::prelude::*; //! use stellr::ZkSolrClient; //! //! # fn main() -> Result<(), Box<dyn Error>> { //! let solr_client = ZkSolrClient::new("localhost:9983", "/")?; //! let solr_request = solr_client //! .select("gettingstarted")? //! .rows(10) //! .q("*:*"); //! //! # let mut rt = Runtime::new().unwrap(); //! let result_struct = //! # rt.block_on(async { //! solr_request //! .unstructured_call() //! .await //! # }) //! ; //! //! let docs_count = result_struct? //! .get("response").unwrap() //! .get("docs").unwrap() //! .as_array().unwrap() //! .len(); //! //! assert_eq!(10, docs_count); //! # Ok(()) //! # } //! ``` //! //! Finally here is an example of data insertion //! //! ```no_run //! # use tokio::runtime::Runtime; //! # use std::error::Error; //! use stellr::prelude::*; //! use stellr::DirectSolrClient; //! use stellr::response_types::SolrUpdateType; //! use serde::Serialize; //! //! #[allow(non_snake_case)] //! #[derive(Serialize)] //! struct MyData { //! id: String, //! important_number: u32, //! } //! //! # fn main() -> Result<(), Box<dyn Error>> { //! # let mut rt = Runtime::new().unwrap(); //! let solr_client = DirectSolrClient::new("http://localhost:8983")?; //! let my_data = vec!(MyData {id: String::from("random-extra-value"), important_number: 42},); //! let solr_request = solr_client //! .update("films")? //! .payload(&my_data)? //! .commit(); //! //! let result_struct = //! # rt.block_on(async { //! solr_request //! .call::<SolrUpdateType>() //! .await //! # }); //! //! assert_eq!(result_struct?.responseHeader.status, 0); //! # Ok(()) } //! ``` //! //! ## Package Features //! //! The crate only has one optional feature: //! //! * `blocking` - use the blocking feature of the reqwest library, rather than the async version //! //! ## Errors //! //! Stellr defines a `SolrError` struct, which wraps errors types from the serde, reqwest and //! zookeeper crates. //! //! ## Safety //! //! This crate introduces no new unsafe code, beyond what already exists in it's dependencies. #![allow(non_snake_case)] #[doc(inline)] pub use clients::{ DirectSolrClient, SolrClientBuilder, SolrCloudMethods, SolrCoreMethods, ZkSolrClient, }; pub use config::SolrClientConfig; pub use errors::{SolrError, SolrResult}; #[doc(inline)] pub use requests::{SolrRequest, SolrRequestBuilder}; mod clients; mod config; mod errors; pub mod prelude; mod requests; pub mod response_types;