From 44e2b74593aed97ca5baae8a0e2bc2ee294b519a Mon Sep 17 00:00:00 2001 From: Sh1nku <42642351+Sh1nku@users.noreply.github.com> Date: Fri, 26 Jul 2024 00:41:41 +0200 Subject: [PATCH 1/5] Restructure Rust crate --- README.md | 16 +- framework/README.md | 12 +- framework/src/clients/async_cloud_client.rs | 138 ++++++++--------- .../src/clients/blocking_cloud_client.rs | 144 +++++++++--------- framework/src/clients/mod.rs | 8 +- framework/src/docs/create_client_test.rs | 6 +- framework/src/docs/create_collection_test.rs | 6 +- framework/src/docs/delete_data_test.rs | 8 +- framework/src/docs/index_data_test.rs | 8 +- framework/src/docs/select_data_test.rs | 8 +- framework/src/{models => }/error.rs | 10 +- framework/src/hosts/mod.rs | 16 +- framework/src/hosts/solr_host.rs | 4 +- framework/src/hosts/solr_server_host.rs | 26 ++-- framework/src/hosts/zookeeper_host.rs | 38 ++--- framework/src/lib.rs | 42 +++-- framework/src/models/auth.rs | 4 +- framework/src/models/commit_type.rs | 3 +- framework/src/models/context.rs | 32 ++-- framework/src/models/facet_set.rs | 8 +- framework/src/models/group.rs | 56 +++---- framework/src/models/json_facet.rs | 8 +- framework/src/models/mod.rs | 21 +-- framework/src/models/response.rs | 28 +--- framework/src/queries/alias.rs | 20 +-- framework/src/queries/collection.rs | 20 +-- framework/src/queries/components/facet_set.rs | 95 ++++-------- framework/src/queries/components/grouping.rs | 30 ++-- .../src/queries/components/json_facet.rs | 82 +++------- framework/src/queries/components/mod.rs | 6 +- framework/src/queries/config.rs | 26 ++-- framework/src/queries/def_type.rs | 36 ++--- framework/src/queries/index.rs | 71 ++++----- framework/src/queries/mod.rs | 8 +- framework/src/queries/request_builder.rs | 19 +-- framework/src/queries/select.rs | 48 +++--- framework/src/runtime.rs | 2 +- framework/tests/functionality/auth_test.rs | 28 ++-- framework/tests/functionality/client_tests.rs | 6 +- framework/tests/functionality/config_test.rs | 12 +- .../tests/functionality/def_type_test.rs | 14 +- .../tests/functionality/facetset_test.rs | 20 ++- .../tests/functionality/grouping_tests.rs | 28 ++-- framework/tests/functionality/index_test.rs | 10 +- .../tests/functionality/json_facet_test.rs | 18 +-- framework/tests/functionality/logging_test.rs | 16 +- framework/tests/functionality/readme_test.rs | 16 +- framework/tests/functionality/select_test.rs | 12 +- framework/tests/functionality/zk_test.rs | 4 +- framework/tests/structures.rs | 18 +-- wrappers/python/src/hosts.rs | 10 +- wrappers/python/src/models/auth.rs | 2 +- wrappers/python/src/models/context.rs | 4 +- wrappers/python/src/models/error.rs | 6 +- wrappers/python/src/models/facet_set.rs | 4 +- wrappers/python/src/models/group.rs | 2 +- wrappers/python/src/models/json_facet.rs | 2 +- wrappers/python/src/models/response.rs | 2 +- wrappers/python/src/queries/alias.rs | 2 +- wrappers/python/src/queries/collection.rs | 2 +- .../src/queries/components/facet_set.rs | 2 +- .../python/src/queries/components/grouping.rs | 2 +- .../src/queries/components/json_facet.rs | 4 +- wrappers/python/src/queries/config.rs | 2 +- wrappers/python/src/queries/def_type.rs | 4 +- wrappers/python/src/queries/index.rs | 16 +- wrappers/python/src/queries/select.rs | 18 +-- 67 files changed, 602 insertions(+), 797 deletions(-) rename framework/src/{models => }/error.rs (86%) diff --git a/README.md b/README.md index b89e54d..cc22053 100644 --- a/README.md +++ b/README.md @@ -22,13 +22,13 @@ Upload a config, create a collection, index a document, select it, and delete it ### Rust ```rust use serde::{Deserialize, Serialize}; -use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; -use solrstice::hosts::solr_server_host::SolrSingleServerHost; -use solrstice::models::auth::SolrBasicAuth; -use solrstice::models::context::SolrServerContextBuilder; -use solrstice::models::error::SolrError; -use solrstice::queries::index::{DeleteQuery, UpdateQuery}; -use solrstice::queries::select::SelectQuery; +use solrstice::AsyncSolrCloudClient; +use solrstice::SolrSingleServerHost; +use solrstice::SolrBasicAuth; +use solrstice::SolrServerContextBuilder; +use solrstice::Error; +use solrstice::{DeleteQuery, UpdateQuery}; +use solrstice::SelectQuery; use std::path::Path; #[derive(Serialize, Deserialize, Debug)] @@ -37,7 +37,7 @@ struct TestData { } #[tokio::test] -pub async fn example() -> Result<(), SolrError> { +pub async fn example() -> Result<(), Error> { //Create a solr client. You can also use a list of zookeeper hosts instead of a single server. let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")) diff --git a/framework/README.md b/framework/README.md index 2c91a86..e52d1fb 100644 --- a/framework/README.md +++ b/framework/README.md @@ -19,13 +19,13 @@ 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::async_cloud_client::AsyncSolrCloudClient; -use solrstice::hosts::solr_server_host::SolrSingleServerHost; -use solrstice::models::auth::SolrBasicAuth; -use solrstice::models::context::SolrServerContextBuilder; +use solrstice::AsyncSolrCloudClient; +use solrstice::SolrSingleServerHost; +use solrstice::SolrBasicAuth; +use solrstice::SolrServerContextBuilder; use solrstice::models::error::SolrError; -use solrstice::queries::index::{DeleteQuery, UpdateQuery}; -use solrstice::queries::select::SelectQuery; +use solrstice::{DeleteQuery, UpdateQuery}; +use solrstice::SelectQuery; use std::path::Path; #[derive(Serialize, Deserialize, Debug)] diff --git a/framework/src/clients/async_cloud_client.rs b/framework/src/clients/async_cloud_client.rs index 18174f4..e4fb84b 100644 --- a/framework/src/clients/async_cloud_client.rs +++ b/framework/src/clients/async_cloud_client.rs @@ -1,5 +1,5 @@ +use crate::error::Error; use crate::models::context::SolrServerContext; -use crate::models::error::SolrError; use crate::models::response::SolrResponse; use crate::queries::alias::{alias_exists, create_alias, delete_alias, get_aliases}; use crate::queries::collection::{ @@ -15,10 +15,7 @@ use std::path::Path; /// Async client for SolrCloud /// # Examples /// ```rust -/// use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; -/// use solrstice::hosts::solr_server_host::SolrSingleServerHost; -/// use solrstice::models::context::SolrServerContextBuilder; -/// +/// use solrstice::{AsyncSolrCloudClient, SolrServerContextBuilder, SolrSingleServerHost}; /// let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).build(); /// let client = AsyncSolrCloudClient::new(context); /// ``` @@ -32,10 +29,7 @@ impl AsyncSolrCloudClient { /// Create a new instance of AsyncSolrCloudClient /// # Examples /// ```rust - /// use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; - /// use solrstice::hosts::solr_server_host::SolrSingleServerHost; - /// use solrstice::models::context::SolrServerContextBuilder; - /// + /// use solrstice::{AsyncSolrCloudClient, SolrServerContextBuilder, SolrSingleServerHost}; /// let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).build(); /// let client = AsyncSolrCloudClient::new(context); /// ``` @@ -49,9 +43,7 @@ impl AsyncSolrCloudClient { /// # Examples /// ```no_run /// # use std::path::Path; - /// # use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; - /// # use solrstice::hosts::solr_server_host::SolrSingleServerHost; - /// # use solrstice::models::context::SolrServerContextBuilder; + /// # use solrstice::{AsyncSolrCloudClient, SolrServerContextBuilder, SolrSingleServerHost}; /// # async fn run() -> Result<(), Box> { /// let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).build(); /// let client = AsyncSolrCloudClient::new(context); @@ -63,7 +55,7 @@ impl AsyncSolrCloudClient { &self, name: N, path: P, - ) -> Result<(), SolrError> { + ) -> Result<(), Error> { upload_config(&self.context, name, path).await } @@ -71,9 +63,9 @@ impl AsyncSolrCloudClient { /// # Examples /// ```no_run /// # use std::path::Path; - /// # use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; - /// # use solrstice::hosts::solr_server_host::SolrSingleServerHost; - /// # use solrstice::models::context::SolrServerContextBuilder; + /// # use solrstice::AsyncSolrCloudClient; + /// # use solrstice::SolrSingleServerHost; + /// # use solrstice::SolrServerContextBuilder; /// # async fn run() -> Result<(), Box> { /// let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).build(); /// let client = AsyncSolrCloudClient::new(context); @@ -81,7 +73,7 @@ impl AsyncSolrCloudClient { /// # Ok(()) /// # } /// ``` - pub async fn get_configs(&self) -> Result, SolrError> { + pub async fn get_configs(&self) -> Result, Error> { get_configs(&self.context).await } @@ -89,9 +81,9 @@ impl AsyncSolrCloudClient { /// # Examples /// ```no_run /// # use std::path::Path; - /// # use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; - /// # use solrstice::hosts::solr_server_host::SolrSingleServerHost; - /// # use solrstice::models::context::SolrServerContextBuilder; + /// # use solrstice::AsyncSolrCloudClient; + /// # use solrstice::SolrSingleServerHost; + /// # use solrstice::SolrServerContextBuilder; /// # async fn run() -> Result<(), Box> { /// let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).build(); /// let client = AsyncSolrCloudClient::new(context); @@ -99,7 +91,7 @@ impl AsyncSolrCloudClient { /// # Ok(()) /// # } /// ``` - pub async fn config_exists>(&self, name: S) -> Result { + pub async fn config_exists>(&self, name: S) -> Result { config_exists(&self.context, name).await } @@ -107,9 +99,9 @@ impl AsyncSolrCloudClient { /// # Examples /// ```no_run /// # use std::path::Path; - /// # use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; - /// # use solrstice::hosts::solr_server_host::SolrSingleServerHost; - /// # use solrstice::models::context::SolrServerContextBuilder; + /// # use solrstice::AsyncSolrCloudClient; + /// # use solrstice::SolrSingleServerHost; + /// # use solrstice::SolrServerContextBuilder; /// # async fn run() -> Result<(), Box> { /// let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).build(); /// let client = AsyncSolrCloudClient::new(context); @@ -117,16 +109,16 @@ impl AsyncSolrCloudClient { /// # Ok(()) /// # } /// ``` - pub async fn delete_config>(&self, name: N) -> Result<(), SolrError> { + pub async fn delete_config>(&self, name: N) -> Result<(), Error> { delete_config(&self.context, name).await } /// Create a collection in SolrCloud /// # Examples /// ```no_run - /// # use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; - /// # use solrstice::hosts::solr_server_host::SolrSingleServerHost; - /// # use solrstice::models::context::SolrServerContextBuilder; + /// # use solrstice::AsyncSolrCloudClient; + /// # use solrstice::SolrSingleServerHost; + /// # use solrstice::SolrServerContextBuilder; /// # async fn run() -> Result<(), Box> { /// let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).build(); /// let client = AsyncSolrCloudClient::new(context); @@ -140,16 +132,16 @@ impl AsyncSolrCloudClient { config: S, shards: usize, replication_factor: usize, - ) -> Result<(), SolrError> { + ) -> Result<(), Error> { create_collection(&self.context, name, config, shards, replication_factor).await } /// Get collections from SolrCloud /// # Examples /// ```no_run - /// # use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; - /// # use solrstice::hosts::solr_server_host::SolrSingleServerHost; - /// # use solrstice::models::context::SolrServerContextBuilder; + /// # use solrstice::AsyncSolrCloudClient; + /// # use solrstice::SolrSingleServerHost; + /// # use solrstice::SolrServerContextBuilder; /// # async fn run() -> Result<(), Box> { /// let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).build(); /// let client = AsyncSolrCloudClient::new(context); @@ -157,16 +149,16 @@ impl AsyncSolrCloudClient { /// # Ok(()) /// # } /// ``` - pub async fn get_collections(&self) -> Result, SolrError> { + pub async fn get_collections(&self) -> Result, Error> { get_collections(&self.context).await } /// Check if a collection exists in SolrCloud /// # Examples /// ```no_run - /// # use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; - /// # use solrstice::hosts::solr_server_host::SolrSingleServerHost; - /// # use solrstice::models::context::SolrServerContextBuilder; + /// # use solrstice::AsyncSolrCloudClient; + /// # use solrstice::SolrSingleServerHost; + /// # use solrstice::SolrServerContextBuilder; /// # async fn run() -> Result<(), Box> { /// let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).build(); /// let client = AsyncSolrCloudClient::new(context); @@ -174,16 +166,16 @@ impl AsyncSolrCloudClient { /// # Ok(()) /// # } /// ``` - pub async fn collection_exists<'a, S: AsRef>(&self, name: S) -> Result { + pub async fn collection_exists<'a, S: AsRef>(&self, name: S) -> Result { collection_exists(&self.context, name).await } /// Delete a collection from SolrCloud /// # Examples /// ```no_run - /// # use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; - /// # use solrstice::hosts::solr_server_host::SolrSingleServerHost; - /// # use solrstice::models::context::SolrServerContextBuilder; + /// # use solrstice::AsyncSolrCloudClient; + /// # use solrstice::SolrSingleServerHost; + /// # use solrstice::SolrServerContextBuilder; /// # async fn run() -> Result<(), Box> { /// let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).build(); /// let client = AsyncSolrCloudClient::new(context); @@ -191,16 +183,16 @@ impl AsyncSolrCloudClient { /// # Ok(()) /// # } /// ``` - pub async fn delete_collection>(&self, name: N) -> Result<(), SolrError> { + pub async fn delete_collection>(&self, name: N) -> Result<(), Error> { delete_collection(&self.context, name).await } /// Create an alias in SolrCloud /// # Examples /// ```no_run - /// # use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; - /// # use solrstice::hosts::solr_server_host::SolrSingleServerHost; - /// # use solrstice::models::context::SolrServerContextBuilder; + /// # use solrstice::AsyncSolrCloudClient; + /// # use solrstice::SolrSingleServerHost; + /// # use solrstice::SolrServerContextBuilder; /// # async fn run() -> Result<(), Box> { /// let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).build(); /// let client = AsyncSolrCloudClient::new(context); @@ -212,7 +204,7 @@ impl AsyncSolrCloudClient { &self, alias: S, collections: &[S], - ) -> Result<(), SolrError> { + ) -> Result<(), Error> { create_alias(&self.context, alias, collections).await } @@ -220,9 +212,9 @@ impl AsyncSolrCloudClient { /// # Examples /// ```no_run /// # use std::collections::HashMap; - /// # use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; - /// # use solrstice::hosts::solr_server_host::SolrSingleServerHost; - /// # use solrstice::models::context::SolrServerContextBuilder; + /// # use solrstice::AsyncSolrCloudClient; + /// # use solrstice::SolrSingleServerHost; + /// # use solrstice::SolrServerContextBuilder; /// # async fn run() -> Result<(), Box> { /// let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).build(); /// let client = AsyncSolrCloudClient::new(context); @@ -230,16 +222,16 @@ impl AsyncSolrCloudClient { /// # Ok(()) /// # } /// ``` - pub async fn get_aliases(&self) -> Result>, SolrError> { + pub async fn get_aliases(&self) -> Result>, Error> { get_aliases(&self.context).await } /// Check if an alias exists in SolrCloud /// # Examples /// ```no_run - /// # use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; - /// # use solrstice::hosts::solr_server_host::SolrSingleServerHost; - /// # use solrstice::models::context::SolrServerContextBuilder; + /// # use solrstice::AsyncSolrCloudClient; + /// # use solrstice::SolrSingleServerHost; + /// # use solrstice::SolrServerContextBuilder; /// # async fn run() -> Result<(), Box> { /// let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).build(); /// let client = AsyncSolrCloudClient::new(context); @@ -247,16 +239,16 @@ impl AsyncSolrCloudClient { /// # Ok(()) /// # } /// ``` - pub async fn alias_exists>(&self, name: N) -> Result { + pub async fn alias_exists>(&self, name: N) -> Result { alias_exists(&self.context, name).await } /// Delete an alias from SolrCloud /// # Examples /// ```no_run - /// # use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; - /// # use solrstice::hosts::solr_server_host::SolrSingleServerHost; - /// # use solrstice::models::context::SolrServerContextBuilder; + /// # use solrstice::AsyncSolrCloudClient; + /// # use solrstice::SolrSingleServerHost; + /// # use solrstice::SolrServerContextBuilder; /// # async fn run() -> Result<(), Box> { /// let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).build(); /// let client = AsyncSolrCloudClient::new(context); @@ -264,17 +256,17 @@ impl AsyncSolrCloudClient { /// # Ok(()) /// # } /// ``` - pub async fn delete_alias>(&self, name: S) -> Result<(), SolrError> { + pub async fn delete_alias>(&self, name: S) -> Result<(), Error> { delete_alias(&self.context, name).await } /// Index some data into SolrCloud /// # Examples /// ```no_run - /// # use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; - /// # use solrstice::hosts::solr_server_host::SolrSingleServerHost; - /// # use solrstice::models::context::SolrServerContextBuilder; - /// # use solrstice::queries::index::UpdateQuery; + /// # use solrstice::AsyncSolrCloudClient; + /// # use solrstice::SolrSingleServerHost; + /// # use solrstice::SolrServerContextBuilder; + /// # use solrstice::UpdateQuery; /// # use serde::Serialize; /// # async fn run() -> Result<(), Box> { /// #[derive(Serialize)] @@ -291,7 +283,7 @@ impl AsyncSolrCloudClient { builder: B, collection: C, data: &[T], - ) -> Result { + ) -> Result { builder .as_ref() .execute(&self.context, collection, data) @@ -301,10 +293,10 @@ impl AsyncSolrCloudClient { /// Select some data from SolrCloud /// # Examples /// ```no_run - /// # use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; - /// # use solrstice::hosts::solr_server_host::SolrSingleServerHost; - /// # use solrstice::models::context::SolrServerContextBuilder; - /// # use solrstice::queries::select::SelectQuery; + /// # use solrstice::AsyncSolrCloudClient; + /// # use solrstice::SolrSingleServerHost; + /// # use solrstice::SolrServerContextBuilder; + /// # use solrstice::SelectQuery; /// # async fn run() -> Result<(), Box> { /// let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).build(); /// let client = AsyncSolrCloudClient::new(context); @@ -316,18 +308,18 @@ impl AsyncSolrCloudClient { &self, builder: B, collection: C, - ) -> Result { + ) -> Result { builder.as_ref().execute(&self.context, collection).await } /// Delete some data from SolrCloud /// # Examples /// ```no_run - /// # use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; - /// # use solrstice::hosts::solr_server_host::SolrSingleServerHost; - /// # use solrstice::models::context::SolrServerContextBuilder; - /// # use solrstice::queries::index::DeleteQuery; - /// # use solrstice::queries::select::SelectQuery; + /// # use solrstice::AsyncSolrCloudClient; + /// # use solrstice::SolrSingleServerHost; + /// # use solrstice::SolrServerContextBuilder; + /// # use solrstice::DeleteQuery; + /// # use solrstice::SelectQuery; /// # async fn run() -> Result<(), Box> { /// let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).build(); /// let client = AsyncSolrCloudClient::new(context); @@ -339,7 +331,7 @@ impl AsyncSolrCloudClient { &self, builder: B, collection: C, - ) -> Result { + ) -> Result { builder.as_ref().execute(&self.context, collection).await } } diff --git a/framework/src/clients/blocking_cloud_client.rs b/framework/src/clients/blocking_cloud_client.rs index 14c53ff..50bdae2 100644 --- a/framework/src/clients/blocking_cloud_client.rs +++ b/framework/src/clients/blocking_cloud_client.rs @@ -1,5 +1,5 @@ +use crate::error::Error; use crate::models::context::SolrServerContext; -use crate::models::error::SolrError; use crate::models::response::SolrResponse; use crate::queries::alias::{ alias_exists_blocking, create_alias_blocking, delete_alias_blocking, get_aliases_blocking, @@ -20,9 +20,7 @@ use std::path::Path; /// A blocking client for SolrCloud. /// # Examples /// ```rust -/// use solrstice::clients::blocking_cloud_client::BlockingSolrCloudClient; -/// use solrstice::hosts::solr_server_host::SolrSingleServerHost; -/// use solrstice::models::context::SolrServerContextBuilder; +/// use solrstice::{BlockingSolrCloudClient, SolrServerContextBuilder, SolrSingleServerHost}; /// /// let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).build(); /// let client = BlockingSolrCloudClient::new(context); @@ -37,9 +35,7 @@ impl BlockingSolrCloudClient { /// Create a new instance of BlockingSolrCloudClient /// # Examples /// ```rust - /// use solrstice::clients::blocking_cloud_client::BlockingSolrCloudClient; - /// use solrstice::hosts::solr_server_host::SolrSingleServerHost; - /// use solrstice::models::context::SolrServerContextBuilder; + /// use solrstice::{BlockingSolrCloudClient, SolrServerContextBuilder, SolrSingleServerHost}; /// /// let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).build(); /// let client = BlockingSolrCloudClient::new(context); @@ -54,9 +50,9 @@ impl BlockingSolrCloudClient { /// # Examples /// ```no_run /// # use std::path::Path; - /// # use solrstice::clients::blocking_cloud_client::BlockingSolrCloudClient; - /// # use solrstice::hosts::solr_server_host::SolrSingleServerHost; - /// # use solrstice::models::context::SolrServerContextBuilder; + /// # use solrstice::BlockingSolrCloudClient; + /// # use solrstice::SolrSingleServerHost; + /// # use solrstice::SolrServerContextBuilder; /// # fn run() -> Result<(), Box> { /// let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).build(); /// let client = BlockingSolrCloudClient::new(context); @@ -68,7 +64,7 @@ impl BlockingSolrCloudClient { &self, name: S, path: P, - ) -> Result<(), SolrError> { + ) -> Result<(), Error> { upload_config_blocking(&self.context, name, path) } @@ -76,9 +72,9 @@ impl BlockingSolrCloudClient { /// # Examples /// ```no_run /// # use std::path::Path; - /// # use solrstice::clients::blocking_cloud_client::BlockingSolrCloudClient; - /// # use solrstice::hosts::solr_server_host::SolrSingleServerHost; - /// # use solrstice::models::context::SolrServerContextBuilder; + /// # use solrstice::BlockingSolrCloudClient; + /// # use solrstice::SolrSingleServerHost; + /// # use solrstice::SolrServerContextBuilder; /// # fn run() -> Result<(), Box> { /// let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).build(); /// let client = BlockingSolrCloudClient::new(context); @@ -86,7 +82,7 @@ impl BlockingSolrCloudClient { /// # Ok(()) /// # } /// ``` - pub fn get_configs(&self) -> Result, SolrError> { + pub fn get_configs(&self) -> Result, Error> { get_configs_blocking(&self.context) } @@ -94,9 +90,9 @@ impl BlockingSolrCloudClient { /// # Examples /// ```no_run /// # use std::path::Path; - /// # use solrstice::clients::blocking_cloud_client::BlockingSolrCloudClient; - /// # use solrstice::hosts::solr_server_host::SolrSingleServerHost; - /// # use solrstice::models::context::SolrServerContextBuilder; + /// # use solrstice::BlockingSolrCloudClient; + /// # use solrstice::SolrSingleServerHost; + /// # use solrstice::SolrServerContextBuilder; /// # fn run() -> Result<(), Box> { /// let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).build(); /// let client = BlockingSolrCloudClient::new(context); @@ -104,7 +100,7 @@ impl BlockingSolrCloudClient { /// # Ok(()) /// # } /// ``` - pub fn config_exists>(&self, name: S) -> Result { + pub fn config_exists>(&self, name: S) -> Result { config_exists_blocking(&self.context, name) } @@ -112,9 +108,9 @@ impl BlockingSolrCloudClient { /// # Examples /// ```no_run /// # use std::path::Path; - /// # use solrstice::clients::blocking_cloud_client::BlockingSolrCloudClient; - /// # use solrstice::hosts::solr_server_host::SolrSingleServerHost; - /// # use solrstice::models::context::SolrServerContextBuilder; + /// # use solrstice::BlockingSolrCloudClient; + /// # use solrstice::SolrSingleServerHost; + /// # use solrstice::SolrServerContextBuilder; /// # fn run() -> Result<(), Box> { /// let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).build(); /// let client = BlockingSolrCloudClient::new(context); @@ -122,16 +118,16 @@ impl BlockingSolrCloudClient { /// # Ok(()) /// # } /// ``` - pub fn delete_config>(&self, name: S) -> Result<(), SolrError> { + pub fn delete_config>(&self, name: S) -> Result<(), Error> { delete_config_blocking(&self.context, name) } /// Create a collection in SolrCloud /// # Examples /// ```no_run - /// # use solrstice::clients::blocking_cloud_client::BlockingSolrCloudClient; - /// # use solrstice::hosts::solr_server_host::SolrSingleServerHost; - /// # use solrstice::models::context::SolrServerContextBuilder; + /// # use solrstice::BlockingSolrCloudClient; + /// # use solrstice::SolrSingleServerHost; + /// # use solrstice::SolrServerContextBuilder; /// # fn run() -> Result<(), Box> { /// let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).build(); /// let client = BlockingSolrCloudClient::new(context); @@ -145,17 +141,17 @@ impl BlockingSolrCloudClient { config: S, shards: usize, replication_factor: usize, - ) -> Result<(), SolrError> { + ) -> Result<(), Error> { create_collection_blocking(&self.context, name, config, shards, replication_factor) } /// Get collections from SolrCloud /// # Examples /// ```no_run - /// # use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; - /// use solrstice::clients::blocking_cloud_client::BlockingSolrCloudClient; - /// # use solrstice::hosts::solr_server_host::SolrSingleServerHost; - /// # use solrstice::models::context::SolrServerContextBuilder; + /// # use solrstice::AsyncSolrCloudClient; + /// use solrstice::BlockingSolrCloudClient; + /// # use solrstice::SolrSingleServerHost; + /// # use solrstice::SolrServerContextBuilder; /// # fn run() -> Result<(), Box> { /// let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).build(); /// let client = BlockingSolrCloudClient::new(context); @@ -163,16 +159,16 @@ impl BlockingSolrCloudClient { /// # Ok(()) /// # } /// ``` - pub fn get_collections(&self) -> Result, SolrError> { + pub fn get_collections(&self) -> Result, Error> { get_collections_blocking(&self.context) } /// Check if a collection exists in SolrCloud /// # Examples /// ```no_run - /// # use solrstice::clients::blocking_cloud_client::BlockingSolrCloudClient; - /// # use solrstice::hosts::solr_server_host::SolrSingleServerHost; - /// # use solrstice::models::context::SolrServerContextBuilder; + /// # use solrstice::BlockingSolrCloudClient; + /// # use solrstice::SolrSingleServerHost; + /// # use solrstice::SolrServerContextBuilder; /// # async fn run() -> Result<(), Box> { /// let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).build(); /// let client = BlockingSolrCloudClient::new(context); @@ -180,16 +176,16 @@ impl BlockingSolrCloudClient { /// # Ok(()) /// # } /// ``` - pub fn collection_exists>(&self, name: S) -> Result { + pub fn collection_exists>(&self, name: S) -> Result { collection_exists_blocking(&self.context, name) } /// Delete a collection from SolrCloud /// # Examples /// ```no_run - /// # use solrstice::clients::blocking_cloud_client::BlockingSolrCloudClient; - /// # use solrstice::hosts::solr_server_host::SolrSingleServerHost; - /// # use solrstice::models::context::SolrServerContextBuilder; + /// # use solrstice::BlockingSolrCloudClient; + /// # use solrstice::SolrSingleServerHost; + /// # use solrstice::SolrServerContextBuilder; /// # fn run() -> Result<(), Box> { /// let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).build(); /// let client = BlockingSolrCloudClient::new(context); @@ -197,16 +193,16 @@ impl BlockingSolrCloudClient { /// # Ok(()) /// # } /// ``` - pub fn delete_collection>(&self, name: S) -> Result<(), SolrError> { + pub fn delete_collection>(&self, name: S) -> Result<(), Error> { delete_collection_blocking(&self.context, name) } /// Create an alias in SolrCloud /// # Examples /// ```no_run - /// # use solrstice::clients::blocking_cloud_client::BlockingSolrCloudClient; - /// # use solrstice::hosts::solr_server_host::SolrSingleServerHost; - /// # use solrstice::models::context::SolrServerContextBuilder; + /// # use solrstice::BlockingSolrCloudClient; + /// # use solrstice::SolrSingleServerHost; + /// # use solrstice::SolrServerContextBuilder; /// # fn run() -> Result<(), Box> { /// let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).build(); /// let client = BlockingSolrCloudClient::new(context); @@ -214,11 +210,7 @@ impl BlockingSolrCloudClient { /// # Ok(()) /// # } /// ``` - pub fn create_alias>( - &self, - alias: S, - collections: &[S], - ) -> Result<(), SolrError> { + pub fn create_alias>(&self, alias: S, collections: &[S]) -> Result<(), Error> { create_alias_blocking(&self.context, alias, collections) } @@ -226,9 +218,9 @@ impl BlockingSolrCloudClient { /// # Examples /// ```no_run /// # use std::collections::HashMap; - /// # use solrstice::clients::blocking_cloud_client::BlockingSolrCloudClient; - /// # use solrstice::hosts::solr_server_host::SolrSingleServerHost; - /// # use solrstice::models::context::SolrServerContextBuilder; + /// # use solrstice::BlockingSolrCloudClient; + /// # use solrstice::SolrSingleServerHost; + /// # use solrstice::SolrServerContextBuilder; /// # fn run() -> Result<(), Box> { /// let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).build(); /// let client = BlockingSolrCloudClient::new(context); @@ -236,16 +228,16 @@ impl BlockingSolrCloudClient { /// # Ok(()) /// # } /// ``` - pub fn get_aliases(&self) -> Result>, SolrError> { + pub fn get_aliases(&self) -> Result>, Error> { get_aliases_blocking(&self.context) } /// Check if an alias exists in SolrCloud /// # Examples /// ```no_run - /// # use solrstice::clients::blocking_cloud_client::BlockingSolrCloudClient; - /// # use solrstice::hosts::solr_server_host::SolrSingleServerHost; - /// # use solrstice::models::context::SolrServerContextBuilder; + /// # use solrstice::BlockingSolrCloudClient; + /// # use solrstice::SolrSingleServerHost; + /// # use solrstice::SolrServerContextBuilder; /// # fn run() -> Result<(), Box> { /// let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).build(); /// let client = BlockingSolrCloudClient::new(context); @@ -253,16 +245,16 @@ impl BlockingSolrCloudClient { /// # Ok(()) /// # } /// ``` - pub fn alias_exists>(&self, name: S) -> Result { + pub fn alias_exists>(&self, name: S) -> Result { alias_exists_blocking(&self.context, name) } /// Delete an alias from SolrCloud /// # Examples /// ```no_run - /// use solrstice::clients::blocking_cloud_client::BlockingSolrCloudClient; - /// # use solrstice::hosts::solr_server_host::SolrSingleServerHost; - /// # use solrstice::models::context::SolrServerContextBuilder; + /// use solrstice::BlockingSolrCloudClient; + /// # use solrstice::SolrSingleServerHost; + /// # use solrstice::SolrServerContextBuilder; /// # fn run() -> Result<(), Box> { /// let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).build(); /// let client = BlockingSolrCloudClient::new(context); @@ -270,18 +262,18 @@ impl BlockingSolrCloudClient { /// # Ok(()) /// # } /// ``` - pub fn delete_alias>(&self, name: S) -> Result<(), SolrError> { + pub fn delete_alias>(&self, name: S) -> Result<(), Error> { delete_alias_blocking(&self.context, name) } /// Index some data into SolrCloud /// # Examples /// ```no_run - /// # use solrstice::hosts::solr_server_host::SolrSingleServerHost; - /// # use solrstice::models::context::SolrServerContextBuilder; - /// # use solrstice::queries::index::UpdateQuery; + /// # use solrstice::SolrSingleServerHost; + /// # use solrstice::SolrServerContextBuilder; + /// # use solrstice::UpdateQuery; /// # use serde::Serialize; - /// # use solrstice::clients::blocking_cloud_client::BlockingSolrCloudClient; + /// # use solrstice::BlockingSolrCloudClient; /// # async fn run() -> Result<(), Box> { /// #[derive(Serialize)] /// struct Data {id: String} @@ -297,7 +289,7 @@ impl BlockingSolrCloudClient { builder: B, collection: S, data: &[T], - ) -> Result { + ) -> Result { builder .as_ref() .execute_blocking(&self.context, collection, data) @@ -306,10 +298,10 @@ impl BlockingSolrCloudClient { /// Select some data from SolrCloud /// # Examples /// ```no_run - /// # use solrstice::clients::blocking_cloud_client::BlockingSolrCloudClient; - /// # use solrstice::hosts::solr_server_host::SolrSingleServerHost; - /// # use solrstice::models::context::SolrServerContextBuilder; - /// # use solrstice::queries::select::SelectQuery; + /// # use solrstice::BlockingSolrCloudClient; + /// # use solrstice::SolrSingleServerHost; + /// # use solrstice::SolrServerContextBuilder; + /// # use solrstice::SelectQuery; /// # fn run() -> Result<(), Box> { /// let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).build(); /// let client = BlockingSolrCloudClient::new(context); @@ -321,18 +313,18 @@ impl BlockingSolrCloudClient { &self, builder: B, collection: S, - ) -> Result { + ) -> Result { builder.as_ref().execute_blocking(&self.context, collection) } /// Delete some data from SolrCloud /// # Examples /// ```no_run - /// # use solrstice::clients::blocking_cloud_client::BlockingSolrCloudClient; - /// # use solrstice::hosts::solr_server_host::SolrSingleServerHost; - /// # use solrstice::models::context::SolrServerContextBuilder; - /// # use solrstice::queries::index::DeleteQuery; - /// # use solrstice::queries::select::SelectQuery; + /// # use solrstice::BlockingSolrCloudClient; + /// # use solrstice::SolrSingleServerHost; + /// # use solrstice::SolrServerContextBuilder; + /// # use solrstice::DeleteQuery; + /// # use solrstice::SelectQuery; /// # fn run() -> Result<(), Box> { /// let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).build(); /// let client = BlockingSolrCloudClient::new(context); @@ -344,7 +336,7 @@ impl BlockingSolrCloudClient { &self, builder: B, collection: S, - ) -> Result { + ) -> Result { builder.as_ref().execute_blocking(&self.context, collection) } } diff --git a/framework/src/clients/mod.rs b/framework/src/clients/mod.rs index 5d3cdce..935aa9d 100644 --- a/framework/src/clients/mod.rs +++ b/framework/src/clients/mod.rs @@ -2,19 +2,15 @@ //! # Examples //! ## Async client for SolrCloud //! ```rust -//! use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; -//! use solrstice::hosts::solr_server_host::SolrSingleServerHost; -//! use solrstice::models::context::SolrServerContextBuilder; //! +//! use solrstice::{AsyncSolrCloudClient, SolrServerContextBuilder, SolrSingleServerHost}; //! let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).build(); //! let client = AsyncSolrCloudClient::new(context); //! ``` //! ## Blocking client for SolrCloud //! ```rust -//! use solrstice::clients::blocking_cloud_client::BlockingSolrCloudClient; -//! use solrstice::hosts::solr_server_host::SolrSingleServerHost; -//! use solrstice::models::context::SolrServerContextBuilder; //! +//! use solrstice::{BlockingSolrCloudClient, SolrServerContextBuilder, SolrSingleServerHost}; //! let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).build(); //! let client = BlockingSolrCloudClient::new(context); //! ``` diff --git a/framework/src/docs/create_client_test.rs b/framework/src/docs/create_client_test.rs index 378aca3..2910e05 100644 --- a/framework/src/docs/create_client_test.rs +++ b/framework/src/docs/create_client_test.rs @@ -1,9 +1,9 @@ use serial_test::parallel; /// ```rust -/// # use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; -/// # use solrstice::hosts::solr_server_host::SolrSingleServerHost; -/// # use solrstice::models::context::SolrServerContextBuilder; +/// # use solrstice::AsyncSolrCloudClient; +/// # use solrstice::SolrSingleServerHost; +/// # use solrstice::SolrServerContextBuilder; /// let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).build(); /// let client = AsyncSolrCloudClient::new(context); /// ``` diff --git a/framework/src/docs/create_collection_test.rs b/framework/src/docs/create_collection_test.rs index 6ae29b5..6d551d9 100644 --- a/framework/src/docs/create_collection_test.rs +++ b/framework/src/docs/create_collection_test.rs @@ -1,9 +1,9 @@ use serial_test::parallel; /// ```rust,no_run -/// # use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; -/// # use solrstice::hosts::solr_server_host::SolrSingleServerHost; -/// # use solrstice::models::context::SolrServerContextBuilder; +/// # use solrstice::AsyncSolrCloudClient; +/// # use solrstice::SolrSingleServerHost; +/// # use solrstice::SolrServerContextBuilder; /// # use std::path::Path; /// # async fn run() -> Result<(), Box> { /// # let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("")).build(); diff --git a/framework/src/docs/delete_data_test.rs b/framework/src/docs/delete_data_test.rs index 9097212..d5c4ed5 100644 --- a/framework/src/docs/delete_data_test.rs +++ b/framework/src/docs/delete_data_test.rs @@ -1,10 +1,10 @@ use serial_test::parallel; /// ```rust,no_run -/// # use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; -/// # use solrstice::hosts::solr_server_host::SolrSingleServerHost; -/// # use solrstice::models::context::SolrServerContextBuilder; -/// # use solrstice::queries::index::DeleteQuery; +/// # use solrstice::AsyncSolrCloudClient; +/// # use solrstice::SolrSingleServerHost; +/// # use solrstice::SolrServerContextBuilder; +/// # use solrstice::DeleteQuery; /// # async fn run() -> Result<(), Box> { /// # let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).build(); /// # let client = AsyncSolrCloudClient::new(context); diff --git a/framework/src/docs/index_data_test.rs b/framework/src/docs/index_data_test.rs index 5516956..68bff44 100644 --- a/framework/src/docs/index_data_test.rs +++ b/framework/src/docs/index_data_test.rs @@ -1,10 +1,10 @@ use serial_test::parallel; /// ```rust,no_run -/// # use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; -/// # use solrstice::hosts::solr_server_host::SolrSingleServerHost; -/// # use solrstice::models::context::SolrServerContextBuilder; -/// # use solrstice::queries::index::UpdateQuery; +/// # use solrstice::AsyncSolrCloudClient; +/// # use solrstice::SolrSingleServerHost; +/// # use solrstice::SolrServerContextBuilder; +/// # use solrstice::UpdateQuery; /// # use serde::{Serialize, Deserialize}; /// /// #[derive(Serialize, Deserialize, Debug)] diff --git a/framework/src/docs/select_data_test.rs b/framework/src/docs/select_data_test.rs index 4abc31b..f1b25df 100644 --- a/framework/src/docs/select_data_test.rs +++ b/framework/src/docs/select_data_test.rs @@ -1,10 +1,10 @@ use serial_test::parallel; /// ```rust,no_run -/// # use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; -/// # use solrstice::hosts::solr_server_host::SolrSingleServerHost; -/// # use solrstice::models::context::SolrServerContextBuilder; -/// # use solrstice::queries::select::SelectQuery; +/// # use solrstice::AsyncSolrCloudClient; +/// # use solrstice::SolrSingleServerHost; +/// # use solrstice::SolrServerContextBuilder; +/// # use solrstice::SelectQuery; /// # use serde::{Serialize, Deserialize}; /// # async fn run() -> Result<(), Box> { /// # let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).build(); diff --git a/framework/src/models/error.rs b/framework/src/error.rs similarity index 86% rename from framework/src/models/error.rs rename to framework/src/error.rs index f467891..27ec2f6 100644 --- a/framework/src/models/error.rs +++ b/framework/src/error.rs @@ -3,7 +3,7 @@ use thiserror::Error; /// Main error type for Solrstice #[derive(Error, Debug)] -pub enum SolrError { +pub enum Error { #[error(transparent)] ReqwestError(#[from] reqwest::Error), #[error(transparent)] @@ -30,14 +30,14 @@ pub enum SolrError { Unknown(String), } -impl From<&str> for SolrError { +impl From<&str> for Error { fn from(err: &str) -> Self { - SolrError::Unknown(err.to_string()) + Error::Unknown(err.to_string()) } } /// Helper function to check if a SolrResponse contains an error -pub fn try_solr_error(response: &SolrResponse) -> Result<(), SolrError> { +pub fn try_solr_error(response: &SolrResponse) -> Result<(), Error> { match &response.error { None => Ok(()), Some(err) => { @@ -47,7 +47,7 @@ pub fn try_solr_error(response: &SolrResponse) -> Result<(), SolrError> { } else if err.trace.is_some() { msg = err.trace.clone().unwrap(); } - Err(SolrError::SolrResponseError { + Err(Error::SolrResponseError { code: err.code, msg, }) diff --git a/framework/src/hosts/mod.rs b/framework/src/hosts/mod.rs index c31ab92..018f708 100644 --- a/framework/src/hosts/mod.rs +++ b/framework/src/hosts/mod.rs @@ -3,20 +3,16 @@ //! ## Connect to a single solr host //! Good for if you have an external load balancer //! ```rust -//! use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; -//! use solrstice::hosts::solr_server_host::SolrSingleServerHost; -//! use solrstice::models::context::{SolrServerContextBuilder}; +//! use solrstice::{AsyncSolrCloudClient, SolrServerContextBuilder, SolrSingleServerHost}; //! //! let host = SolrSingleServerHost::new("localhost:8983"); //! let client = AsyncSolrCloudClient::new(SolrServerContextBuilder::new(host).build()); //! ``` //! ## Connect to zookeeper instances //! ```no_run -//! use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; -//! use solrstice::hosts::zookeeper_host::ZookeeperEnsembleHostConnector; -//! use solrstice::models::context::{SolrServerContextBuilder}; +//! use solrstice::{AsyncSolrCloudClient, SolrServerContextBuilder, ZookeeperEnsembleHostConnector}; //! -//! # async fn run() -> Result<(), Box> { +//! async fn run() -> Result<(), Box> { //! let host = ZookeeperEnsembleHostConnector::new(["localhost:8983", "localhost:8984"], std::time::Duration::from_secs(3)).connect().await?; //! let client = AsyncSolrCloudClient::new(SolrServerContextBuilder::new(host).build()); //! # Ok(()) @@ -24,8 +20,8 @@ //! ``` /// Solr auth host trait -pub mod solr_host; +pub(crate) mod solr_host; /// Direct solr connectors -pub mod solr_server_host; +pub(crate) mod solr_server_host; /// Zookeeper connector -pub mod zookeeper_host; +pub(crate) mod zookeeper_host; diff --git a/framework/src/hosts/solr_host.rs b/framework/src/hosts/solr_host.rs index de62c9b..a6c1759 100644 --- a/framework/src/hosts/solr_host.rs +++ b/framework/src/hosts/solr_host.rs @@ -1,4 +1,4 @@ -use crate::models::error::SolrError; +use crate::error::Error; use async_trait::async_trait; use dyn_clone::DynClone; use std::borrow::Cow; @@ -6,6 +6,6 @@ use std::borrow::Cow; /// SolrHost specifies how to connect to a solr server. #[async_trait] pub trait SolrHost: DynClone { - async fn get_solr_node(&self) -> Result, SolrError>; + async fn get_solr_node(&self) -> Result, Error>; } dyn_clone::clone_trait_object!(SolrHost); diff --git a/framework/src/hosts/solr_server_host.rs b/framework/src/hosts/solr_server_host.rs index 7a4e642..916c160 100644 --- a/framework/src/hosts/solr_server_host.rs +++ b/framework/src/hosts/solr_server_host.rs @@ -1,5 +1,5 @@ +use crate::error::Error; use crate::hosts::solr_host::SolrHost; -use crate::models::error::SolrError; use async_trait::async_trait; use std::borrow::Cow; use std::time::Duration; @@ -7,9 +7,7 @@ use std::time::Duration; /// Connect to a single solr host /// Good for if you have an external load balancer /// ```rust -/// use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; -/// use solrstice::hosts::solr_server_host::SolrSingleServerHost; -/// use solrstice::models::context::{SolrServerContextBuilder}; +/// use solrstice::{AsyncSolrCloudClient, SolrServerContextBuilder, SolrSingleServerHost}; /// /// let host = SolrSingleServerHost::new("localhost:8983"); /// let client = AsyncSolrCloudClient::new(SolrServerContextBuilder::new(host).build()); @@ -21,7 +19,7 @@ pub struct SolrSingleServerHost { #[async_trait] impl SolrHost for SolrSingleServerHost { - async fn get_solr_node(&self) -> Result, SolrError> { + async fn get_solr_node(&self) -> Result, Error> { Ok(Cow::Borrowed(&self.host)) } } @@ -30,9 +28,7 @@ impl SolrSingleServerHost { /// Connect to a single solr host /// Good for if you have an external load balancer /// ```rust - /// use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; - /// use solrstice::hosts::solr_server_host::SolrSingleServerHost; - /// use solrstice::models::context::{SolrServerContextBuilder}; + /// use solrstice::{AsyncSolrCloudClient, SolrServerContextBuilder, SolrSingleServerHost}; /// /// let host = SolrSingleServerHost::new("localhost:8983"); /// let client = AsyncSolrCloudClient::new(SolrServerContextBuilder::new(host).build()); @@ -47,9 +43,7 @@ impl SolrSingleServerHost { /// It would be better to use [ZookeeperEnsembleHostConnector](crate::hosts::zookeeper_host::ZookeeperEnsembleHostConnector) instead. /// The timeout is used to determine how long to wait for a response from a solr host before trying the next one /// ```rust -/// use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; -/// use solrstice::hosts::solr_server_host::{SolrMultipleServerHost}; -/// use solrstice::models::context::{SolrServerContextBuilder}; +/// use solrstice::{AsyncSolrCloudClient, SolrMultipleServerHost, SolrServerContextBuilder}; /// /// let host = SolrMultipleServerHost::new(["localhost:8983", "localhost:8984"], std::time::Duration::from_secs(3)); /// let client = AsyncSolrCloudClient::new(SolrServerContextBuilder::new(host).build()); @@ -62,10 +56,10 @@ pub struct SolrMultipleServerHost { #[async_trait] impl SolrHost for SolrMultipleServerHost { - async fn get_solr_node(&self) -> Result, SolrError> { + async fn get_solr_node(&self) -> Result, Error> { let mut server_indices: Vec = (0..self.hosts.len()).collect(); if server_indices.is_empty() { - return Err(SolrError::SolrConnectionError( + return Err(Error::SolrConnectionError( "No Solr Host Specified".to_string(), )); } @@ -88,7 +82,7 @@ impl SolrHost for SolrMultipleServerHost { } } } - Err(SolrError::SolrConnectionError( + Err(Error::SolrConnectionError( "No Solr Host answered".to_string(), )) } @@ -100,9 +94,7 @@ impl SolrMultipleServerHost { /// It would be better to use [ZookeeperEnsembleHostConnector](crate::hosts::zookeeper_host::ZookeeperEnsembleHostConnector) instead. /// The timeout is used to determine how long to wait for a response from a solr host before trying the next one /// ```rust - /// use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; - /// use solrstice::hosts::solr_server_host::{SolrMultipleServerHost}; - /// use solrstice::models::context::{SolrServerContextBuilder}; + /// use solrstice::{AsyncSolrCloudClient, SolrMultipleServerHost, SolrServerContextBuilder}; /// /// let host = SolrMultipleServerHost::new(["localhost:8983", "localhost:8984"], std::time::Duration::from_secs(3)); /// let client = AsyncSolrCloudClient::new(SolrServerContextBuilder::new(host).build()); diff --git a/framework/src/hosts/zookeeper_host.rs b/framework/src/hosts/zookeeper_host.rs index b688dc1..58705aa 100644 --- a/framework/src/hosts/zookeeper_host.rs +++ b/framework/src/hosts/zookeeper_host.rs @@ -1,5 +1,5 @@ +use crate::error::Error; use crate::hosts::solr_host::SolrHost; -use crate::models::error::SolrError; use async_trait::async_trait; use log::debug; use std::borrow::Cow; @@ -10,9 +10,8 @@ use zookeeper_async::{WatchedEvent, Watcher, ZkResult, ZooKeeper}; /// Connect to zookeeper instances to get a list of solr nodes to connect to. Select randomly from the list of live nodes. /// The timeout is used to determine how long to wait for a response from a solr host before trying the next one /// ```no_run -/// use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; -/// use solrstice::hosts::zookeeper_host::ZookeeperEnsembleHostConnector; -/// use solrstice::models::context::{SolrServerContextBuilder}; +/// +/// use solrstice::{AsyncSolrCloudClient, SolrServerContextBuilder, ZookeeperEnsembleHostConnector}; /// /// # async fn run() -> Result<(), Box> { /// let host = ZookeeperEnsembleHostConnector::new(["localhost:8983", "localhost:8984"], std::time::Duration::from_secs(3)).connect().await?; @@ -30,9 +29,7 @@ impl ZookeeperEnsembleHostConnector { /// Connect to zookeeper instances to get a list of solr nodes to connect to. Select randomly from the list of live nodes. /// The timeout is used to determine how long to wait for a response from a solr host before trying the next one /// ```no_run - /// use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; - /// use solrstice::hosts::zookeeper_host::ZookeeperEnsembleHostConnector; - /// use solrstice::models::context::{SolrServerContextBuilder}; + /// use solrstice::{AsyncSolrCloudClient, SolrServerContextBuilder, ZookeeperEnsembleHostConnector}; /// /// # async fn run() -> Result<(), Box> { /// let host = ZookeeperEnsembleHostConnector::new(["localhost:8983", "localhost:8984"], std::time::Duration::from_secs(3)).connect().await?; @@ -53,9 +50,8 @@ impl ZookeeperEnsembleHostConnector { /// Connect to zookeeper instances to get a list of solr nodes to connect to. Select randomly from the list of live nodes. /// The timeout is used to determine how long to wait for a response from a solr host before trying the next one /// ```no_run - /// use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; - /// use solrstice::hosts::zookeeper_host::ZookeeperEnsembleHostConnector; - /// use solrstice::models::context::{SolrServerContextBuilder}; + /// + /// use solrstice::{AsyncSolrCloudClient, SolrServerContextBuilder, ZookeeperEnsembleHostConnector}; /// /// # async fn run() -> Result<(), Box> { /// let host = ZookeeperEnsembleHostConnector::new(["localhost:8983", "localhost:8984"], std::time::Duration::from_secs(3)).connect().await?; @@ -63,7 +59,7 @@ impl ZookeeperEnsembleHostConnector { /// # Ok(()) /// # } /// ``` - pub async fn connect(self) -> Result { + pub async fn connect(self) -> Result { ZookeeperEnsembleHost::new(self.hosts.as_slice(), self.timeout).await } } @@ -75,18 +71,15 @@ impl ZookeeperEnsembleHostConnector { /// Connect to zookeeper instances to get a list of solr nodes to connect to. Select randomly from the list of live nodes. /// The timeout is used to determine how long to wait for a response from a solr host before trying the next one /// ```no_run - /// use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; - /// use solrstice::clients::blocking_cloud_client::BlockingSolrCloudClient; - /// use solrstice::hosts::solr_server_host::{SolrMultipleServerHost}; - /// use solrstice::hosts::zookeeper_host::ZookeeperEnsembleHostConnector; - /// use solrstice::models::context::{SolrServerContextBuilder}; + /// use solrstice::{BlockingSolrCloudClient, SolrServerContextBuilder, ZookeeperEnsembleHostConnector}; + /// /// # async fn run() -> Result<(), Box> { /// let host = ZookeeperEnsembleHostConnector::new(["localhost:8983", "localhost:8984"], std::time::Duration::from_secs(3)).connect_blocking()?; /// let client = BlockingSolrCloudClient::new(SolrServerContextBuilder::new(host).build()); /// # Ok(()) /// # } /// ``` - pub fn connect_blocking(self) -> Result { + pub fn connect_blocking(self) -> Result { RUNTIME.block_on(self.connect()) } } @@ -94,9 +87,8 @@ impl ZookeeperEnsembleHostConnector { /// Connect to zookeeper instances to get a list of solr nodes to connect to. Select randomly from the list of live nodes. /// The timeout is used to determine how long to wait for a response from a solr host before trying the next one /// ```rust -/// use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; -/// use solrstice::hosts::zookeeper_host::ZookeeperEnsembleHostConnector; -/// use solrstice::models::context::{SolrServerContextBuilder}; +/// +/// use solrstice::{AsyncSolrCloudClient, SolrServerContextBuilder, ZookeeperEnsembleHostConnector}; /// /// # async fn run() -> Result<(), Box> { /// let host = ZookeeperEnsembleHostConnector::new(["localhost:8983", "localhost:8984"], std::time::Duration::from_secs(3)).connect().await?; @@ -113,7 +105,7 @@ impl ZookeeperEnsembleHost { pub(crate) async fn new, V: IntoIterator>( hosts: V, timeout: Duration, - ) -> Result { + ) -> Result { let hosts = hosts.into_iter().map(|s| s.into()).collect::>(); let hosts = hosts.join(","); Ok(ZookeeperEnsembleHost { @@ -124,10 +116,10 @@ impl ZookeeperEnsembleHost { #[async_trait] impl SolrHost for ZookeeperEnsembleHost { - async fn get_solr_node(&self) -> Result, SolrError> { + async fn get_solr_node(&self) -> Result, Error> { let hosts = get_hosts_from_zookeeper(&self.client).await?; match hosts.get(fastrand::usize(0..hosts.len())) { - None => Err(SolrError::SolrConnectionError( + None => Err(Error::SolrConnectionError( "No ready Solr nodes from Zookeeper".to_string(), )), //TODO Investigate this further. Is it always http://, and do people use auth? diff --git a/framework/src/lib.rs b/framework/src/lib.rs index 45ae4b7..208bcf4 100644 --- a/framework/src/lib.rs +++ b/framework/src/lib.rs @@ -3,13 +3,13 @@ //! # Examples //! ```no_run //! use serde::{Deserialize, Serialize}; -//! use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; -//! use solrstice::hosts::solr_server_host::SolrSingleServerHost; -//! use solrstice::models::auth::SolrBasicAuth; -//! use solrstice::models::context::{SolrServerContextBuilder}; -//! use solrstice::models::error::SolrError; -//! use solrstice::queries::index::{DeleteQuery, UpdateQuery}; -//! use solrstice::queries::select::SelectQuery; +//! use solrstice::AsyncSolrCloudClient; +//! use solrstice::SolrSingleServerHost; +//! use solrstice::SolrBasicAuth; +//! use solrstice::{SolrServerContextBuilder}; +//! use solrstice::Error; +//! use solrstice::{DeleteQuery, UpdateQuery}; +//! use solrstice::SelectQuery; //! use std::path::Path; //! //! #[derive(Serialize, Deserialize, Debug)] @@ -18,7 +18,7 @@ //! } //! //! #[tokio::test] -//! pub async fn example() -> Result<(), SolrError> { +//! pub async fn example() -> Result<(), Error> { //! //! //Create a solr client. You can also use a list of zookeeper hosts instead of a single server. //! let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")) @@ -70,16 +70,36 @@ //! ``` /// Solr Clients -pub mod clients; +mod clients; +pub use clients::async_cloud_client::*; +#[cfg(feature = "blocking")] +pub use clients::blocking_cloud_client::*; + /// Host types -pub mod hosts; +mod hosts; +pub use crate::hosts::solr_host::*; +pub use crate::hosts::solr_server_host::*; +pub use crate::hosts::zookeeper_host::*; /// Model structs pub mod models; +pub use models::auth::*; +pub use models::commit_type::*; +pub use models::context::*; /// Query types pub mod queries; +pub use queries::components::facet_set::*; +pub use queries::components::grouping::*; +pub use queries::components::json_facet::*; +pub use queries::def_type::*; +pub use queries::index::*; +pub use queries::request_builder::*; +pub use queries::select::*; #[cfg(feature = "blocking")] /// Tokio Runtime for blocking usage -pub mod runtime; +mod runtime; #[cfg(doctest)] pub mod docs; +/// Error types for the library. +pub(crate) mod error; +pub use error::Error; diff --git a/framework/src/models/auth.rs b/framework/src/models/auth.rs index ed35316..21c6e2d 100644 --- a/framework/src/models/auth.rs +++ b/framework/src/models/auth.rs @@ -10,7 +10,7 @@ dyn_clone::clone_trait_object!(SolrAuth); /// Basic Authentication /// # Examples /// ``` -/// use solrstice::models::auth::SolrBasicAuth; +/// use solrstice::SolrBasicAuth; /// let auth = SolrBasicAuth::new("solr", Some("SolrRocks")); #[derive(Clone)] pub struct SolrBasicAuth { @@ -26,7 +26,7 @@ impl SolrAuth for SolrBasicAuth { impl SolrBasicAuth { /// Create a new Basic Authentication - /// use solrstice::models::auth::SolrBasicAuth; + /// use solrstice::SolrBasicAuth; /// let auth = SolrBasicAuth::new("solr", Some("SolrRocks")); pub fn new, O: Into>>(username: S, password: O) -> SolrBasicAuth { SolrBasicAuth { diff --git a/framework/src/models/commit_type.rs b/framework/src/models/commit_type.rs index 6bdec27..81d9fd2 100644 --- a/framework/src/models/commit_type.rs +++ b/framework/src/models/commit_type.rs @@ -6,8 +6,7 @@ use serde::{Deserialize, Serialize}; /// Conversely, a `Soft` commit corresponds to `softCommit=true`. /// # Examples /// ``` -/// use solrstice::models::commit_type::CommitType; -/// use solrstice::queries::index::{DeleteQuery, UpdateQuery}; +/// use solrstice::{CommitType, DeleteQuery, UpdateQuery}; /// /// let update_query = UpdateQuery::new().commit_type(CommitType::Soft); /// let delete_query = DeleteQuery::new().commit_type(CommitType::Soft); diff --git a/framework/src/models/context.rs b/framework/src/models/context.rs index 7a35d54..8d3c52c 100644 --- a/framework/src/models/context.rs +++ b/framework/src/models/context.rs @@ -6,10 +6,7 @@ use std::sync::Arc; /// A SolrServerContext specifies how to connect to a solr server, and how to authenticate. /// # Examples /// ``` -/// use solrstice::models::context::SolrServerContextBuilder; -/// use solrstice::hosts::solr_host::SolrHost; -/// use solrstice::hosts::solr_server_host::SolrSingleServerHost; -/// use solrstice::models::auth::SolrBasicAuth; +/// use solrstice::{SolrBasicAuth, SolrServerContextBuilder, SolrSingleServerHost}; /// /// let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")) /// .with_auth(SolrBasicAuth::new("solr", Some("SolrRocks"))) @@ -27,8 +24,8 @@ impl SolrServerContextBuilder { /// Create a new SolrServerContextBuilder /// # Examples /// ```no_run - /// use solrstice::models::context::SolrServerContextBuilder; - /// use solrstice::hosts::solr_server_host::SolrSingleServerHost; + /// use solrstice::{SolrServerContextBuilder, SolrSingleServerHost}; + /// /// let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).build(); /// ``` pub fn new(host: A) -> Self { @@ -43,10 +40,7 @@ impl SolrServerContextBuilder { /// Create a new SolrServerContextBuilder /// # Examples /// ```no_run - /// use solrstice::models::context::SolrServerContextBuilder; - /// use solrstice::hosts::solr_server_host::SolrSingleServerHost; - /// use solrstice::models::auth::SolrBasicAuth; - /// + /// use solrstice::{SolrBasicAuth, SolrServerContextBuilder, SolrSingleServerHost}; /// let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")) /// .with_auth(SolrBasicAuth::new("username", Some("password"))).build(); /// ``` @@ -59,9 +53,8 @@ impl SolrServerContextBuilder { /// # Examples /// ``` /// use std::time::Duration; - /// use solrstice::models::context::SolrServerContextBuilder; /// use reqwest::Client; - /// use solrstice::hosts::solr_server_host::SolrSingleServerHost; + /// use solrstice::{SolrServerContextBuilder, SolrSingleServerHost}; /// /// let client = Client::builder().timeout(Duration::from_secs(10)).build().unwrap(); /// let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).with_client(client).build(); @@ -76,10 +69,8 @@ impl SolrServerContextBuilder { /// `Pretty` is expensive as it needs deserialize and reserialize the body a second time. /// # Examples /// ``` - /// use solrstice::models::context::SolrServerContextBuilder; - /// use solrstice::hosts::solr_server_host::SolrSingleServerHost; - /// use solrstice::models::auth::SolrBasicAuth; - /// use solrstice::queries::request_builder::LoggingPolicy; + /// use solrstice::{LoggingPolicy, SolrServerContextBuilder, SolrSingleServerHost}; + /// /// let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")) /// .with_logging_policy(LoggingPolicy::Fast(4096)) /// .build(); @@ -91,8 +82,8 @@ impl SolrServerContextBuilder { /// Build a SolrServerContext /// # Examples /// ```no_run - /// use solrstice::models::context::SolrServerContextBuilder; - /// use solrstice::hosts::solr_server_host::SolrSingleServerHost; + /// use solrstice::{SolrServerContextBuilder, SolrSingleServerHost}; + /// /// let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).build(); /// ``` pub fn build(self) -> SolrServerContext { @@ -103,10 +94,7 @@ impl SolrServerContextBuilder { /// A SolrServerContext specifies how to connect to a solr server, and how to authenticate. /// # Examples /// ``` -/// use solrstice::models::context::SolrServerContextBuilder; -/// use solrstice::hosts::solr_host::SolrHost; -/// use solrstice::hosts::solr_server_host::SolrSingleServerHost; -/// use solrstice::models::auth::SolrBasicAuth; +/// use solrstice::{SolrBasicAuth, SolrServerContextBuilder, SolrSingleServerHost}; /// /// let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")) /// .with_auth(SolrBasicAuth::new("solr", Some("SolrRocks"))) diff --git a/framework/src/models/facet_set.rs b/framework/src/models/facet_set.rs index 9a58c89..d08840c 100644 --- a/framework/src/models/facet_set.rs +++ b/framework/src/models/facet_set.rs @@ -1,4 +1,4 @@ -use crate::models::error::SolrError; +use crate::error::Error; use serde::de::DeserializeOwned; use serde::{Deserialize, Serialize}; use std::collections::HashMap; @@ -17,7 +17,7 @@ pub struct SolrFacetSetResult { fields: HashMap>, } -pub fn fields_deserializer<'de, D>( +fn fields_deserializer<'de, D>( deserializer: D, ) -> Result>, D::Error> where @@ -94,7 +94,7 @@ pub struct SolrPivotFacetResult { } impl SolrPivotFacetResult { - pub fn get_value(&self) -> Result { + pub fn get_value(&self) -> Result { Ok(serde_json::from_value::(self.value.clone())?) } @@ -122,7 +122,7 @@ pub struct SolrFieldFacetResult { } impl SolrFieldFacetResult { - pub fn get_key(&self) -> Result { + pub fn get_key(&self) -> Result { Ok(serde_json::from_value::(self.key.clone())?) } diff --git a/framework/src/models/group.rs b/framework/src/models/group.rs index e91cd71..d44322e 100644 --- a/framework/src/models/group.rs +++ b/framework/src/models/group.rs @@ -1,4 +1,4 @@ -use crate::models::error::SolrError; +use crate::error::Error; use crate::models::response::SolrDocsResponse; use serde::de::DeserializeOwned; use serde::{Deserialize, Serialize}; @@ -19,11 +19,8 @@ impl SolrGroupResult { /// Returns a field query result /// # Examples /// ```no_run - /// # use solrstice::hosts::solr_server_host::SolrSingleServerHost; - /// use solrstice::models::auth::SolrBasicAuth; - /// # use solrstice::models::context::SolrServerContextBuilder; - /// use solrstice::queries::components::grouping::GroupingComponent; - /// use solrstice::queries::select::SelectQuery; + /// use solrstice::{GroupingComponent, SelectQuery, SolrServerContextBuilder, SolrSingleServerHost}; + /// /// # async fn run() -> Result<(), Box> { /// # let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).build(); /// let response = SelectQuery::new() @@ -48,12 +45,10 @@ impl SolrGroupResult { /// Returns a grouping query result /// # Examples /// ```no_run - /// # use solrstice::hosts::solr_server_host::SolrSingleServerHost; - /// use solrstice::models::auth::SolrBasicAuth; - /// # use solrstice::models::context::SolrServerContextBuilder; - /// use solrstice::queries::components::grouping::GroupingComponent; - /// use solrstice::queries::select::SelectQuery; - /// # async fn run() -> Result<(), Box> { + /// use solrstice::{GroupingComponent, SelectQuery, SolrSingleServerHost}; + /// # use solrstice::SolrServerContextBuilder; + /// + /// async fn run() -> Result<(), Box> { /// # let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).build(); /// let response = SelectQuery::new() /// .grouping( @@ -79,11 +74,7 @@ impl SolrGroupResult { /// If [GroupFormatting::Simple](crate::queries::components::grouping::GroupFormatting::Simple) is used, returns a simple grouping query result. This uses the same logic as [get_query_result](SolrGroupResult::get_query_result) /// # Examples /// ```no_run - /// # use solrstice::hosts::solr_server_host::SolrSingleServerHost; - /// use solrstice::models::auth::SolrBasicAuth; - /// # use solrstice::models::context::SolrServerContextBuilder; - /// use solrstice::queries::components::grouping::{GroupFormatting, GroupingComponent}; - /// use solrstice::queries::select::SelectQuery; + /// use solrstice::{GroupFormatting, GroupingComponent, SolrBasicAuth, SelectQuery, SolrServerContextBuilder, SolrSingleServerHost}; /// # async fn run() -> Result<(), Box> { /// # let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).build(); /// let response = SelectQuery::new() @@ -117,12 +108,9 @@ impl SolrGroupResult { /// group_value can be multiple types (int, string), so it is not immediately deserialized /// # Examples /// ```no_run -/// # use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; -/// # use solrstice::hosts::solr_server_host::SolrSingleServerHost; -/// # use solrstice::models::context::SolrServerContextBuilder; -/// # use solrstice::queries::components::grouping::GroupingComponent; -/// # use solrstice::queries::select::SelectQuery; -/// # async fn run() -> Result<(), Box> { +/// use solrstice::{AsyncSolrCloudClient, GroupingComponent, SelectQuery, SolrServerContextBuilder, SolrSingleServerHost}; +/// +/// async fn run() -> Result<(), Box> { /// # let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).build(); /// # let client = AsyncSolrCloudClient::new(context); /// let response = client.select(&SelectQuery::new() @@ -153,11 +141,10 @@ impl SolrGroupFieldResult { /// Returns the group key /// # Examples /// ```no_run - /// # use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; - /// # use solrstice::hosts::solr_server_host::SolrSingleServerHost; - /// # use solrstice::models::context::SolrServerContextBuilder; - /// # use solrstice::queries::components::grouping::GroupingComponent; - /// # use solrstice::queries::select::SelectQuery; + /// # use solrstice::{AsyncSolrCloudClient, SolrSingleServerHost}; + /// # use solrstice::SolrServerContextBuilder; + /// # use solrstice::GroupingComponent; + /// # use solrstice::SelectQuery; /// # async fn run() -> Result<(), Box> { /// # let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).build(); /// # let client = AsyncSolrCloudClient::new(context); @@ -174,18 +161,17 @@ impl SolrGroupFieldResult { /// # Ok(()) /// # } /// ``` - pub fn get_group_value(&self) -> Result { - serde_json::from_str(self.group_value.get()).map_err(SolrError::from) + pub fn get_group_value(&self) -> Result { + serde_json::from_str(self.group_value.get()).map_err(Error::from) } /// Returns a list of documents corresponding to the group /// # Examples /// ```no_run - /// # use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; - /// # use solrstice::hosts::solr_server_host::SolrSingleServerHost; - /// # use solrstice::models::context::SolrServerContextBuilder; - /// # use solrstice::queries::components::grouping::GroupingComponent; - /// # use solrstice::queries::select::SelectQuery; + /// # use solrstice::{AsyncSolrCloudClient, SolrSingleServerHost}; + /// # use solrstice::SolrServerContextBuilder; + /// # use solrstice::GroupingComponent; + /// # use solrstice::SelectQuery; /// # async fn run() -> Result<(), Box> { /// # let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).build(); /// # let client = AsyncSolrCloudClient::new(context); diff --git a/framework/src/models/json_facet.rs b/framework/src/models/json_facet.rs index f50cac0..5ae9b76 100644 --- a/framework/src/models/json_facet.rs +++ b/framework/src/models/json_facet.rs @@ -5,13 +5,7 @@ use std::collections::HashMap; /// Get self defined facets. /// # Examples /// ```no_run -/// # use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; -/// # use solrstice::hosts::solr_server_host::SolrSingleServerHost; -/// # use solrstice::models::auth::SolrBasicAuth; -/// # use solrstice::models::context::SolrServerContextBuilder; -/// # use solrstice::queries::components::facet_set::FacetSetComponent; -/// # use solrstice::queries::components::json_facet::{JsonFacetComponent, JsonQueryFacet}; -/// # use solrstice::queries::select::SelectQuery; +/// # use solrstice::{AsyncSolrCloudClient, JsonFacetComponent, JsonQueryFacet, SelectQuery, SolrServerContextBuilder, SolrSingleServerHost}; /// # async fn run() -> Result<(), Box> { /// # let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).build(); /// let client = AsyncSolrCloudClient::new(context); diff --git a/framework/src/models/mod.rs b/framework/src/models/mod.rs index c3bb693..70f32ac 100644 --- a/framework/src/models/mod.rs +++ b/framework/src/models/mod.rs @@ -1,18 +1,21 @@ //! Models used by the Solr Client. /// All authentication types supported by the library. -pub mod auth; +pub(crate) mod auth; /// Commit types for Solr's update and delete queries. -pub mod commit_type; +pub(crate) mod commit_type; /// Context for the solr Client. Specifying how to connect. -pub mod context; -/// Error types for the library. -pub mod error; +pub(crate) mod context; /// Facet -pub mod facet_set; +pub(crate) mod facet_set; +pub use facet_set::*; /// Models used by the GroupingComponent. -pub mod group; +pub(crate) mod group; +pub use group::*; + /// Facets returned by JSON faceting. -pub mod json_facet; +pub(crate) mod json_facet; +pub use json_facet::*; /// Models used to get responses from Solr -pub mod response; +pub(crate) mod response; +pub use response::*; diff --git a/framework/src/models/response.rs b/framework/src/models/response.rs index c182918..f072a93 100644 --- a/framework/src/models/response.rs +++ b/framework/src/models/response.rs @@ -1,4 +1,4 @@ -use crate::models::error::SolrError; +use crate::error::Error; use crate::models::facet_set::SolrFacetSetResult; use crate::models::group::SolrGroupResult; use crate::models::json_facet::SolrJsonFacetResponse; @@ -68,12 +68,8 @@ impl SolrDocsResponse { /// /// # Examples /// ```no_run - /// # use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; - /// # use solrstice::hosts::solr_server_host::SolrSingleServerHost; - /// # use solrstice::models::auth::SolrBasicAuth; - /// # use solrstice::models::context::SolrServerContextBuilder; - /// # use solrstice::queries::components::grouping::GroupingComponent; - /// # use solrstice::queries::select::SelectQuery; + /// use solrstice::{AsyncSolrCloudClient, SelectQuery, SolrBasicAuth, SolrServerContextBuilder, SolrSingleServerHost}; + /// /// # async fn run() -> Result<(), Box> { /// let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).with_auth(SolrBasicAuth::new("solr", Some("SolrRocks"))).build(); /// let client = AsyncSolrCloudClient::new(context); @@ -82,7 +78,7 @@ impl SolrDocsResponse { /// Ok(()) /// # } /// ``` - pub fn get_docs(&self) -> Result, SolrError> { + pub fn get_docs(&self) -> Result, Error> { serde_json::from_str::>(self.docs.get()).map_err(|e| e.into()) } } @@ -125,12 +121,8 @@ impl SolrResponse { /// Get the docs returned by a select request. /// # Examples /// ```no_run - /// # use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; - /// # use solrstice::hosts::solr_server_host::SolrSingleServerHost; - /// # use solrstice::models::auth::SolrBasicAuth; - /// # use solrstice::models::context::SolrServerContextBuilder; - /// # use solrstice::queries::components::grouping::GroupingComponent; - /// # use solrstice::queries::select::SelectQuery; + /// use solrstice::{AsyncSolrCloudClient, SelectQuery, SolrBasicAuth, SolrServerContextBuilder, SolrSingleServerHost}; + /// /// # async fn run() -> Result<(), Box> { /// let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).with_auth(SolrBasicAuth::new("solr", Some("SolrRocks"))).build(); /// let client = AsyncSolrCloudClient::new(context); @@ -146,12 +138,8 @@ impl SolrResponse { /// /// # Examples /// ```no_run - /// # use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; - /// # use solrstice::hosts::solr_server_host::SolrSingleServerHost; - /// # use solrstice::models::auth::SolrBasicAuth; - /// # use solrstice::models::context::SolrServerContextBuilder; - /// # use solrstice::queries::components::grouping::GroupingComponent; - /// # use solrstice::queries::select::SelectQuery; + /// # use solrstice::{AsyncSolrCloudClient, GroupingComponent, SelectQuery, SolrBasicAuth, SolrServerContextBuilder, SolrSingleServerHost}; + /// /// # async fn run() -> Result<(), Box> { /// let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).with_auth(SolrBasicAuth::new("solr", Some("SolrRocks"))).build(); /// let client = AsyncSolrCloudClient::new(context); diff --git a/framework/src/queries/alias.rs b/framework/src/queries/alias.rs index 08d5c52..e3d402a 100644 --- a/framework/src/queries/alias.rs +++ b/framework/src/queries/alias.rs @@ -1,5 +1,5 @@ +use crate::error::Error; use crate::models::context::SolrServerContext; -use crate::models::error::SolrError; use crate::queries::request_builder::SolrRequestBuilder; use std::collections::HashMap; @@ -9,13 +9,13 @@ use std::collections::HashMap; /// Example usage can be found at [AsyncSolrCloudClient::get_aliases](crate::clients::async_cloud_client::AsyncSolrCloudClient::get_aliases) pub async fn get_aliases>( context: C, -) -> Result>, SolrError> { +) -> Result>, Error> { let json = SolrRequestBuilder::new(context.as_ref(), "/solr/admin/collections") .with_query_params(&[("action", "LISTALIASES")]) .send_get() .await?; match json.aliases { - None => Err(SolrError::Unknown( + None => Err(Error::Unknown( "Could not find alias key in map".to_string(), )), Some(aliases) => Ok(aliases), @@ -30,7 +30,7 @@ pub async fn create_alias, S: AsRef>( context: C, name: S, collections: &[S], -) -> Result<(), SolrError> { +) -> Result<(), Error> { let collections = collections .iter() .map(|x| x.as_ref()) @@ -55,7 +55,7 @@ pub async fn create_alias, S: AsRef>( pub async fn alias_exists, S: AsRef>( context: C, name: S, -) -> Result { +) -> Result { let aliases = get_aliases(context).await?; Ok(aliases.contains_key(name.as_ref())) } @@ -67,7 +67,7 @@ pub async fn alias_exists, S: AsRef>( pub async fn delete_alias, S: AsRef>( context: C, name: S, -) -> Result<(), SolrError> { +) -> Result<(), Error> { let query_params = [("action", "DELETEALIAS"), ("name", name.as_ref())]; SolrRequestBuilder::new(context.as_ref(), "/solr/admin/collections") .with_query_params(query_params.as_ref()) @@ -85,7 +85,7 @@ use crate::runtime::RUNTIME; /// Example usage can be found at [BlockingSolrCloudClient::get_aliases](crate::clients::blocking_cloud_client::BlockingSolrCloudClient::get_aliases) pub fn get_aliases_blocking>( context: C, -) -> Result>, SolrError> { +) -> Result>, Error> { RUNTIME.handle().block_on(get_aliases(context)) } @@ -98,7 +98,7 @@ pub fn create_alias_blocking, S: AsRef>( context: C, name: S, collections: &[S], -) -> Result<(), SolrError> { +) -> Result<(), Error> { RUNTIME .handle() .block_on(create_alias(context, name, collections)) @@ -112,7 +112,7 @@ pub fn create_alias_blocking, S: AsRef>( pub fn alias_exists_blocking, S: AsRef>( context: C, name: S, -) -> Result { +) -> Result { RUNTIME.handle().block_on(alias_exists(context, name)) } @@ -124,6 +124,6 @@ pub fn alias_exists_blocking, S: AsRef>( pub fn delete_alias_blocking, S: AsRef>( context: C, name: S, -) -> Result<(), SolrError> { +) -> Result<(), Error> { RUNTIME.handle().block_on(delete_alias(context, name)) } diff --git a/framework/src/queries/collection.rs b/framework/src/queries/collection.rs index 7f8cd09..5d941f1 100644 --- a/framework/src/queries/collection.rs +++ b/framework/src/queries/collection.rs @@ -1,5 +1,5 @@ +use crate::error::Error; use crate::models::context::SolrServerContext; -use crate::models::error::SolrError; use crate::queries::request_builder::SolrRequestBuilder; pub async fn create_collection, S: AsRef>( @@ -8,7 +8,7 @@ pub async fn create_collection, S: AsRef>( config: S, shards: usize, replication_factor: usize, -) -> Result<(), SolrError> { +) -> Result<(), Error> { let query_params = [ ("action", "CREATE"), ("name", name.as_ref()), @@ -25,14 +25,14 @@ pub async fn create_collection, S: AsRef>( pub async fn get_collections>( context: C, -) -> Result, SolrError> { +) -> Result, Error> { let query_params = [("action", "LIST"), ("wt", "json")]; let json = SolrRequestBuilder::new(context.as_ref(), "/solr/admin/collections") .with_query_params(query_params.as_ref()) .send_get() .await?; match json.collections { - None => Err(SolrError::Unknown("Could not get collections".to_string())), + None => Err(Error::Unknown("Could not get collections".to_string())), Some(collections) => Ok(collections), } } @@ -40,7 +40,7 @@ pub async fn get_collections>( pub async fn collection_exists, S: AsRef>( context: C, name: S, -) -> Result { +) -> Result { let collections = get_collections(context).await?; Ok(collections.contains(&name.as_ref().to_string())) } @@ -48,7 +48,7 @@ pub async fn collection_exists, S: AsRef>( pub async fn delete_collection, S: AsRef>( context: C, name: S, -) -> Result<(), SolrError> { +) -> Result<(), Error> { let query_params = [("action", "DELETE"), ("name", name.as_ref())]; SolrRequestBuilder::new(context.as_ref(), "/solr/admin/collections") .with_query_params(query_params.as_ref()) @@ -66,7 +66,7 @@ pub fn create_collection_blocking, S: AsRef>( config: S, shards: usize, replication_factor: usize, -) -> Result<(), SolrError> { +) -> Result<(), Error> { RUNTIME.handle().block_on(create_collection( context, name, @@ -79,7 +79,7 @@ pub fn create_collection_blocking, S: AsRef>( #[cfg(feature = "blocking")] pub fn get_collections_blocking>( context: C, -) -> Result, SolrError> { +) -> Result, Error> { RUNTIME.handle().block_on(get_collections(context)) } @@ -87,7 +87,7 @@ pub fn get_collections_blocking>( pub fn collection_exists_blocking, S: AsRef>( context: C, name: S, -) -> Result { +) -> Result { RUNTIME.handle().block_on(collection_exists(context, name)) } @@ -95,6 +95,6 @@ pub fn collection_exists_blocking, S: AsRef>( pub fn delete_collection_blocking, S: AsRef>( context: C, name: S, -) -> Result<(), SolrError> { +) -> Result<(), Error> { RUNTIME.handle().block_on(delete_collection(context, name)) } diff --git a/framework/src/queries/components/facet_set.rs b/framework/src/queries/components/facet_set.rs index c27bf94..0993f44 100644 --- a/framework/src/queries/components/facet_set.rs +++ b/framework/src/queries/components/facet_set.rs @@ -7,12 +7,8 @@ use std::collections::HashMap; /// Get facet counts for different types of faceting. /// # Examples /// ```no_run -/// # use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; -/// # use solrstice::hosts::solr_server_host::SolrSingleServerHost; -/// # use solrstice::models::auth::SolrBasicAuth; -/// # use solrstice::models::context::SolrServerContextBuilder; -/// # use solrstice::queries::components::facet_set::FacetSetComponent; -/// # use solrstice::queries::select::SelectQuery; +/// use solrstice::{AsyncSolrCloudClient, FacetSetComponent, SelectQuery, SolrServerContextBuilder, SolrSingleServerHost}; +/// /// # async fn run() -> Result<(), Box> { /// # let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).build(); /// let client = AsyncSolrCloudClient::new(context); @@ -42,12 +38,9 @@ impl FacetSetComponent { /// Get facet counts for different types of faceting. /// # Examples /// ```no_run - /// # use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; - /// # use solrstice::hosts::solr_server_host::SolrSingleServerHost; - /// # use solrstice::models::auth::SolrBasicAuth; - /// # use solrstice::models::context::SolrServerContextBuilder; - /// # use solrstice::queries::components::facet_set::FacetSetComponent; - /// # use solrstice::queries::select::SelectQuery; + /// use solrstice::{AsyncSolrCloudClient, FacetSetComponent, SelectQuery, SolrSingleServerHost}; + /// # use solrstice::SolrServerContextBuilder; + /// /// # async fn run() -> Result<(), Box> { /// # let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).build(); /// let client = AsyncSolrCloudClient::new(context); @@ -73,15 +66,11 @@ impl FacetSetComponent { /// Set pivot facets /// # Examples /// ```no_run - /// # use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; - /// # use solrstice::hosts::solr_server_host::SolrSingleServerHost; - /// # use solrstice::models::auth::SolrBasicAuth; - /// # use solrstice::models::context::SolrServerContextBuilder; - /// # use solrstice::queries::components::facet_set::{FacetSetComponent, PivotFacetComponent}; - /// # use solrstice::queries::select::SelectQuery; + /// use solrstice::{SolrBasicAuth, FacetSetComponent, PivotFacetComponent, AsyncSolrCloudClient, SelectQuery, SolrSingleServerHost}; + /// # use solrstice::SolrServerContextBuilder; /// # async fn run() -> Result<(), Box> { /// # let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).build(); - /// let client = AsyncSolrCloudClient::new(context); + /// let client = AsyncSolrCloudClient::new(context); /// let query = SelectQuery::new() /// .facet_set(&FacetSetComponent::new().pivots(PivotFacetComponent::new(["interests,age"]))); /// let response = client @@ -115,12 +104,9 @@ impl FacetSetComponent { /// Set query facets /// # Examples /// ```no_run - /// # use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; - /// # use solrstice::hosts::solr_server_host::SolrSingleServerHost; - /// # use solrstice::models::auth::SolrBasicAuth; - /// # use solrstice::models::context::SolrServerContextBuilder; - /// # use solrstice::queries::components::facet_set::FacetSetComponent; - /// # use solrstice::queries::select::SelectQuery; + /// # use solrstice::{SolrServerContextBuilder, SolrSingleServerHost}; + /// use solrstice::{AsyncSolrCloudClient, FacetSetComponent, SelectQuery}; + /// /// # async fn run() -> Result<(), Box> { /// # let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).build(); /// let client = AsyncSolrCloudClient::new(context); @@ -142,12 +128,8 @@ impl FacetSetComponent { /// Set field facets /// # Examples /// ```no_run - /// # use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; - /// # use solrstice::hosts::solr_server_host::SolrSingleServerHost; - /// # use solrstice::models::auth::SolrBasicAuth; - /// # use solrstice::models::context::SolrServerContextBuilder; - /// # use solrstice::queries::components::facet_set::{FacetSetComponent, FieldFacetComponent, FieldFacetEntry}; - /// # use solrstice::queries::select::SelectQuery; + /// # use solrstice::{SolrServerContextBuilder, SolrSingleServerHost}; + /// use solrstice::{FacetSetComponent, FieldFacetComponent, FieldFacetEntry, AsyncSolrCloudClient, SelectQuery}; /// # async fn run() -> Result<(), Box> { /// # let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).build(); /// let client = AsyncSolrCloudClient::new(context); @@ -191,12 +173,8 @@ impl From<&FacetSetComponent> for FacetSetComponent { /// A facet component for pivot facets. /// # Examples /// ```no_run -/// # use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; -/// # use solrstice::hosts::solr_server_host::SolrSingleServerHost; -/// # use solrstice::models::auth::SolrBasicAuth; -/// # use solrstice::models::context::SolrServerContextBuilder; -/// # use solrstice::queries::components::facet_set::{FacetSetComponent, PivotFacetComponent}; -/// # use solrstice::queries::select::SelectQuery; +/// use solrstice::{AsyncSolrCloudClient, FacetSetComponent, PivotFacetComponent, SelectQuery, SolrSingleServerHost}; +/// # use solrstice::SolrServerContextBuilder; /// # async fn run() -> Result<(), Box> { /// # let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).build(); /// let client = AsyncSolrCloudClient::new(context); @@ -239,12 +217,9 @@ impl PivotFacetComponent { /// Create a new pivot facet component. /// # Examples /// ```no_run - /// # use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; - /// # use solrstice::hosts::solr_server_host::SolrSingleServerHost; - /// # use solrstice::models::auth::SolrBasicAuth; - /// # use solrstice::models::context::SolrServerContextBuilder; - /// # use solrstice::queries::components::facet_set::{FacetSetComponent, PivotFacetComponent}; - /// # use solrstice::queries::select::SelectQuery; + /// use solrstice::{AsyncSolrCloudClient, FacetSetComponent, PivotFacetComponent, SelectQuery, SolrSingleServerHost}; + /// + /// # use solrstice::SolrServerContextBuilder; /// # async fn run() -> Result<(), Box> { /// # let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).build(); /// let client = AsyncSolrCloudClient::new(context); @@ -302,12 +277,8 @@ impl From<&PivotFacetComponent> for PivotFacetComponent { /// Component for field facets /// # Examples /// ```no_run -/// # use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; -/// use solrstice::hosts::solr_server_host::SolrSingleServerHost; -/// # use solrstice::models::auth::SolrBasicAuth; -/// # use solrstice::models::context::SolrServerContextBuilder; -/// # use solrstice::queries::components::facet_set::{FacetSetComponent, FieldFacetComponent, FieldFacetEntry}; -/// # use solrstice::queries::select::SelectQuery; +/// # use solrstice::{AsyncSolrCloudClient, FacetSetComponent, FieldFacetComponent, FieldFacetEntry, SelectQuery, SolrSingleServerHost}; +/// # use solrstice::SolrServerContextBuilder; /// # async fn run() -> Result<(), Box> { /// # let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).build(); /// let client = AsyncSolrCloudClient::new(context); @@ -524,12 +495,8 @@ impl FieldFacetComponent { /// Create a new field facet component. /// # Examples /// ```no_run - /// # use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; - /// use solrstice::hosts::solr_server_host::SolrSingleServerHost; - /// # use solrstice::models::auth::SolrBasicAuth; - /// # use solrstice::models::context::SolrServerContextBuilder; - /// # use solrstice::queries::components::facet_set::{FacetSetComponent, FieldFacetComponent, FieldFacetEntry}; - /// # use solrstice::queries::select::SelectQuery; + /// use solrstice::{AsyncSolrCloudClient, FacetSetComponent, FieldFacetComponent, FieldFacetEntry, SelectQuery, SolrSingleServerHost}; + /// # use solrstice::SolrServerContextBuilder; /// # async fn run() -> Result<(), Box> { /// # let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).build(); /// let client = AsyncSolrCloudClient::new(context); @@ -592,12 +559,8 @@ pub enum FieldFacetMethod { /// A field facet entry represents a single field facet. /// # Examples /// ```no_run -/// # use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; -/// use solrstice::hosts::solr_server_host::SolrSingleServerHost; -/// # use solrstice::models::auth::SolrBasicAuth; -/// # use solrstice::models::context::SolrServerContextBuilder; -/// # use solrstice::queries::components::facet_set::{FacetSetComponent, FieldFacetComponent, FieldFacetEntry}; -/// # use solrstice::queries::select::SelectQuery; +/// # use solrstice::{AsyncSolrCloudClient, FacetSetComponent, FieldFacetComponent, FieldFacetEntry, SelectQuery, SolrSingleServerHost}; +/// # use solrstice::SolrServerContextBuilder; /// # async fn run() -> Result<(), Box> { /// # let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).build(); /// let client = AsyncSolrCloudClient::new(context); @@ -645,12 +608,8 @@ impl FieldFacetEntry { /// Create a new field facet entry /// # Examples /// ```no_run - /// # use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; - /// use solrstice::hosts::solr_server_host::SolrSingleServerHost; - /// # use solrstice::models::auth::SolrBasicAuth; - /// # use solrstice::models::context::SolrServerContextBuilder; - /// # use solrstice::queries::components::facet_set::{FacetSetComponent, FieldFacetComponent, FieldFacetEntry}; - /// # use solrstice::queries::select::SelectQuery; + /// use solrstice::{AsyncSolrCloudClient, FacetSetComponent, FieldFacetComponent, FieldFacetEntry, SelectQuery, SolrSingleServerHost}; + /// # use solrstice::SolrServerContextBuilder; /// # async fn run() -> Result<(), Box> { /// # let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).build(); /// let client = AsyncSolrCloudClient::new(context); @@ -764,7 +723,7 @@ impl From<&FieldFacetEntry> for FieldFacetEntry { } #[cfg(test)] -pub mod tests { +mod tests { use crate::queries::components::facet_set::{FacetSetComponent, FieldFacetComponent}; #[test] diff --git a/framework/src/queries/components/grouping.rs b/framework/src/queries/components/grouping.rs index 3f84b3a..c4521a5 100644 --- a/framework/src/queries/components/grouping.rs +++ b/framework/src/queries/components/grouping.rs @@ -19,11 +19,8 @@ impl fmt::Display for GroupFormatting { /// Group documents by a field or query. /// # Examples /// ```no_run -/// # use solrstice::hosts::solr_server_host::SolrSingleServerHost; -/// use solrstice::models::auth::SolrBasicAuth; -/// # use solrstice::models::context::SolrServerContextBuilder; -/// use solrstice::queries::components::grouping::GroupingComponent; -/// use solrstice::queries::select::SelectQuery; +/// use solrstice::{GroupingComponent, SelectQuery, SolrBasicAuth, SolrSingleServerHost}; +/// # use solrstice::SolrServerContextBuilder; /// # async fn run() -> Result<(), Box> { /// # let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).build(); /// let response = SelectQuery::new() @@ -71,11 +68,8 @@ impl GroupingComponent { /// Create a new GroupingComponentBuilder. /// # Examples /// ```no_run - /// # use solrstice::hosts::solr_server_host::SolrSingleServerHost; - /// use solrstice::models::auth::SolrBasicAuth; - /// # use solrstice::models::context::SolrServerContextBuilder; - /// use solrstice::queries::components::grouping::GroupingComponent; - /// use solrstice::queries::select::SelectQuery; + /// use solrstice::{GroupingComponent, SelectQuery, SolrBasicAuth, SolrSingleServerHost}; + /// # use solrstice::SolrServerContextBuilder; /// # async fn run() -> Result<(), Box> { /// # let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).build(); /// let response = SelectQuery::new() @@ -112,7 +106,7 @@ impl GroupingComponent { /// Fields to group by. /// # Examples /// ```rust - /// use solrstice::queries::components::grouping::GroupingComponent; + /// use solrstice::GroupingComponent; /// GroupingComponent::new().fields(["age"]); /// ``` pub fn fields, I: IntoIterator, O: Into>>( @@ -128,7 +122,7 @@ impl GroupingComponent { /// Queries to group by. /// # Examples /// ```rust - /// use solrstice::queries::components::grouping::GroupingComponent; + /// use solrstice::GroupingComponent; /// GroupingComponent::new().queries(["age:[0 TO 59]", "age:[60 TO *]"]); /// ``` pub fn queries, I: IntoIterator, O: Into>>( @@ -144,7 +138,7 @@ impl GroupingComponent { /// Maximum number of documents per group. /// # Examples /// ```rust - /// use solrstice::queries::components::grouping::GroupingComponent; + /// use solrstice::GroupingComponent; /// GroupingComponent::new().limit(10); /// ``` pub fn limit>>(mut self, limit: O) -> Self { @@ -155,7 +149,7 @@ impl GroupingComponent { /// Initial offset /// # Examples /// ```rust - /// use solrstice::queries::components::grouping::GroupingComponent; + /// use solrstice::GroupingComponent; /// GroupingComponent::new().limit(10).offset(10); /// ``` pub fn offset>>(mut self, offset: O) -> Self { @@ -166,7 +160,7 @@ impl GroupingComponent { /// How to sort the documents in the groups. /// # Examples /// ```rust - /// use solrstice::queries::components::grouping::GroupingComponent; + /// use solrstice::GroupingComponent; /// GroupingComponent::new().sort(["age asc"]); /// ``` pub fn sort, I: IntoIterator, O: Into>>( @@ -182,7 +176,7 @@ impl GroupingComponent { /// How to format the groups. /// # Examples /// ```rust - /// use solrstice::queries::components::grouping::{GroupingComponent, GroupFormatting}; + /// use solrstice::{GroupingComponent, GroupFormatting}; /// GroupingComponent::new().format(GroupFormatting::Simple); /// ``` pub fn format>>(mut self, format: O) -> Self { @@ -193,7 +187,7 @@ impl GroupingComponent { /// Put the results in the main result set. /// # Examples /// ```rust - /// use solrstice::queries::components::grouping::GroupingComponent; + /// use solrstice::GroupingComponent; /// GroupingComponent::new().main(true); /// ``` pub fn main>>(mut self, main: O) -> Self { @@ -204,7 +198,7 @@ impl GroupingComponent { /// Include the number of groups that have matched the query. /// # Examples /// ```rust - /// use solrstice::queries::components::grouping::GroupingComponent; + /// use solrstice::GroupingComponent; /// GroupingComponent::new().n_groups(true); /// ``` pub fn n_groups>>(mut self, n_groups: O) -> Self { diff --git a/framework/src/queries/components/json_facet.rs b/framework/src/queries/components/json_facet.rs index 1a198e5..5e74559 100644 --- a/framework/src/queries/components/json_facet.rs +++ b/framework/src/queries/components/json_facet.rs @@ -1,16 +1,12 @@ -use serde::{Deserialize, Serialize, Serializer}; use std::collections::HashMap; +use serde::{Deserialize, Serialize, Serializer}; + /// Get self defined facets. /// # Examples /// ```no_run -/// # use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; -/// # use solrstice::hosts::solr_server_host::SolrSingleServerHost; -/// # use solrstice::models::auth::SolrBasicAuth; -/// # use solrstice::models::context::SolrServerContextBuilder; -/// # use solrstice::queries::components::facet_set::FacetSetComponent; -/// # use solrstice::queries::components::json_facet::{JsonFacetComponent, JsonQueryFacet}; -/// # use solrstice::queries::select::SelectQuery; +/// use solrstice::{AsyncSolrCloudClient, JsonFacetComponent, JsonQueryFacet, SelectQuery, SolrSingleServerHost}; +/// # use solrstice::SolrServerContextBuilder; /// # async fn run() -> Result<(), Box> { /// # let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).build(); /// let client = AsyncSolrCloudClient::new(context); @@ -51,13 +47,8 @@ impl JsonFacetComponent { /// Create a new instance of [JsonFacetComponent]. /// # Examples /// ```no_run - /// # use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; - /// # use solrstice::hosts::solr_server_host::SolrSingleServerHost; - /// # use solrstice::models::auth::SolrBasicAuth; - /// # use solrstice::models::context::SolrServerContextBuilder; - /// # use solrstice::queries::components::facet_set::FacetSetComponent; - /// # use solrstice::queries::components::json_facet::{JsonFacetComponent, JsonQueryFacet}; - /// # use solrstice::queries::select::SelectQuery; + /// use solrstice::{AsyncSolrCloudClient, JsonFacetComponent, JsonQueryFacet, SelectQuery, SolrSingleServerHost}; + /// # use solrstice::SolrServerContextBuilder; /// # async fn run() -> Result<(), Box> { /// # let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).build(); /// let client = AsyncSolrCloudClient::new(context); @@ -126,14 +117,8 @@ pub enum JsonFacetType { /// A facet that counts the number of documents that match a query /// # Examples /// ```no_run -/// # use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; -/// # use solrstice::hosts::solr_server_host::SolrSingleServerHost; -/// # use solrstice::models::auth::SolrBasicAuth; -/// # use solrstice::models::context::SolrServerContextBuilder; -/// # use solrstice::models::json_facet::SolrJsonFacetResponse; -/// # use solrstice::queries::components::facet_set::FacetSetComponent; -/// # use solrstice::queries::components::json_facet::{JsonFacetComponent, JsonQueryFacet, JsonStatFacet, JsonTermsFacet}; -/// # use solrstice::queries::select::SelectQuery; +/// # use solrstice::{AsyncSolrCloudClient, JsonFacetComponent, JsonQueryFacet, JsonStatFacet, JsonTermsFacet, SelectQuery, SolrSingleServerHost}; +/// # use solrstice::SolrServerContextBuilder; /// # async fn run() -> Result<(), Box> { /// # let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).build(); /// let client = AsyncSolrCloudClient::new(context); @@ -149,7 +134,7 @@ pub enum JsonFacetType { /// .ok_or("No age facet")?; /// let buckets = age /// .get_buckets() -/// .collect::>(); +/// .collect::>(); /// assert_eq!(buckets.len(), 3); /// # Ok(()) /// # } @@ -180,14 +165,8 @@ impl JsonTermsFacet { /// A facet that counts the number of documents that match a query /// # Examples /// ```no_run - /// # use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; - /// # use solrstice::hosts::solr_server_host::SolrSingleServerHost; - /// # use solrstice::models::auth::SolrBasicAuth; - /// # use solrstice::models::context::SolrServerContextBuilder; - /// # use solrstice::models::json_facet::SolrJsonFacetResponse; - /// # use solrstice::queries::components::facet_set::FacetSetComponent; - /// # use solrstice::queries::components::json_facet::{JsonFacetComponent, JsonQueryFacet, JsonStatFacet, JsonTermsFacet}; - /// # use solrstice::queries::select::SelectQuery; + /// use solrstice::{AsyncSolrCloudClient, JsonFacetComponent, JsonQueryFacet, JsonStatFacet, JsonTermsFacet, SelectQuery, SolrSingleServerHost}; + /// # use solrstice::SolrServerContextBuilder; /// # async fn run() -> Result<(), Box> { /// # let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).build(); /// let client = AsyncSolrCloudClient::new(context); @@ -203,7 +182,7 @@ impl JsonTermsFacet { /// .ok_or("No age facet")?; /// let buckets = age /// .get_buckets() - /// .collect::>(); + /// .collect::>(); /// assert_eq!(buckets.len(), 3); /// # Ok(()) /// # } @@ -260,13 +239,8 @@ impl JsonTermsFacet { /// A facet that does a query and returns the number of documents that match /// # Examples /// ```no_run -/// # use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; -/// # use solrstice::hosts::solr_server_host::SolrSingleServerHost; -/// # use solrstice::models::auth::SolrBasicAuth; -/// # use solrstice::models::context::SolrServerContextBuilder; -/// # use solrstice::queries::components::facet_set::FacetSetComponent; -/// # use solrstice::queries::components::json_facet::{JsonFacetComponent, JsonQueryFacet, JsonStatFacet}; -/// # use solrstice::queries::select::SelectQuery; +/// use solrstice::{AsyncSolrCloudClient, JsonFacetComponent, JsonQueryFacet, JsonStatFacet, SelectQuery, SolrSingleServerHost}; +/// # use solrstice::SolrServerContextBuilder; /// # async fn run() -> Result<(), Box> { /// # let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).build(); /// let client = AsyncSolrCloudClient::new(context); @@ -313,13 +287,8 @@ impl JsonQueryFacet { /// Create a new query facet /// # Examples /// ```no_run - /// # use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; - /// # use solrstice::hosts::solr_server_host::SolrSingleServerHost; - /// # use solrstice::models::auth::SolrBasicAuth; - /// # use solrstice::models::context::SolrServerContextBuilder; - /// # use solrstice::queries::components::facet_set::FacetSetComponent; - /// # use solrstice::queries::components::json_facet::{JsonFacetComponent, JsonQueryFacet, JsonStatFacet}; - /// # use solrstice::queries::select::SelectQuery; + /// use solrstice::{AsyncSolrCloudClient, JsonFacetComponent, JsonQueryFacet, JsonStatFacet, SelectQuery, SolrSingleServerHost}; + /// # use solrstice::SolrServerContextBuilder; /// # async fn run() -> Result<(), Box> { /// # let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).build(); /// let client = AsyncSolrCloudClient::new(context); @@ -402,13 +371,9 @@ impl JsonQueryFacet { /// A facet that does a query and gets the number of results /// # Examples /// ```no_run -/// # use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; -/// # use solrstice::hosts::solr_server_host::SolrSingleServerHost; -/// # use solrstice::models::auth::SolrBasicAuth; -/// # use solrstice::models::context::SolrServerContextBuilder; -/// # use solrstice::queries::components::facet_set::FacetSetComponent; -/// # use solrstice::queries::components::json_facet::{JsonFacetComponent, JsonQueryFacet, JsonStatFacet}; -/// # use solrstice::queries::select::SelectQuery; +/// use solrstice::{AsyncSolrCloudClient, JsonFacetComponent, JsonQueryFacet, JsonStatFacet, SelectQuery, SolrSingleServerHost}; +/// # use solrstice::SolrServerContextBuilder; +/// /// # async fn run() -> Result<(), Box> { /// # let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).build(); /// let client = AsyncSolrCloudClient::new(context); @@ -440,13 +405,8 @@ impl JsonStatFacet { /// Create a new JsonStatFacet /// # Examples /// ```no_run - /// # use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; - /// # use solrstice::hosts::solr_server_host::SolrSingleServerHost; - /// # use solrstice::models::auth::SolrBasicAuth; - /// # use solrstice::models::context::SolrServerContextBuilder; - /// # use solrstice::queries::components::facet_set::FacetSetComponent; - /// # use solrstice::queries::components::json_facet::{JsonFacetComponent, JsonQueryFacet, JsonStatFacet}; - /// # use solrstice::queries::select::SelectQuery; + /// use solrstice::{AsyncSolrCloudClient, JsonFacetComponent, JsonQueryFacet, JsonStatFacet, SelectQuery, SolrSingleServerHost}; + /// # use solrstice::SolrServerContextBuilder; /// # async fn run() -> Result<(), Box> { /// # let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).build(); /// let client = AsyncSolrCloudClient::new(context); diff --git a/framework/src/queries/components/mod.rs b/framework/src/queries/components/mod.rs index f4912e5..5258410 100644 --- a/framework/src/queries/components/mod.rs +++ b/framework/src/queries/components/mod.rs @@ -1,10 +1,10 @@ //! Components for queries. /// Grouping component -pub mod grouping; +pub(crate) mod grouping; /// Facet count component -pub mod facet_set; +pub(crate) mod facet_set; /// Json facet component -pub mod json_facet; +pub(crate) mod json_facet; diff --git a/framework/src/queries/config.rs b/framework/src/queries/config.rs index 56c4501..24e94c3 100644 --- a/framework/src/queries/config.rs +++ b/framework/src/queries/config.rs @@ -1,5 +1,5 @@ +use crate::error::Error; use crate::models::context::SolrServerContext; -use crate::models::error::SolrError; use crate::queries::request_builder::SolrRequestBuilder; use std::fs::File; use std::io::{Read, Seek, Write}; @@ -14,7 +14,7 @@ fn zip_dir( prefix: &Path, writer: T, method: zip::CompressionMethod, -) -> Result<(), SolrError> +) -> Result<(), Error> where T: Write + Seek, { @@ -43,7 +43,7 @@ pub async fn upload_config, S: AsRef, P: AsRef< context: C, name: S, path: P, -) -> Result<(), SolrError> { +) -> Result<(), Error> { let query_params = [("action", "UPLOAD"), ("name", name.as_ref())]; let mut outfile = tempfile()?; path.as_ref().try_exists()?; @@ -71,16 +71,14 @@ pub async fn upload_config, S: AsRef, P: AsRef< Ok(()) } -pub async fn get_configs>( - context: C, -) -> Result, SolrError> { +pub async fn get_configs>(context: C) -> Result, Error> { let query_params = [("action", "LIST"), ("wt", "json")]; let json = SolrRequestBuilder::new(context.as_ref(), "/solr/admin/configs") .with_query_params(query_params.as_ref()) .send_get() .await?; match json.config_sets { - None => Err(SolrError::Unknown("Could not get configsets".to_string())), + None => Err(Error::Unknown("Could not get configsets".to_string())), Some(config_sets) => Ok(config_sets), } } @@ -88,7 +86,7 @@ pub async fn get_configs>( pub async fn config_exists, S: AsRef>( context: C, name: S, -) -> Result { +) -> Result { let configs = get_configs(context).await?; Ok(configs.contains(&name.as_ref().to_string())) } @@ -96,7 +94,7 @@ pub async fn config_exists, S: AsRef>( pub async fn delete_config, S: AsRef>( context: C, name: S, -) -> Result<(), SolrError> { +) -> Result<(), Error> { let query_params = [("action", "DELETE"), ("name", name.as_ref())]; SolrRequestBuilder::new(context.as_ref(), "/solr/admin/configs") .with_query_params(query_params.as_ref()) @@ -113,16 +111,14 @@ pub fn upload_config_blocking, S: AsRef, P: AsR context: C, name: S, path: P, -) -> Result<(), SolrError> { +) -> Result<(), Error> { RUNTIME .handle() .block_on(upload_config(context, name, path)) } #[cfg(feature = "blocking")] -pub fn get_configs_blocking>( - context: C, -) -> Result, SolrError> { +pub fn get_configs_blocking>(context: C) -> Result, Error> { RUNTIME.handle().block_on(get_configs(context)) } @@ -130,7 +126,7 @@ pub fn get_configs_blocking>( pub fn config_exists_blocking, S: AsRef>( context: C, name: S, -) -> Result { +) -> Result { RUNTIME.handle().block_on(config_exists(context, name)) } @@ -138,6 +134,6 @@ pub fn config_exists_blocking, S: AsRef>( pub fn delete_config_blocking, S: AsRef>( context: C, name: S, -) -> Result<(), SolrError> { +) -> Result<(), Error> { RUNTIME.handle().block_on(delete_config(context, name)) } diff --git a/framework/src/queries/def_type.rs b/framework/src/queries/def_type.rs index 1a18cc4..ba562f7 100644 --- a/framework/src/queries/def_type.rs +++ b/framework/src/queries/def_type.rs @@ -25,11 +25,10 @@ pub enum QueryOperator { /// Documentation can be found at [SolrDocs](https://solr.apache.org/guide/8_11/the-standard-query-parser.html) /// # Examples /// ```no_run -/// # use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; -/// # use solrstice::hosts::solr_server_host::SolrSingleServerHost; -/// # use solrstice::models::context::SolrServerContextBuilder; -/// # use solrstice::queries::def_type::{DefType, LuceneQuery}; -/// # use solrstice::queries::select::SelectQuery; +/// # use solrstice::{AsyncSolrCloudClient, SolrSingleServerHost}; +/// # use solrstice::SolrServerContextBuilder; +/// # use solrstice::{DefType, LuceneQuery}; +/// # use solrstice::SelectQuery; /// # async fn run() -> Result<(), Box> { /// # let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).build(); /// # let client = AsyncSolrCloudClient::new(context); @@ -75,11 +74,10 @@ impl LuceneQuery { /// Create a new lucene query /// # Examples /// ```no_run - /// # use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; - /// # use solrstice::hosts::solr_server_host::SolrSingleServerHost; - /// # use solrstice::models::context::SolrServerContextBuilder; - /// # use solrstice::queries::def_type::{DefType, LuceneQuery}; - /// # use solrstice::queries::select::SelectQuery; + /// # use solrstice::{AsyncSolrCloudClient, SolrSingleServerHost}; + /// # use solrstice::SolrServerContextBuilder; + /// # use solrstice::{DefType, LuceneQuery}; + /// # use solrstice::SelectQuery; /// # async fn run() -> Result<(), Box> { /// # let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).build(); /// # let client = AsyncSolrCloudClient::new(context); @@ -120,11 +118,10 @@ impl LuceneQuery { /// Documentation can be found at [SolrDocs](https://solr.apache.org/guide/8_11/the-dismax-query-parser.html) /// # Examples /// ```no_run -/// # use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; -/// # use solrstice::hosts::solr_server_host::SolrSingleServerHost; -/// # use solrstice::models::context::SolrServerContextBuilder; -/// # use solrstice::queries::def_type::{DefType, DismaxQuery}; -/// # use solrstice::queries::select::SelectQuery; +/// # use solrstice::{AsyncSolrCloudClient, SolrSingleServerHost}; +/// # use solrstice::SolrServerContextBuilder; +/// # use solrstice::{DefType, DismaxQuery}; +/// # use solrstice::SelectQuery; /// # async fn run() -> Result<(), Box> { /// # let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).build(); /// # let client = AsyncSolrCloudClient::new(context); @@ -188,11 +185,10 @@ impl DismaxQuery { /// Create a new dismax query /// /// ```no_run - /// # use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; - /// # use solrstice::hosts::solr_server_host::SolrSingleServerHost; - /// # use solrstice::models::context::SolrServerContextBuilder; - /// # use solrstice::queries::def_type::{DefType, DismaxQuery}; - /// # use solrstice::queries::select::SelectQuery; + /// # use solrstice::{AsyncSolrCloudClient, SolrSingleServerHost}; + /// # use solrstice::SolrServerContextBuilder; + /// # use solrstice::{DefType, DismaxQuery}; + /// # use solrstice::SelectQuery; /// # async fn run() -> Result<(), Box> { /// # let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")).build(); /// # let client = AsyncSolrCloudClient::new(context); diff --git a/framework/src/queries/index.rs b/framework/src/queries/index.rs index 5a4e3d6..269be29 100644 --- a/framework/src/queries/index.rs +++ b/framework/src/queries/index.rs @@ -1,6 +1,6 @@ +use crate::error::Error; use crate::models::commit_type::CommitType; use crate::models::context::SolrServerContext; -use crate::models::error::SolrError; use crate::models::response::SolrResponse; use crate::queries::request_builder::SolrRequestBuilder; use serde::{Deserialize, Serialize}; @@ -8,13 +8,10 @@ use serde::{Deserialize, Serialize}; /// A builder for the update handler. /// # Examples /// ```no_run -/// # use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; -/// # use solrstice::hosts::solr_server_host::SolrSingleServerHost; -/// # use solrstice::models::context::SolrServerContextBuilder; -/// # use solrstice::queries::index::UpdateQuery; -/// # use serde::Serialize; -/// # use solrstice::models::commit_type::CommitType; -/// # async fn run() -> Result<(), Box> { +/// use serde::Serialize; +/// use solrstice::{AsyncSolrCloudClient, CommitType, SolrServerContextBuilder, SolrSingleServerHost, UpdateQuery}; +/// +/// async fn run() -> Result<(), Box> { /// #[derive(Serialize)] /// struct Data {id: String} /// @@ -46,13 +43,11 @@ impl UpdateQuery { /// Create a new instance of UpdateQuery. /// # Examples /// ```no_run - /// # use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; - /// # use solrstice::hosts::solr_server_host::SolrSingleServerHost; - /// # use solrstice::models::context::SolrServerContextBuilder; - /// # use solrstice::queries::index::UpdateQuery; - /// # use serde::Serialize; - /// # use solrstice::models::commit_type::CommitType; - /// # async fn run() -> Result<(), Box> { + /// # use serde::Serialize; /// + /// + /// use solrstice::{AsyncSolrCloudClient, CommitType, SolrServerContextBuilder, SolrSingleServerHost, UpdateQuery}; + /// + /// async fn run() -> Result<(), Box> { /// #[derive(Serialize)] /// struct Data {id: String} /// @@ -72,7 +67,7 @@ impl UpdateQuery { /// Set the handler for the query. Default is "update". /// # Examples /// ```no_run - /// use solrstice::queries::index::UpdateQuery; + /// use solrstice::UpdateQuery; /// let builder = UpdateQuery::new().handler("custom_handler"); /// ``` pub fn handler>(mut self, handler: S) -> Self { @@ -83,8 +78,8 @@ impl UpdateQuery { /// Set the commit type for the query. Default is CommitType::Hard. /// # Examples /// ```no_run - /// use solrstice::models::commit_type::CommitType; - /// use solrstice::queries::index::UpdateQuery; + /// use solrstice::CommitType; + /// use solrstice::UpdateQuery; /// let builder = UpdateQuery::new().commit_type(CommitType::Soft); /// ``` pub fn commit_type(mut self, commit_type: CommitType) -> Self { @@ -100,7 +95,7 @@ impl UpdateQuery { context: C, collection: S, data: &[D], - ) -> Result { + ) -> Result { let mut query_params = vec![("overwrite", "true")]; match self.commit_type { CommitType::Hard => query_params.push(("commit", "true")), @@ -122,13 +117,10 @@ impl UpdateQuery { /// Since there is no way to delete properly with JSON, it uses XML. /// # Examples /// ```no_run -/// # use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; -/// # use solrstice::hosts::solr_server_host::SolrSingleServerHost; -/// # use solrstice::models::context::SolrServerContextBuilder; -/// # use solrstice::queries::index::DeleteQuery; -/// # use serde::Serialize; -/// # use solrstice::models::commit_type::CommitType; -/// # async fn run() -> Result<(), Box> { +/// use serde::Serialize; +/// use solrstice::{AsyncSolrCloudClient, DeleteQuery, SolrServerContextBuilder, SolrSingleServerHost}; +/// +/// async fn run() -> Result<(), Box> { /// #[derive(Serialize)] /// struct Data {id: String} /// @@ -166,13 +158,10 @@ impl DeleteQuery { /// Create a new instance of DeleteQuery. /// # Examples /// ```no_run - /// # use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; - /// # use solrstice::hosts::solr_server_host::SolrSingleServerHost; - /// # use solrstice::models::context::SolrServerContextBuilder; - /// # use solrstice::queries::index::DeleteQuery; - /// # use serde::Serialize; - /// # use solrstice::models::commit_type::CommitType; - /// # async fn run() -> Result<(), Box> { + /// use serde::Serialize; + /// use solrstice::{AsyncSolrCloudClient, DeleteQuery, SolrServerContextBuilder, SolrSingleServerHost}; + /// + /// async fn run() -> Result<(), Box> { /// #[derive(Serialize)] /// struct Data {id: String} /// @@ -194,7 +183,7 @@ impl DeleteQuery { /// Set the handler for the query. Default is "update". /// # Examples /// ```no_run - /// use solrstice::queries::index::DeleteQuery; + /// use solrstice::DeleteQuery; /// let builder = DeleteQuery::new().handler("custom_handler"); /// ``` pub fn handler>(mut self, handler: S) -> Self { @@ -205,8 +194,8 @@ impl DeleteQuery { /// Set the commit_type for the query. Default is CommitType::Hard. /// # Examples /// ```no_run - /// use solrstice::models::commit_type::CommitType; - /// use solrstice::queries::index::DeleteQuery; + /// use solrstice::CommitType; + /// use solrstice::DeleteQuery; /// let builder = DeleteQuery::new().commit_type(CommitType::Soft); /// ``` pub fn commit_type(mut self, commit_type: CommitType) -> Self { @@ -217,7 +206,7 @@ impl DeleteQuery { /// Set the ids to delete /// # Examples /// ```no_run - /// use solrstice::queries::index::DeleteQuery; + /// use solrstice::DeleteQuery; /// let builder = DeleteQuery::new().ids(["document1", "document2"]); /// ``` pub fn ids, V: IntoIterator, O: Into>>( @@ -233,7 +222,7 @@ impl DeleteQuery { /// Set the queries to delete /// # Examples /// ```no_run - /// use solrstice::queries::index::DeleteQuery; + /// use solrstice::DeleteQuery; /// let builder = DeleteQuery::new().queries(["age:[* TO *]"]); /// ``` pub fn queries, V: IntoIterator, O: Into>>( @@ -253,7 +242,7 @@ impl DeleteQuery { &self, context: C, collection: S, - ) -> Result { + ) -> Result { let ids = self.ids.as_ref().map(|ids| { ids.iter() .map(|id| format!("{}", id)) @@ -301,7 +290,7 @@ impl UpdateQuery { context: C, collection: S, data: &[D], - ) -> Result { + ) -> Result { RUNTIME .handle() .block_on(self.execute(context, collection, data)) @@ -316,7 +305,7 @@ impl DeleteQuery { &self, context: C, collection: S, - ) -> Result { + ) -> Result { RUNTIME.handle().block_on(self.execute(context, collection)) } } diff --git a/framework/src/queries/mod.rs b/framework/src/queries/mod.rs index 1915ed2..1077ac8 100644 --- a/framework/src/queries/mod.rs +++ b/framework/src/queries/mod.rs @@ -9,10 +9,10 @@ pub mod components; /// Config API pub mod config; /// Def types for select queries. Eg: `luscene`, `edismax` -pub mod def_type; +pub(crate) mod def_type; /// Index and Delete API -pub mod index; +pub(crate) mod index; /// Request builder for queries -pub mod request_builder; +pub(crate) mod request_builder; /// Select query API -pub mod select; +pub(crate) mod select; diff --git a/framework/src/queries/request_builder.rs b/framework/src/queries/request_builder.rs index 5b8d88d..c873a9b 100644 --- a/framework/src/queries/request_builder.rs +++ b/framework/src/queries/request_builder.rs @@ -1,5 +1,5 @@ +use crate::error::{try_solr_error, Error}; use crate::models::context::SolrServerContext; -use crate::models::error::{try_solr_error, SolrError}; use crate::models::response::SolrResponse; use log::debug; use reqwest::header::HeaderMap; @@ -58,7 +58,7 @@ impl<'a> SolrRequestBuilder<'a> { self } - pub async fn send_get(self) -> Result { + pub async fn send_get(self) -> Result { let request = create_standard_request( self.context, self.url, @@ -82,7 +82,7 @@ impl<'a> SolrRequestBuilder<'a> { pub async fn send_post_with_json( self, json: &T, - ) -> Result { + ) -> Result { let mut request = create_standard_request( self.context, self.url, @@ -104,10 +104,7 @@ impl<'a> SolrRequestBuilder<'a> { Ok(solr_response) } - pub async fn send_post_with_body>( - self, - data: T, - ) -> Result { + pub async fn send_post_with_body>(self, data: T) -> Result { let mut request = create_standard_request( self.context, self.url, @@ -136,7 +133,7 @@ async fn create_standard_request<'a>( request_type: SolrRequestType, query_params: Option<&'a [(&'a str, &'a str)]>, headers: Option<&Vec<(String, String)>>, -) -> Result { +) -> Result { let url = format!("{}{}", context.host.get_solr_node().await?, url); let mut request = match request_type { SolrRequestType::Get => context.client.get(url), @@ -157,15 +154,15 @@ async fn create_standard_request<'a>( Ok(request) } -async fn try_request_auth_error(response: &Response) -> Result<(), SolrError> { +async fn try_request_auth_error(response: &Response) -> Result<(), Error> { match response.error_for_status_ref() { Ok(_) => Ok(()), Err(e) => { - if e.status().ok_or(SolrError::Unknown( + if e.status().ok_or(Error::Unknown( "Error while getting response code from request".to_string(), ))? == 401 { - Err(SolrError::SolrAuthError( + Err(Error::SolrAuthError( "Authentication failed with 401. Check credentials.".to_string(), )) } else { diff --git a/framework/src/queries/select.rs b/framework/src/queries/select.rs index 176c519..4b525dc 100644 --- a/framework/src/queries/select.rs +++ b/framework/src/queries/select.rs @@ -1,7 +1,7 @@ use serde::{Deserialize, Serialize}; +use crate::error::Error; use crate::models::context::SolrServerContext; -use crate::models::error::SolrError; use crate::models::response::SolrResponse; use crate::queries::components::facet_set::FacetSetComponent; use crate::queries::components::grouping::GroupingComponent; @@ -18,9 +18,9 @@ struct PostQueryWrapper { /// Builder for a select query. /// -/// Also take a look at [AsyncSolrCloudClient::select](crate::clients::async_cloud_client::AsyncSolrCloudClient::select) +/// Also take a look at [AsyncSolrCloudClient::select](crate::AsyncSolrCloudClient::select) /// ```rust -/// use solrstice::queries::select::SelectQuery; +/// use solrstice::SelectQuery; /// SelectQuery::new().fq(["field1:val1", "field2:val2"]).q("*:*").rows(10).start(0); /// ``` #[derive(Serialize, Deserialize, Clone, Default, PartialEq, Debug)] @@ -63,9 +63,9 @@ impl AsRef for SelectQuery { impl SelectQuery { /// Builder for a select query. /// - /// Also take a look at [AsyncSolrCloudClient::select](crate::clients::async_cloud_client::AsyncSolrCloudClient::select) + /// Also take a look at [AsyncSolrCloudClient::select](crate::select) /// ```rust - /// use solrstice::queries::select::SelectQuery; + /// use solrstice::SelectQuery; /// SelectQuery::new().fq(["field1:val1", "field2:val2"]).q("*:*").rows(10).start(0); /// ``` pub fn new() -> Self { @@ -93,7 +93,7 @@ impl SelectQuery { /// A list of filter queries /// ```rust - /// use solrstice::queries::select::SelectQuery; + /// use solrstice::SelectQuery; /// SelectQuery::new().fq(["id:1"]); /// ``` pub fn fq, V: IntoIterator, O: Into>>( @@ -108,7 +108,7 @@ impl SelectQuery { /// Set the fields to return /// ```rust - /// use solrstice::queries::select::SelectQuery; + /// use solrstice::SelectQuery; /// SelectQuery::new().fl(["field1", "field2"]); /// ``` pub fn fl, V: IntoIterator, O: Into>>( @@ -123,7 +123,7 @@ impl SelectQuery { ///Set the sort order ///```rust - /// use solrstice::queries::select::SelectQuery; + /// use solrstice::SelectQuery; /// SelectQuery::new().sort(["id asc", "field1 desc"]); /// ``` pub fn sort, V: IntoIterator, O: Into>>( @@ -138,7 +138,7 @@ impl SelectQuery { /// How many rows to return /// ```rust - /// use solrstice::queries::select::SelectQuery; + /// use solrstice::SelectQuery; /// SelectQuery::new().rows(1000); /// ``` pub fn rows(mut self, rows: usize) -> Self { @@ -148,7 +148,7 @@ impl SelectQuery { /// The offset to start from /// ```rust - /// use solrstice::queries::select::SelectQuery; + /// use solrstice::SelectQuery; /// SelectQuery::new().start(10); /// ``` pub fn start(mut self, start: usize) -> Self { @@ -159,11 +159,8 @@ impl SelectQuery { /// Use a cursor mark to iterate over the results /// Default starts with "*", and which causes [SolrResponse::next_cursor_mark](crate::models::response::SolrResponse::next_cursor_mark) to be set. And can be provided for the next select. /// ```no_run - /// use solrstice::queries::select::SelectQuery; - /// # use solrstice::models::context::SolrServerContextBuilder; - /// # use solrstice::clients::async_cloud_client; - /// use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; - /// # use solrstice::hosts::solr_server_host::SolrSingleServerHost; + /// use solrstice::{AsyncSolrCloudClient, SelectQuery, SolrSingleServerHost}; + /// # use solrstice::SolrServerContextBuilder; /// # async fn run() -> Result<(), Box> { /// # let client = AsyncSolrCloudClient::new(SolrServerContextBuilder::new(SolrSingleServerHost::new("localhost:8983")).build()); /// let mut builder = SelectQuery::new().cursor_mark("*"); @@ -190,11 +187,9 @@ impl SelectQuery { /// Do a grouping query. Also take a look at [SolrGroupResult](crate::models::group::SolrGroupResult) and [SolrGroupFieldResult](crate::models::group::SolrGroupFieldResult) /// # Examples /// ```no_run - /// # use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; - /// # use solrstice::hosts::solr_server_host::SolrSingleServerHost; - /// # use solrstice::models::context::SolrServerContextBuilder; - /// use solrstice::queries::components::grouping::GroupingComponent; - /// use solrstice::queries::select::SelectQuery; + /// use solrstice::{GroupingComponent, SelectQuery, SolrSingleServerHost}; + /// # use solrstice::AsyncSolrCloudClient; + /// # use solrstice::SolrServerContextBuilder; /// # async fn run() -> Result<(), Box> { /// # let client = AsyncSolrCloudClient::new(SolrServerContextBuilder::new(SolrSingleServerHost::new("localhost:8983")).build()); /// let builder = SelectQuery::new() @@ -219,12 +214,9 @@ impl SelectQuery { /// Note. The default q parameter is *:*, which will not work on `dismax` or `edismax`. So you need to specify a query. /// # Examples /// ```no_run - /// # use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; - /// # use solrstice::hosts::solr_server_host::SolrSingleServerHost; - /// # use solrstice::models::context::SolrServerContextBuilder; - /// use solrstice::queries::components::grouping::GroupingComponent; - /// use solrstice::queries::def_type::{DefType, EdismaxQuery}; - /// use solrstice::queries::select::SelectQuery; + /// use solrstice::{DefType, EdismaxQuery, SelectQuery, SolrSingleServerHost}; + /// # use solrstice::AsyncSolrCloudClient; + /// # use solrstice::SolrServerContextBuilder; /// # async fn run() -> Result<(), Box> { /// # let client = AsyncSolrCloudClient::new(SolrServerContextBuilder::new(SolrSingleServerHost::new("localhost:8983")).build()); /// let builder = SelectQuery::new() @@ -259,7 +251,7 @@ impl SelectQuery { &self, context: C, collection: T, - ) -> Result { + ) -> Result { let solr_url = format!("/solr/{}/{}", collection.as_ref(), &self.handle); let wrapper = PostQueryWrapper { params: self.clone(), @@ -277,7 +269,7 @@ impl SelectQuery { &self, context: C, collection: S, - ) -> Result { + ) -> Result { RUNTIME.handle().block_on(self.execute(context, collection)) } } diff --git a/framework/src/runtime.rs b/framework/src/runtime.rs index 73b0a3f..6b02b1a 100644 --- a/framework/src/runtime.rs +++ b/framework/src/runtime.rs @@ -1,5 +1,5 @@ lazy_static::lazy_static! { - pub static ref RUNTIME: tokio::runtime::Runtime = { + pub(crate) static ref RUNTIME: tokio::runtime::Runtime = { tokio::runtime::Runtime::new().expect("Failed to create runtime for blocking calls") }; } diff --git a/framework/tests/functionality/auth_test.rs b/framework/tests/functionality/auth_test.rs index dd333b3..c1b4bfd 100644 --- a/framework/tests/functionality/auth_test.rs +++ b/framework/tests/functionality/auth_test.rs @@ -1,13 +1,13 @@ use crate::structures::BaseTestsBuildup; use serial_test::parallel; -use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; -use solrstice::models::auth::SolrBasicAuth; -use solrstice::models::context::SolrServerContextBuilder; -use solrstice::models::error::SolrError; +use solrstice::AsyncSolrCloudClient; +use solrstice::Error; +use solrstice::SolrBasicAuth; +use solrstice::SolrServerContextBuilder; #[tokio::test] #[parallel] -async fn auth_gives_sensible_error_when_not_provided() -> Result<(), SolrError> { +async fn auth_gives_sensible_error_when_not_provided() -> Result<(), Error> { let config = BaseTestsBuildup::new().await; if config.auth.is_none() { return Ok(()); @@ -16,19 +16,17 @@ async fn auth_gives_sensible_error_when_not_provided() -> Result<(), SolrError> let client = AsyncSolrCloudClient::new(context); let response = client.get_collections().await; match response { - Ok(_) => Err(SolrError::Unknown("Should not have succeeded".to_string())), + Ok(_) => Err(Error::Unknown("Should not have succeeded".to_string())), Err(e) => match e { - SolrError::SolrAuthError(_) => Ok(()), - _ => Err(SolrError::Unknown( - "Should have been auth error".to_string(), - )), + Error::SolrAuthError(_) => Ok(()), + _ => Err(Error::Unknown("Should have been auth error".to_string())), }, } } #[tokio::test] #[parallel] -async fn auth_gives_sensible_error_when_wrong() -> Result<(), SolrError> { +async fn auth_gives_sensible_error_when_wrong() -> Result<(), Error> { let config = BaseTestsBuildup::new().await; if config.auth.is_none() { return Ok(()); @@ -39,12 +37,10 @@ async fn auth_gives_sensible_error_when_wrong() -> Result<(), SolrError> { let client = AsyncSolrCloudClient::new(context); let response = client.get_collections().await; match response { - Ok(_) => Err(SolrError::Unknown("Should not have succeeded".to_string())), + Ok(_) => Err(Error::Unknown("Should not have succeeded".to_string())), Err(e) => match e { - SolrError::SolrAuthError(_) => Ok(()), - _ => Err(SolrError::Unknown( - "Should have been auth error".to_string(), - )), + Error::SolrAuthError(_) => Ok(()), + _ => Err(Error::Unknown("Should have been auth error".to_string())), }, } } diff --git a/framework/tests/functionality/client_tests.rs b/framework/tests/functionality/client_tests.rs index b00b4eb..3442621 100644 --- a/framework/tests/functionality/client_tests.rs +++ b/framework/tests/functionality/client_tests.rs @@ -1,9 +1,9 @@ use crate::structures::BaseTestsBuildup; use serde::{Deserialize, Serialize}; use serial_test::parallel; -use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; -use solrstice::queries::index::{DeleteQuery, UpdateQuery}; -use solrstice::queries::select::SelectQuery; +use solrstice::AsyncSolrCloudClient; +use solrstice::SelectQuery; +use solrstice::{DeleteQuery, UpdateQuery}; use std::path::Path; use tokio::join; diff --git a/framework/tests/functionality/config_test.rs b/framework/tests/functionality/config_test.rs index d09c67d..508dce3 100644 --- a/framework/tests/functionality/config_test.rs +++ b/framework/tests/functionality/config_test.rs @@ -1,12 +1,12 @@ use crate::structures::BaseTestsBuildup; use serial_test::parallel; -use solrstice::models::error::SolrError; use solrstice::queries::config::{config_exists, delete_config, get_configs, upload_config}; +use solrstice::Error; use std::path::Path; #[tokio::test] #[parallel] -async fn upload_config_uploads_config() -> Result<(), SolrError> { +async fn upload_config_uploads_config() -> Result<(), Error> { let config = BaseTestsBuildup::new().await; let _ = delete_config(&config.context, "UploadConfig").await; assert!(!config_exists(&config.context, "UploadConfig") @@ -30,7 +30,7 @@ async fn upload_config_uploads_config() -> Result<(), SolrError> { #[tokio::test] #[parallel] -async fn get_configs_gets_configs() -> Result<(), SolrError> { +async fn get_configs_gets_configs() -> Result<(), Error> { let config = BaseTestsBuildup::new().await; let configs = get_configs(&config.context).await.unwrap(); assert!(configs.contains(&"_default".to_string())); @@ -39,7 +39,7 @@ async fn get_configs_gets_configs() -> Result<(), SolrError> { #[tokio::test] #[parallel] -async fn delete_config_deletes_config() -> Result<(), SolrError> { +async fn delete_config_deletes_config() -> Result<(), Error> { let config = BaseTestsBuildup::new().await; let _ = delete_config(&config.context, "DeleteConfig").await; upload_config( @@ -63,7 +63,7 @@ async fn delete_config_deletes_config() -> Result<(), SolrError> { #[tokio::test] #[parallel] -async fn config_exists_works_when_config_exists() -> Result<(), SolrError> { +async fn config_exists_works_when_config_exists() -> Result<(), Error> { let config = BaseTestsBuildup::new().await; assert!(config_exists(&config.context, "_default").await.unwrap()); Ok(()) @@ -71,7 +71,7 @@ async fn config_exists_works_when_config_exists() -> Result<(), SolrError> { #[tokio::test] #[parallel] -async fn config_exists_works_when_config_doesent_exist() -> Result<(), SolrError> { +async fn config_exists_works_when_config_doesent_exist() -> Result<(), Error> { let config = BaseTestsBuildup::new().await; assert!(!config_exists(&config.context, "_this_does_not_exist") .await diff --git a/framework/tests/functionality/def_type_test.rs b/framework/tests/functionality/def_type_test.rs index a25311b..c938010 100644 --- a/framework/tests/functionality/def_type_test.rs +++ b/framework/tests/functionality/def_type_test.rs @@ -1,13 +1,13 @@ use crate::structures::{get_test_data, FunctionalityTestsBuildup, Population}; use serial_test::parallel; -use solrstice::models::error::SolrError; -use solrstice::queries::def_type::{DefType, DismaxQuery, EdismaxQuery, LuceneQuery}; -use solrstice::queries::index::UpdateQuery; -use solrstice::queries::select::SelectQuery; +use solrstice::Error; +use solrstice::SelectQuery; +use solrstice::UpdateQuery; +use solrstice::{DefType, DismaxQuery, EdismaxQuery, LuceneQuery}; #[tokio::test] #[parallel] -pub async fn test_dismax_query_parser() -> Result<(), SolrError> { +pub async fn test_dismax_query_parser() -> Result<(), Error> { let config = FunctionalityTestsBuildup::build_up("Dismax").await.unwrap(); let update = UpdateQuery::new(); update @@ -33,7 +33,7 @@ pub async fn test_dismax_query_parser() -> Result<(), SolrError> { #[tokio::test] #[parallel] -pub async fn test_edismax_query_parser() -> Result<(), SolrError> { +pub async fn test_edismax_query_parser() -> Result<(), Error> { let config = FunctionalityTestsBuildup::build_up("Edismax") .await .unwrap(); @@ -62,7 +62,7 @@ pub async fn test_edismax_query_parser() -> Result<(), SolrError> { #[tokio::test] #[parallel] -pub async fn test_lucene_query_parser() -> Result<(), SolrError> { +pub async fn test_lucene_query_parser() -> Result<(), Error> { let config = FunctionalityTestsBuildup::build_up("Lucene").await.unwrap(); let update = UpdateQuery::new(); update diff --git a/framework/tests/functionality/facetset_test.rs b/framework/tests/functionality/facetset_test.rs index 0e4d143..6de9ab4 100644 --- a/framework/tests/functionality/facetset_test.rs +++ b/framework/tests/functionality/facetset_test.rs @@ -1,15 +1,13 @@ use crate::structures::{get_test_data, FunctionalityTestsBuildup}; use serial_test::parallel; -use solrstice::models::error::SolrError; -use solrstice::queries::components::facet_set::{ - FacetSetComponent, FieldFacetComponent, FieldFacetEntry, PivotFacetComponent, -}; -use solrstice::queries::index::UpdateQuery; -use solrstice::queries::select::SelectQuery; +use solrstice::Error; +use solrstice::SelectQuery; +use solrstice::UpdateQuery; +use solrstice::{FacetSetComponent, FieldFacetComponent, FieldFacetEntry, PivotFacetComponent}; #[tokio::test] #[parallel] -pub async fn test_facet_pivot_works() -> Result<(), SolrError> { +pub async fn test_facet_pivot_works() -> Result<(), Error> { let config = FunctionalityTestsBuildup::build_up("FacetPivot") .await .unwrap(); @@ -48,7 +46,7 @@ pub async fn test_facet_pivot_works() -> Result<(), SolrError> { #[tokio::test] #[parallel] -pub async fn test_facet_query_works() -> Result<(), SolrError> { +pub async fn test_facet_query_works() -> Result<(), Error> { let config = FunctionalityTestsBuildup::build_up("FacetQuery") .await .unwrap(); @@ -73,7 +71,7 @@ pub async fn test_facet_query_works() -> Result<(), SolrError> { #[tokio::test] #[parallel] -pub async fn test_facet_field_works() -> Result<(), SolrError> { +pub async fn test_facet_field_works() -> Result<(), Error> { let config = FunctionalityTestsBuildup::build_up("FacetField") .await .unwrap(); @@ -100,7 +98,7 @@ pub async fn test_facet_field_works() -> Result<(), SolrError> { #[tokio::test] #[parallel] -pub async fn test_facet_field_exclude_works() -> Result<(), SolrError> { +pub async fn test_facet_field_exclude_works() -> Result<(), Error> { let config = FunctionalityTestsBuildup::build_up("FacetFieldExclude") .await .unwrap(); @@ -130,7 +128,7 @@ pub async fn test_facet_field_exclude_works() -> Result<(), SolrError> { #[tokio::test] #[parallel] -pub async fn test_facet_field_exclude_works_missing() -> Result<(), SolrError> { +pub async fn test_facet_field_exclude_works_missing() -> Result<(), Error> { let config = FunctionalityTestsBuildup::build_up("FacetFieldMissing") .await .unwrap(); diff --git a/framework/tests/functionality/grouping_tests.rs b/framework/tests/functionality/grouping_tests.rs index 91b5d61..6476479 100644 --- a/framework/tests/functionality/grouping_tests.rs +++ b/framework/tests/functionality/grouping_tests.rs @@ -1,14 +1,14 @@ use crate::structures::{get_test_data, FunctionalityTestsBuildup}; use serial_test::parallel; -use solrstice::models::error::SolrError; -use solrstice::queries::components::grouping::{GroupFormatting, GroupingComponent}; -use solrstice::queries::index::UpdateQuery; -use solrstice::queries::select::SelectQuery; +use solrstice::Error; +use solrstice::SelectQuery; +use solrstice::UpdateQuery; +use solrstice::{GroupFormatting, GroupingComponent}; use std::collections::HashMap; #[tokio::test] #[parallel] -async fn group_fields() -> Result<(), SolrError> { +async fn group_fields() -> Result<(), Error> { let config = FunctionalityTestsBuildup::build_up("GroupBasic") .await .unwrap(); @@ -24,7 +24,7 @@ async fn group_fields() -> Result<(), SolrError> { .await?; let groups = response .get_groups() - .ok_or(SolrError::Unknown("No groups found".to_string()))?; + .ok_or(Error::Unknown("No groups found".to_string()))?; let age_group = groups.get("age").unwrap(); let correct_data: HashMap = [(20, 2), (40, 2), (60, 2)].iter().cloned().collect(); for group in age_group.get_field_result().unwrap() { @@ -41,7 +41,7 @@ async fn group_fields() -> Result<(), SolrError> { #[tokio::test] #[parallel] -async fn group_queries() -> Result<(), SolrError> { +async fn group_queries() -> Result<(), Error> { let config = FunctionalityTestsBuildup::build_up("GroupQuery") .await .unwrap(); @@ -60,7 +60,7 @@ async fn group_queries() -> Result<(), SolrError> { .await?; let groups = response .get_groups() - .ok_or(SolrError::Unknown("Could not get groups".to_string()))?; + .ok_or(Error::Unknown("Could not get groups".to_string()))?; let first = groups .get("age:[0 TO 59]") .unwrap() @@ -79,7 +79,7 @@ async fn group_queries() -> Result<(), SolrError> { #[tokio::test] #[parallel] -async fn group_n_groups() -> Result<(), SolrError> { +async fn group_n_groups() -> Result<(), Error> { let config = FunctionalityTestsBuildup::build_up("GroupNGroups") .await .unwrap(); @@ -100,11 +100,11 @@ async fn group_n_groups() -> Result<(), SolrError> { .await?; let groups = response .get_groups() - .ok_or(SolrError::Unknown("Could not get groups".to_string()))?; + .ok_or(Error::Unknown("Could not get groups".to_string()))?; let age_group = groups.get("age").unwrap(); let n_groups = age_group .get_n_groups() - .ok_or(SolrError::Unknown("No n_groups".to_string()))?; + .ok_or(Error::Unknown("No n_groups".to_string()))?; assert_eq!(n_groups, 3); let _ = config.tear_down().await; Ok(()) @@ -112,7 +112,7 @@ async fn group_n_groups() -> Result<(), SolrError> { #[tokio::test] #[parallel] -async fn group_main() -> Result<(), SolrError> { +async fn group_main() -> Result<(), Error> { let config = FunctionalityTestsBuildup::build_up("GroupMain") .await .unwrap(); @@ -140,7 +140,7 @@ async fn group_main() -> Result<(), SolrError> { #[tokio::test] #[parallel] -async fn group_main_false() -> Result<(), SolrError> { +async fn group_main_false() -> Result<(), Error> { let config = FunctionalityTestsBuildup::build_up("GroupMainFalse") .await .unwrap(); @@ -166,7 +166,7 @@ async fn group_main_false() -> Result<(), SolrError> { #[tokio::test] #[parallel] -async fn group_simple() -> Result<(), SolrError> { +async fn group_simple() -> Result<(), Error> { let config = FunctionalityTestsBuildup::build_up("GroupSimple") .await .unwrap(); diff --git a/framework/tests/functionality/index_test.rs b/framework/tests/functionality/index_test.rs index fecabb5..ad6ee4c 100644 --- a/framework/tests/functionality/index_test.rs +++ b/framework/tests/functionality/index_test.rs @@ -1,15 +1,15 @@ use crate::structures::{get_test_data, BaseTestsBuildup, City, FunctionalityTestsBuildup}; use serial_test::parallel; -use solrstice::models::error::SolrError; use solrstice::queries::collection::{create_collection, delete_collection}; use solrstice::queries::config::{delete_config, upload_config}; -use solrstice::queries::index::{DeleteQuery, UpdateQuery}; -use solrstice::queries::select::SelectQuery; +use solrstice::Error; +use solrstice::SelectQuery; +use solrstice::{DeleteQuery, UpdateQuery}; use std::path::Path; #[tokio::test] #[parallel] -async fn index_indexes_documents() -> Result<(), SolrError> { +async fn index_indexes_documents() -> Result<(), Error> { let config = BaseTestsBuildup::new().await; let config_name = "IndexConfig".to_string(); let collection_name = "IndexCollection".to_string(); @@ -42,7 +42,7 @@ async fn index_indexes_documents() -> Result<(), SolrError> { #[tokio::test] #[parallel] -async fn index_indexes_correct_documents() -> Result<(), SolrError> { +async fn index_indexes_correct_documents() -> Result<(), Error> { let config = BaseTestsBuildup::new().await; let config_name = "IndexCorrectConfig".to_string(); let collection_name = "IndexCorrectCollection".to_string(); diff --git a/framework/tests/functionality/json_facet_test.rs b/framework/tests/functionality/json_facet_test.rs index 0071da6..fb45867 100644 --- a/framework/tests/functionality/json_facet_test.rs +++ b/framework/tests/functionality/json_facet_test.rs @@ -1,16 +1,12 @@ use crate::structures::{get_test_data, FunctionalityTestsBuildup}; use serial_test::parallel; -use solrstice::models::error::SolrError; -use solrstice::models::json_facet::SolrJsonFacetResponse; -use solrstice::queries::components::json_facet::{ - JsonFacetComponent, JsonQueryFacet, JsonStatFacet, JsonTermsFacet, -}; -use solrstice::queries::index::UpdateQuery; -use solrstice::queries::select::SelectQuery; +use solrstice::models::SolrJsonFacetResponse; +use solrstice::{Error, SelectQuery, UpdateQuery}; +use solrstice::{JsonFacetComponent, JsonQueryFacet, JsonStatFacet, JsonTermsFacet}; #[tokio::test] #[parallel] -pub async fn test_json_query_facet_works() -> Result<(), SolrError> { +pub async fn test_json_query_facet_works() -> Result<(), Error> { let config = FunctionalityTestsBuildup::build_up("JsonFacetQuery") .await .unwrap(); @@ -39,7 +35,7 @@ pub async fn test_json_query_facet_works() -> Result<(), SolrError> { #[tokio::test] #[parallel] -pub async fn test_json_stat_facet_works() -> Result<(), SolrError> { +pub async fn test_json_stat_facet_works() -> Result<(), Error> { let config = FunctionalityTestsBuildup::build_up("JsonFacetStats") .await .unwrap(); @@ -68,7 +64,7 @@ pub async fn test_json_stat_facet_works() -> Result<(), SolrError> { #[tokio::test] #[parallel] -pub async fn test_json_terms_facet_works() -> Result<(), SolrError> { +pub async fn test_json_terms_facet_works() -> Result<(), Error> { let config = FunctionalityTestsBuildup::build_up("JsonFacetTerms") .await .unwrap(); @@ -97,7 +93,7 @@ pub async fn test_json_terms_facet_works() -> Result<(), SolrError> { #[tokio::test] #[parallel] -pub async fn test_json_facet_sub_works() -> Result<(), SolrError> { +pub async fn test_json_facet_sub_works() -> Result<(), Error> { let config = FunctionalityTestsBuildup::build_up("JsonFacetSub") .await .unwrap(); diff --git a/framework/tests/functionality/logging_test.rs b/framework/tests/functionality/logging_test.rs index d72ba47..eae750b 100644 --- a/framework/tests/functionality/logging_test.rs +++ b/framework/tests/functionality/logging_test.rs @@ -1,10 +1,10 @@ use crate::structures::BaseTestsBuildup; use log::{Metadata, Record}; use serial_test::serial; -use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; -use solrstice::models::context::SolrServerContextBuilder; -use solrstice::models::error::SolrError; -use solrstice::queries::request_builder::LoggingPolicy; +use solrstice::AsyncSolrCloudClient; +use solrstice::Error; +use solrstice::LoggingPolicy; +use solrstice::SolrServerContextBuilder; use std::sync::{Arc, Mutex, OnceLock}; struct TestLogger { @@ -40,7 +40,7 @@ pub fn init_logger() -> Arc>> { #[tokio::test] #[serial] -async fn logging_logs_message() -> Result<(), SolrError> { +async fn logging_logs_message() -> Result<(), Error> { let config = BaseTestsBuildup::new().await; let mut context = SolrServerContextBuilder::new(config.host); if config.auth.is_some() { @@ -62,12 +62,12 @@ async fn logging_logs_message() -> Result<(), SolrError> { return Ok(()); } } - Err(SolrError::Unknown("No log message found".to_string())) + Err(Error::Unknown("No log message found".to_string())) } #[tokio::test] #[serial] -async fn logging_does_not_log_message_if_disabled() -> Result<(), SolrError> { +async fn logging_does_not_log_message_if_disabled() -> Result<(), Error> { let config = BaseTestsBuildup::new().await; let mut context = SolrServerContextBuilder::new(config.host).with_logging_policy(LoggingPolicy::Off); @@ -88,7 +88,7 @@ async fn logging_does_not_log_message_if_disabled() -> Result<(), SolrError> { let messages = LOGGER_MESSAGES.get().unwrap().lock().unwrap(); for message in messages.iter() { if message.contains("Sending Solr request to") { - return Err(SolrError::Unknown(format!( + return Err(Error::Unknown(format!( "Did not expect log message, but got {}", message ))); diff --git a/framework/tests/functionality/readme_test.rs b/framework/tests/functionality/readme_test.rs index 3e684dd..6a3cb57 100644 --- a/framework/tests/functionality/readme_test.rs +++ b/framework/tests/functionality/readme_test.rs @@ -1,13 +1,13 @@ use crate::structures::BaseTestsBuildup; use serde::{Deserialize, Serialize}; -use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; -// use solrstice::hosts::solr_server_host::SolrSingleServerHost; -// use solrstice::models::auth::SolrBasicAuth; -// use solrstice::models::context::SolrServerContextBuilder; +use solrstice::AsyncSolrCloudClient; +// use solrstice::SolrSingleServerHost; +// use solrstice::SolrBasicAuth; +// use solrstice::SolrServerContextBuilder; use serial_test::parallel; -use solrstice::models::error::SolrError; -use solrstice::queries::index::{DeleteQuery, UpdateQuery}; -use solrstice::queries::select::SelectQuery; +use solrstice::Error; +use solrstice::SelectQuery; +use solrstice::{DeleteQuery, UpdateQuery}; use std::path::Path; #[derive(Serialize, Deserialize, Debug)] @@ -17,7 +17,7 @@ struct TestData { #[tokio::test] #[parallel] -pub async fn example() -> Result<(), SolrError> { +pub async fn example() -> Result<(), Error> { let config = BaseTestsBuildup::new().await; //Create a solr client. You can also use a list of zookeeper hosts instead of a single server. diff --git a/framework/tests/functionality/select_test.rs b/framework/tests/functionality/select_test.rs index 2b518e5..75f5c52 100644 --- a/framework/tests/functionality/select_test.rs +++ b/framework/tests/functionality/select_test.rs @@ -1,12 +1,12 @@ use crate::structures::{get_test_data, City, FunctionalityTestsBuildup}; use serial_test::parallel; -use solrstice::models::error::SolrError; -use solrstice::queries::index::UpdateQuery; -use solrstice::queries::select::SelectQuery; +use solrstice::Error; +use solrstice::SelectQuery; +use solrstice::UpdateQuery; #[tokio::test] #[parallel] -async fn select_works_when_no_result() -> Result<(), SolrError> { +async fn select_works_when_no_result() -> Result<(), Error> { let config = FunctionalityTestsBuildup::build_up("SelectNoResult") .await .unwrap(); @@ -30,7 +30,7 @@ async fn select_works_when_no_result() -> Result<(), SolrError> { #[tokio::test] #[parallel] -async fn select_works_when_no_result_serde_value() -> Result<(), SolrError> { +async fn select_works_when_no_result_serde_value() -> Result<(), Error> { let config = FunctionalityTestsBuildup::build_up("SelectNoResultSerdeValue") .await .unwrap(); @@ -54,7 +54,7 @@ async fn select_works_when_no_result_serde_value() -> Result<(), SolrError> { #[tokio::test] #[parallel] -async fn select_works_using_cursor_mark() -> Result<(), SolrError> { +async fn select_works_using_cursor_mark() -> Result<(), Error> { let config = FunctionalityTestsBuildup::build_up("SelectCursorMark") .await .unwrap(); diff --git a/framework/tests/functionality/zk_test.rs b/framework/tests/functionality/zk_test.rs index 003dd2a..3de9d12 100644 --- a/framework/tests/functionality/zk_test.rs +++ b/framework/tests/functionality/zk_test.rs @@ -1,7 +1,7 @@ use crate::structures::BaseTestsBuildup; use serial_test::parallel; -use solrstice::hosts::solr_host::SolrHost; -use solrstice::hosts::zookeeper_host::ZookeeperEnsembleHostConnector; +use solrstice::SolrHost; +use solrstice::ZookeeperEnsembleHostConnector; use std::time::Duration; use std::vec; diff --git a/framework/tests/structures.rs b/framework/tests/structures.rs index 9fdf38b..bfdb96b 100644 --- a/framework/tests/structures.rs +++ b/framework/tests/structures.rs @@ -1,12 +1,12 @@ use serde::{Deserialize, Serialize}; -use solrstice::clients::async_cloud_client::AsyncSolrCloudClient; -use solrstice::hosts::solr_server_host::SolrSingleServerHost; -use solrstice::models::auth::SolrBasicAuth; -use solrstice::models::context::{SolrServerContext, SolrServerContextBuilder}; -use solrstice::models::error::SolrError; +use solrstice; use solrstice::queries::collection::{create_collection, delete_collection}; use solrstice::queries::config::{delete_config, upload_config}; -use solrstice::queries::request_builder::SolrRequestBuilder; +use solrstice::SolrBasicAuth; +use solrstice::SolrRequestBuilder; +use solrstice::SolrSingleServerHost; +use solrstice::{AsyncSolrCloudClient, Error}; +use solrstice::{SolrServerContext, SolrServerContextBuilder}; use std::path::Path; use std::string::ToString; use std::time::Duration; @@ -57,7 +57,7 @@ pub struct FunctionalityTestsBuildup { } impl FunctionalityTestsBuildup { - pub async fn build_up(basename: &str) -> Result { + pub async fn build_up(basename: &str) -> Result { dotenv::from_filename("../test_setup/.env").ok(); let host = std::env::var("SOLR_HOST").unwrap(); let config_path = "../test_setup/test_collection".to_string(); @@ -65,7 +65,7 @@ impl FunctionalityTestsBuildup { let password = std::env::var("SOLR_PASSWORD").unwrap(); let auth = match username.is_empty() { true => { - return Err(SolrError::Unknown( + return Err(Error::Unknown( "Could not find solr username in tests .env file".to_string(), )) } @@ -100,7 +100,7 @@ impl FunctionalityTestsBuildup { }) } - pub async fn tear_down(&self) -> Result<(), SolrError> { + pub async fn tear_down(&self) -> Result<(), Error> { delete_collection(&self.context, &self.collection_name) .await .unwrap(); diff --git a/wrappers/python/src/hosts.rs b/wrappers/python/src/hosts.rs index 615aae0..3dc2d5a 100644 --- a/wrappers/python/src/hosts.rs +++ b/wrappers/python/src/hosts.rs @@ -5,10 +5,10 @@ use crate::models::context::{ use crate::models::error::PyErrWrapper; use async_trait::async_trait; use pyo3::prelude::*; -use solrstice::hosts::solr_host::SolrHost; -use solrstice::hosts::solr_server_host::{SolrMultipleServerHost, SolrSingleServerHost}; -use solrstice::hosts::zookeeper_host::ZookeeperEnsembleHostConnector; -use solrstice::models::error::SolrError; +use solrstice::Error; +use solrstice::SolrHost; +use solrstice::ZookeeperEnsembleHostConnector; +use solrstice::{SolrMultipleServerHost, SolrSingleServerHost}; use std::borrow::Cow; use std::sync::Arc; use std::time::Duration; @@ -37,7 +37,7 @@ pub struct SolrHostWrapper { #[async_trait] impl SolrHost for SolrHostWrapper { - async fn get_solr_node(&self) -> Result, SolrError> { + async fn get_solr_node(&self) -> Result, Error> { self.solr_host.get_solr_node().await } } diff --git a/wrappers/python/src/models/auth.rs b/wrappers/python/src/models/auth.rs index 5ce33f1..904d824 100644 --- a/wrappers/python/src/models/auth.rs +++ b/wrappers/python/src/models/auth.rs @@ -1,5 +1,5 @@ use pyo3::prelude::*; -use solrstice::models::auth::{SolrAuth, SolrBasicAuth}; +use solrstice::{SolrAuth, SolrBasicAuth}; use std::sync::Arc; #[pymodule] diff --git a/wrappers/python/src/models/context.rs b/wrappers/python/src/models/context.rs index 7e6a1f6..36561ce 100644 --- a/wrappers/python/src/models/context.rs +++ b/wrappers/python/src/models/context.rs @@ -2,8 +2,8 @@ use crate::hosts::{SolrHostWrapper, SolrSingleServerHostWrapper}; use crate::models::auth::SolrAuthWrapper; use pyo3::prelude::*; use serde::{Deserialize, Serialize}; -use solrstice::models::context::{SolrServerContext, SolrServerContextBuilder}; -use solrstice::queries::request_builder::LoggingPolicy; +use solrstice::LoggingPolicy; +use solrstice::{SolrServerContext, SolrServerContextBuilder}; #[derive(FromPyObject)] pub enum SolrHostUnion { diff --git a/wrappers/python/src/models/error.rs b/wrappers/python/src/models/error.rs index 474c4fe..5394be7 100644 --- a/wrappers/python/src/models/error.rs +++ b/wrappers/python/src/models/error.rs @@ -2,12 +2,12 @@ use pyo3::exceptions::PyRuntimeError; use pyo3::prelude::*; use pyo3::PyDowncastError; use pythonize::PythonizeError; -use solrstice::models::error::SolrError; +use solrstice::Error; pub struct PyErrWrapper(PyErr); -impl From for PyErrWrapper { - fn from(err: SolrError) -> PyErrWrapper { +impl From for PyErrWrapper { + fn from(err: Error) -> PyErrWrapper { PyErrWrapper(PyRuntimeError::new_err(err.to_string())) } } diff --git a/wrappers/python/src/models/facet_set.rs b/wrappers/python/src/models/facet_set.rs index 78ea45f..7a9cf1d 100644 --- a/wrappers/python/src/models/facet_set.rs +++ b/wrappers/python/src/models/facet_set.rs @@ -5,9 +5,7 @@ use crate::queries::components::facet_set::{ }; use pyo3::prelude::*; use pythonize::pythonize; -use solrstice::models::facet_set::{ - SolrFacetSetResult, SolrFieldFacetResult, SolrPivotFacetResult, -}; +use solrstice::models::{SolrFacetSetResult, SolrFieldFacetResult, SolrPivotFacetResult}; use std::collections::HashMap; #[pymodule] diff --git a/wrappers/python/src/models/group.rs b/wrappers/python/src/models/group.rs index f164ae8..c0214ae 100644 --- a/wrappers/python/src/models/group.rs +++ b/wrappers/python/src/models/group.rs @@ -3,7 +3,7 @@ use crate::models::response::SolrDocsResponseWrapper; use crate::queries::components::grouping::{GroupFormattingWrapper, GroupingComponentWrapper}; use pyo3::prelude::*; use pythonize::pythonize; -use solrstice::models::group::{SolrGroupFieldResult, SolrGroupResult}; +use solrstice::models::{SolrGroupFieldResult, SolrGroupResult}; #[pymodule] pub fn group(_py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> { diff --git a/wrappers/python/src/models/json_facet.rs b/wrappers/python/src/models/json_facet.rs index 0729dbe..f957510 100644 --- a/wrappers/python/src/models/json_facet.rs +++ b/wrappers/python/src/models/json_facet.rs @@ -5,7 +5,7 @@ use crate::queries::components::json_facet::{ }; use pyo3::prelude::*; use pythonize::pythonize; -use solrstice::models::json_facet::SolrJsonFacetResponse; +use solrstice::models::SolrJsonFacetResponse; use std::collections::HashMap; #[pymodule] diff --git a/wrappers/python/src/models/response.rs b/wrappers/python/src/models/response.rs index 52e6525..7858a55 100644 --- a/wrappers/python/src/models/response.rs +++ b/wrappers/python/src/models/response.rs @@ -4,7 +4,7 @@ use crate::models::group::{SolrGroupFieldResultWrapper, SolrGroupResultWrapper}; use crate::models::json_facet::SolrJsonFacetResponseWrapper; use pyo3::prelude::*; use pythonize::pythonize; -use solrstice::models::response::{SolrDocsResponse, SolrResponse}; +use solrstice::models::{SolrDocsResponse, SolrResponse}; use std::collections::HashMap; #[pymodule] diff --git a/wrappers/python/src/queries/alias.rs b/wrappers/python/src/queries/alias.rs index 2e17421..8cfde49 100644 --- a/wrappers/python/src/queries/alias.rs +++ b/wrappers/python/src/queries/alias.rs @@ -1,7 +1,7 @@ use crate::models::context::SolrServerContextWrapper; use crate::models::error::PyErrWrapper; use pyo3::prelude::*; -use solrstice::models::context::SolrServerContext; +use solrstice::SolrServerContext; use solrstice::queries::alias::{ alias_exists as alias_exists_rs, create_alias as create_alias_rs, delete_alias as delete_alias_rs, get_aliases as get_aliases_rs, diff --git a/wrappers/python/src/queries/collection.rs b/wrappers/python/src/queries/collection.rs index 9669b1a..d24f5ff 100644 --- a/wrappers/python/src/queries/collection.rs +++ b/wrappers/python/src/queries/collection.rs @@ -1,7 +1,7 @@ use crate::models::context::SolrServerContextWrapper; use crate::models::error::PyErrWrapper; use pyo3::prelude::*; -use solrstice::models::context::SolrServerContext; +use solrstice::SolrServerContext; use solrstice::queries::collection::{ collection_exists as collection_exists_rs, create_collection as create_collection_rs, delete_collection as delete_collection_rs, get_collections as get_collections_rs, diff --git a/wrappers/python/src/queries/components/facet_set.rs b/wrappers/python/src/queries/components/facet_set.rs index cf27e89..78dd934 100644 --- a/wrappers/python/src/queries/components/facet_set.rs +++ b/wrappers/python/src/queries/components/facet_set.rs @@ -1,5 +1,5 @@ use pyo3::prelude::*; -use solrstice::queries::components::facet_set::{ +use solrstice::{ FacetSetComponent, FieldFacetComponent, FieldFacetEntry, FieldFacetMethod, FieldFacetSort, PivotFacetComponent, }; diff --git a/wrappers/python/src/queries/components/grouping.rs b/wrappers/python/src/queries/components/grouping.rs index f7d4b0e..c384d28 100644 --- a/wrappers/python/src/queries/components/grouping.rs +++ b/wrappers/python/src/queries/components/grouping.rs @@ -1,6 +1,6 @@ use pyo3::prelude::*; use serde::{Deserialize, Serialize}; -use solrstice::queries::components::grouping::{GroupFormatting, GroupingComponent}; +use solrstice::{GroupFormatting, GroupingComponent}; #[pyclass(name = "GroupingComponent", module = "solrstice.group", subclass)] #[derive(Clone, Serialize, Deserialize)] diff --git a/wrappers/python/src/queries/components/json_facet.rs b/wrappers/python/src/queries/components/json_facet.rs index c5360e1..d8e8164 100644 --- a/wrappers/python/src/queries/components/json_facet.rs +++ b/wrappers/python/src/queries/components/json_facet.rs @@ -1,7 +1,5 @@ use pyo3::prelude::*; -use solrstice::queries::components::json_facet::{ - JsonFacetComponent, JsonFacetType, JsonQueryFacet, JsonStatFacet, JsonTermsFacet, -}; +use solrstice::{JsonFacetComponent, JsonFacetType, JsonQueryFacet, JsonStatFacet, JsonTermsFacet}; use std::collections::HashMap; #[derive(Clone, Debug, PartialEq)] diff --git a/wrappers/python/src/queries/config.rs b/wrappers/python/src/queries/config.rs index a4f4634..0333239 100644 --- a/wrappers/python/src/queries/config.rs +++ b/wrappers/python/src/queries/config.rs @@ -1,7 +1,7 @@ use crate::models::context::SolrServerContextWrapper; use crate::models::error::PyErrWrapper; use pyo3::prelude::*; -use solrstice::models::context::SolrServerContext; +use solrstice::SolrServerContext; use solrstice::queries::config::{ config_exists as config_exists_rs, delete_config as delete_config_rs, get_configs as get_configs_rs, upload_config as upload_config_rs, diff --git a/wrappers/python/src/queries/def_type.rs b/wrappers/python/src/queries/def_type.rs index 2632bfb..a59beae 100644 --- a/wrappers/python/src/queries/def_type.rs +++ b/wrappers/python/src/queries/def_type.rs @@ -1,8 +1,6 @@ use pyo3::prelude::*; use serde::{Deserialize, Serialize}; -use solrstice::queries::def_type::{ - DefType, DismaxQuery, EdismaxQuery, LuceneQuery, QueryOperator, -}; +use solrstice::{DefType, DismaxQuery, EdismaxQuery, LuceneQuery, QueryOperator}; #[pymodule] pub fn def_type(_py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> { diff --git a/wrappers/python/src/queries/index.rs b/wrappers/python/src/queries/index.rs index b04e69c..3366e2d 100644 --- a/wrappers/python/src/queries/index.rs +++ b/wrappers/python/src/queries/index.rs @@ -5,10 +5,10 @@ use pyo3::prelude::*; use pyo3::types::PyBytes; use pythonize::depythonize_bound; use serde::{Deserialize, Serialize}; -use solrstice::models::commit_type::CommitType; -use solrstice::models::context::SolrServerContext; -use solrstice::models::error::SolrError; -use solrstice::queries::index::{DeleteQuery, UpdateQuery}; +use solrstice::CommitType; +use solrstice::Error; +use solrstice::SolrServerContext; +use solrstice::{DeleteQuery, UpdateQuery}; #[pyclass(name = "CommitType")] #[derive(Clone, Copy, Serialize, Deserialize)] @@ -84,7 +84,7 @@ impl UpdateQueryWrapper { match state.extract::<&PyBytes>(py) { Ok(s) => { *self = serde_json::from_slice(s.as_bytes()) - .map_err(SolrError::from) + .map_err(Error::from) .map_err(PyErrWrapper::from)?; Ok(()) } @@ -96,7 +96,7 @@ impl UpdateQueryWrapper { Ok(PyBytes::new_bound( py, serde_json::to_string(&self) - .map_err(SolrError::from) + .map_err(Error::from) .map_err(PyErrWrapper::from)? .as_bytes(), ) @@ -189,7 +189,7 @@ impl DeleteQueryWrapper { match state.extract::<&PyBytes>(py) { Ok(s) => { *self = serde_json::from_slice(s.as_bytes()) - .map_err(SolrError::from) + .map_err(Error::from) .map_err(PyErrWrapper::from)?; Ok(()) } @@ -201,7 +201,7 @@ impl DeleteQueryWrapper { Ok(PyBytes::new_bound( py, serde_json::to_string(&self) - .map_err(SolrError::from) + .map_err(Error::from) .map_err(PyErrWrapper::from)? .as_bytes(), ) diff --git a/wrappers/python/src/queries/select.rs b/wrappers/python/src/queries/select.rs index ad97b43..e8a1ceb 100644 --- a/wrappers/python/src/queries/select.rs +++ b/wrappers/python/src/queries/select.rs @@ -8,13 +8,13 @@ use crate::queries::def_type::DefTypeWrapper; use pyo3::prelude::*; use pyo3::types::PyBytes; use serde::{Deserialize, Serialize}; -use solrstice::models::context::SolrServerContext; -use solrstice::models::error::SolrError; -use solrstice::queries::components::facet_set::FacetSetComponent; -use solrstice::queries::components::grouping::GroupingComponent; -use solrstice::queries::components::json_facet::JsonFacetComponent; -use solrstice::queries::def_type::DefType; -use solrstice::queries::select::SelectQuery; +use solrstice::DefType; +use solrstice::Error; +use solrstice::FacetSetComponent; +use solrstice::GroupingComponent; +use solrstice::JsonFacetComponent; +use solrstice::SelectQuery; +use solrstice::SolrServerContext; #[pyclass(name = "SelectQuery", module = "solrstice.queries", subclass)] #[derive(Clone, Serialize, Deserialize)] @@ -105,7 +105,7 @@ impl SelectQueryWrapper { match state.extract::<&PyBytes>(py) { Ok(s) => { *self = serde_json::from_slice(s.as_bytes()) - .map_err(SolrError::from) + .map_err(Error::from) .map_err(PyErrWrapper::from)?; Ok(()) } @@ -117,7 +117,7 @@ impl SelectQueryWrapper { Ok(PyBytes::new_bound( py, serde_json::to_string(&self) - .map_err(SolrError::from) + .map_err(Error::from) .map_err(PyErrWrapper::from)? .as_bytes(), ) From 1755c235006e258193f1d29cf328d519f7d515b9 Mon Sep 17 00:00:00 2001 From: Sh1nku <42642351+Sh1nku@users.noreply.github.com> Date: Fri, 26 Jul 2024 11:56:53 +0200 Subject: [PATCH 2/5] Restructure python module --- CHANGELOG.md | 2 + README.md | 71 +- wrappers/python/README.md | 12 +- wrappers/python/mypy.ini | 25 + wrappers/python/pyrightconfig.json | 45 + wrappers/python/solrstice/__init__.pyi | 899 ++++++++++++++++++ wrappers/python/solrstice/alias.pyi | 14 +- wrappers/python/solrstice/auth.pyi | 15 - wrappers/python/solrstice/clients.pyi | 240 ----- wrappers/python/solrstice/collection.pyi | 30 +- wrappers/python/solrstice/config.pyi | 14 +- wrappers/python/solrstice/def_type.pyi | 105 -- wrappers/python/solrstice/facet_set.pyi | 164 ---- wrappers/python/solrstice/group.pyi | 86 -- wrappers/python/solrstice/hosts.pyi | 91 -- wrappers/python/solrstice/json_facet.pyi | 99 -- wrappers/python/solrstice/models.pyi | 201 ++++ wrappers/python/solrstice/queries.pyi | 126 --- wrappers/python/solrstice/response.pyi | 30 - wrappers/python/src/clients.rs | 15 +- wrappers/python/src/hosts.rs | 34 +- wrappers/python/src/lib.rs | 124 ++- wrappers/python/src/models/auth.rs | 11 +- wrappers/python/src/models/context.rs | 10 +- wrappers/python/src/models/facet_set.rs | 31 +- wrappers/python/src/models/group.rs | 14 +- wrappers/python/src/models/json_facet.rs | 21 +- wrappers/python/src/models/response.rs | 15 +- .../src/queries/components/facet_set.rs | 12 +- .../python/src/queries/components/grouping.rs | 4 +- .../src/queries/components/json_facet.rs | 10 +- wrappers/python/src/queries/def_type.rs | 20 +- wrappers/python/src/queries/index.rs | 4 +- wrappers/python/src/queries/select.rs | 2 +- wrappers/python/tests/helpers.py | 11 +- wrappers/python/tests/test_clients.py | 6 +- wrappers/python/tests/test_def_type.py | 4 +- wrappers/python/tests/test_facetset.py | 4 +- wrappers/python/tests/test_group.py | 4 +- wrappers/python/tests/test_hosts.py | 4 +- wrappers/python/tests/test_index.py | 2 +- wrappers/python/tests/test_json_facet.py | 4 +- wrappers/python/tests/test_latency.py | 8 +- wrappers/python/tests/test_logging.py | 6 +- wrappers/python/tests/test_multiprocessing.py | 8 +- wrappers/python/tests/test_pickle.py | 4 +- wrappers/python/tests/test_select.py | 2 +- 47 files changed, 1418 insertions(+), 1245 deletions(-) create mode 100644 wrappers/python/mypy.ini create mode 100644 wrappers/python/pyrightconfig.json delete mode 100644 wrappers/python/solrstice/auth.pyi delete mode 100644 wrappers/python/solrstice/clients.pyi delete mode 100644 wrappers/python/solrstice/def_type.pyi delete mode 100644 wrappers/python/solrstice/facet_set.pyi delete mode 100644 wrappers/python/solrstice/group.pyi delete mode 100644 wrappers/python/solrstice/hosts.pyi delete mode 100644 wrappers/python/solrstice/json_facet.pyi create mode 100644 wrappers/python/solrstice/models.pyi delete mode 100644 wrappers/python/solrstice/queries.pyi delete mode 100644 wrappers/python/solrstice/response.pyi diff --git a/CHANGELOG.md b/CHANGELOG.md index ceb3c39..f13439d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ # v0.5.0 * Add logging of solr requests +* Move most items into the top level module namespace in both Rust and Python +* Rename `SolrError` to `Error` # v0.4.3 diff --git a/README.md b/README.md index cc22053..92db2ae 100644 --- a/README.md +++ b/README.md @@ -5,30 +5,32 @@ Solrstice is a SolrCloud aware client library written in rust. It also provides a wrapper to python. -Use the [Rust documentation](https://docs.rs/solrstice) or the [Python documentation](https://sh1nku.github.io/solrstice/python) for more information. +Use the [Rust documentation](https://docs.rs/solrstice) or +the [Python documentation](https://sh1nku.github.io/solrstice/python) for more information. + ## Features + * Config API * Collection API * Alias API * Select Documents - * Grouping Component Query - * DefTypes (lucene, dismax, edismax) - * Facet Counts (Query, Field, Pivot) - * Json Facet (Query, Stat, Terms, Nested) + * Grouping Component Query + * DefTypes (lucene, dismax, edismax) + * Facet Counts (Query, Field, Pivot) + * Json Facet (Query, Stat, Terms, Nested) * Indexing Documents * Deleting Documents + ## Examples + Upload a config, create a collection, index a document, select it, and delete it. + ### Rust + ```rust use serde::{Deserialize, Serialize}; -use solrstice::AsyncSolrCloudClient; -use solrstice::SolrSingleServerHost; -use solrstice::SolrBasicAuth; -use solrstice::SolrServerContextBuilder; -use solrstice::Error; -use solrstice::{DeleteQuery, UpdateQuery}; -use solrstice::SelectQuery; +use solrstice::{AsyncSolrCloudClient, SolrSingleServerHost, SolrBasicAuth, + SolrServerContextBuilder, Error, DeleteQuery, UpdateQuery, SelectQuery}; use std::path::Path; #[derive(Serialize, Deserialize, Debug)] @@ -38,82 +40,83 @@ struct TestData { #[tokio::test] pub async fn example() -> Result<(), Error> { - + //Create a solr client. You can also use a list of zookeeper hosts instead of a single server. let context = SolrServerContextBuilder::new(SolrSingleServerHost::new("http://localhost:8983")) .with_auth(SolrBasicAuth::new("solr", Some("SolrRocks"))).build(); let client = AsyncSolrCloudClient::new(context); - + // Upload config client .upload_config("example_config", Path::new("/path/to/config")) .await?; - + // Create collection client .create_collection("example_collection", "example_config", 1, 1) .await?; - + // Index document let docs = vec![TestData { - id: "example_document".to_string(), + id: "example_document".to_string(), }]; client .index( - &UpdateQuery::new(), - "example_collection", - docs.as_slice(), + &UpdateQuery::new(), + "example_collection", + docs.as_slice(), ) .await?; - + // Search and retrieve the document let docs = client .select( - &SelectQuery::new().fq(["id:example_document"]), - "example_collection", + &SelectQuery::new().fq(["id:example_document"]), + "example_collection", ) .await? .get_docs_response() .ok_or("No response provided")? .get_docs::()?; - + // Delete the document client .delete( - &DeleteQuery::new().ids(["example_document"]), - "example_collection", + &DeleteQuery::new().ids(["example_document"]), + "example_collection", ) .await?; Ok(()) } ``` + ### Python + ```python import asyncio -from solrstice.clients import AsyncSolrCloudClient -from solrstice.hosts import SolrSingleServerHost, SolrServerContext -from solrstice.auth import SolrBasicAuth -from solrstice.queries import UpdateQuery, SelectQuery, DeleteQuery +from solrstice import AsyncSolrCloudClient, SolrSingleServerHost, SolrServerContext, \ + SolrBasicAuth, UpdateQuery, SelectQuery, DeleteQuery # A SolrServerContext specifies how the library should interact with Solr context = SolrServerContext(SolrSingleServerHost('localhost:8983'), SolrBasicAuth('solr', 'SolrRocks')) client = AsyncSolrCloudClient(context) + async def main(): # Create config and collection await client.upload_config('example_config', 'path/to/config') await client.create_collection('example_collection', 'example_config', shards=1, replication_factor=1) - + # Index a document await client.index(UpdateQuery(), 'example_collection', [{'id': 'example_document', 'title': 'Example document'}]) - + # Search for the document response = await client.select(SelectQuery(fq=['title:Example document']), 'example_collection') docs = response.get_docs_response().get_docs() - + # Delete the document await client.delete(DeleteQuery(ids=['example_document']), 'example_collection') - + asyncio.run(main()) ``` \ No newline at end of file diff --git a/wrappers/python/README.md b/wrappers/python/README.md index ff924fc..f684bb8 100644 --- a/wrappers/python/README.md +++ b/wrappers/python/README.md @@ -31,10 +31,8 @@ pip install solrstice ```python import asyncio -from solrstice.auth import SolrBasicAuth -from solrstice.clients import AsyncSolrCloudClient -from solrstice.hosts import SolrServerContext, SolrSingleServerHost -from solrstice.queries import DeleteQuery, SelectQuery, UpdateQuery +from solrstice import SolrBasicAuth, SolrServerContext, SolrSingleServerHost, AsyncSolrCloudClient, UpdateQuery, + SelectQuery, DeleteQuery # A SolrServerContext specifies how the library should interact with Solr context = SolrServerContext(SolrSingleServerHost('localhost:8983'), SolrBasicAuth('solr', 'SolrRocks')) @@ -63,10 +61,8 @@ asyncio.run(main()) ### Blocking ```python -from solrstice.auth import SolrBasicAuth -from solrstice.clients import BlockingSolrCloudClient -from solrstice.hosts import SolrServerContext, SolrSingleServerHost -from solrstice.queries import DeleteQuery, SelectQuery, UpdateQuery +from solrstice import SolrBasicAuth, BlockingSolrCloudClient, SolrServerContext, SolrSingleServerHost, DeleteQuery, + SelectQuery, UpdateQuery # A SolrServerContext specifies how the library should interact with Solr context = SolrServerContext(SolrSingleServerHost('localhost:8983'), SolrBasicAuth('solr', 'SolrRocks')) diff --git a/wrappers/python/mypy.ini b/wrappers/python/mypy.ini new file mode 100644 index 0000000..79a8fa0 --- /dev/null +++ b/wrappers/python/mypy.ini @@ -0,0 +1,25 @@ +[mypy] +files=solrstice +warn_unused_configs=True + +# Dynamic typing +disallow_any_unimported = True +disallow_any_generics=True +disallow_subclassing_any = True + +# Untyped definitions and calls +disallow_untyped_calls = True +disallow_untyped_defs = True +disallow_incomplete_defs = True +check_untyped_defs = True +disallow_untyped_decorators = True + +# Warnings +warn_redundant_casts = True +## Conflict between mypy and pyright +warn_unused_ignores = False +warn_no_return = True + +# Misc +allow_redefinition = True +strict_equality = True \ No newline at end of file diff --git a/wrappers/python/pyrightconfig.json b/wrappers/python/pyrightconfig.json new file mode 100644 index 0000000..dd6ab21 --- /dev/null +++ b/wrappers/python/pyrightconfig.json @@ -0,0 +1,45 @@ +{ + "include": [ + "solrstice" + ], + "exclude": [ + "**/__pycache__" + ], + "defineConstant": { + "DEBUG": true + }, + "reportMissingModuleSource": false, + "reportPrivateImportUsage": false, + "reportRedeclaration": false, + "disableBytesTypePromotions": true, + "strictListInference": true, + "strictDictionaryInference": true, + "strictSetInference": true, + "reportConstantRedefinition": true, + "reportDeprecated": true, + "reportIncompleteStub": true, + "reportInconsistentConstructor": true, + "reportInvalidStubStatement": true, + "reportMatchNotExhaustive": true, + "reportMissingParameterType": true, + "reportMissingTypeArgument": true, + "reportTypeCommentUsage": true, + "reportUnnecessaryCast": true, + "reportUnnecessaryComparison": true, + "reportUnnecessaryContains": true, + "reportUnnecessaryIsInstance": true, + "reportUnusedClass": true, + "reportUnusedFunction": true, + "reportUnusedVariable": true, + "reportUntypedBaseClass": true, + "reportUntypedClassDecorator": true, + "reportUntypedFunctionDecorator": true, + "reportUntypedNamedTuple": true, + "pythonVersion": "3.8", + "pythonPlatform": "Linux", + "executionEnvironments": [ + { + "root": "." + } + ] +} \ No newline at end of file diff --git a/wrappers/python/solrstice/__init__.pyi b/wrappers/python/solrstice/__init__.pyi index e69de29..5f44006 100644 --- a/wrappers/python/solrstice/__init__.pyi +++ b/wrappers/python/solrstice/__init__.pyi @@ -0,0 +1,899 @@ +import abc +from abc import ABC +from enum import Enum +from os import PathLike +from typing import Optional, List, Dict, Union, TYPE_CHECKING, Any + +if TYPE_CHECKING: + from solrstice.models import SolrResponse + + +#region auth +class SolrAuth(ABC): + """Base class for Solr authentication""" + + +class SolrBasicAuth(SolrAuth): + """Basic authentication for Solr + + :param username: Username for Solr + :param password: Password for Solr + """ + + def __init__(self, username: str, password: Optional[str] = None) -> None: + pass + + +#endregion + +#region def_type +class QueryOperator(Enum): + AND = "AND" + OR = "OR" + + +class DefType(abc.ABC): + pass + + +class LuceneQuery(DefType): + """ + Create a Lucene query builder. + + :param q_op: Query operator. + :param df: Default field + :param sow: Split on whitespace + """ + + def __init__( + self, + q_op: Optional[QueryOperator] = None, + df: Optional[str] = None, + sow: Optional[bool] = None, + ): + pass + + +class DismaxQuery(DefType): + """ + Create a DisMax query builder. + + :param q_alt: Alternate query + :param qf: Query fields + :param mm: Minimum match + :param pf: Phrase fields + :param ps: Phrase slop + :param qs: Query slop + :param tie: Tie breaker + :param bq: Boost query + :param bf: Boost functions + """ + + def __init__( + self, + q_alt: Optional[str] = None, + qf: Optional[str] = None, + mm: Optional[str] = None, + pf: Optional[str] = None, + ps: Optional[str] = None, + qs: Optional[str] = None, + tie: Optional[str] = None, + bq: Optional[List[str]] = None, + bf: Optional[List[str]] = None, + ): + pass + + +class EdismaxQuery(DefType): + """ + Create an Edismax query builder. + + :param q_alt: Alternate query + :param qf: Query fields + :param mm: Minimum match + :param mm_auto_relax: Automatically relax mm + :param pf: Phrase fields + :param pf2: Phrase fields 2 + :param pf3: Phrase fields 3 + :param ps: Phrase slop + :param ps2: Phrase slop 2 + :param ps3: Phrase slop 3 + :param qs: Query slop + :param tie: Tie breaker + :param bq: Boost query + :param bf: Boost functions + :param sow: Split on whitespace + :param boost: Boost + :param lowercase_operators: Lowercase operators + :param stopwords: Stopwords + :param uf: User fields + """ + + def __init__( + self, + q_alt: Optional[str] = None, + qf: Optional[str] = None, + mm: Optional[str] = None, + mm_auto_relax: Optional[bool] = None, + pf: Optional[str] = None, + pf2: Optional[str] = None, + pf3: Optional[str] = None, + ps: Optional[str] = None, + ps2: Optional[str] = None, + ps3: Optional[str] = None, + qs: Optional[str] = None, + tie: Optional[str] = None, + bq: Optional[List[str]] = None, + bf: Optional[List[str]] = None, + sow: Optional[bool] = None, + boost: Optional[List[str]] = None, + lowercase_operators: Optional[bool] = None, + stopwords: Optional[bool] = None, + uf: Optional[str] = None, + ): + pass + + +#endregion + +#region facet_set + +class FacetSetComponent: + """ + Creates a facet set component allowing for counting of facets of different types + + :param queries: A list of queries to facet on + :param fields: A list of fields to facet on + :param pivots: A list of pivots to facet on + """ + + def __init__( + self, + queries: Optional[List[str]] = None, + fields: Optional["FieldFacetComponent"] = None, + pivots: Optional["PivotFacetComponent"] = None, + ): + pass + + +class PivotFacetComponent: + """ + Allows faceting using pivots + + :param pivots: A list of pivots to facet on + :param min_count: The minimum count for a facet to be returned + """ + + def __init__(self, pivots: List[str], min_count: Optional[str]): + pass + + +class FieldFacetComponent: + """ + Allows faceting using fields + + :param fields: A list of fields to facet on + :param exclude_terms: Comma separated list of terms to exclude from the facet. Escaping needs to be done manually + """ + + def __init__( + self, + fields: List["FieldFacetEntry"], + exclude_terms: Optional[str] = None, + ): + pass + + +class FieldFacetSort(Enum): + """ + The sort order for a field facet + """ + + Count = "Count" + Index = "Index" + + +class FieldFacetMethod(Enum): + """ + The method for a field facet + """ + + Enum = "Enum" + Fc = "Fc" + Fcs = "Fcs" + + +class FieldFacetEntry: + """ + + :param field: The field to facet on + :param prefix: Limit the terms to those starting with the given prefix + :param contains: Limit the terms to those containing the given substring + :param contains_ignore_case: Whether to ignore case when filtering by contains + :param sort: The sort order for the facet + :param limit: The maximum number of facet entries to return + :param offset: The offset into the facet entries to return + :param min_count: The minimum count needed for a facet to be returned + :param missing: Whether to include a facet for missing values + :param method: The method to use for the facet. Default is Fc + :param enum_cache_min_df: The minimum document frequency for a term to be included in the facet cache. Only used for Enum method + :param exists: Cap facet counts by 1 + """ + + def __init__( + self, + field: str, + prefix: Optional[str] = None, + contains: Optional[str] = None, + contains_ignore_case: Optional[bool] = None, + sort: Optional["FieldFacetSort"] = None, + limit: Optional[int] = None, + offset: Optional[int] = None, + min_count: Optional[int] = None, + missing: Optional[bool] = None, + method: Optional["FieldFacetMethod"] = None, + enum_cache_min_df: Optional[int] = None, + exists: Optional[bool] = None, + ): + pass + + +#endregion + +#region json_facet + +class JsonFacetComponent: + """ + Json faceting component + + :param facets: A dictionary of facets to apply to the query + """ + + def __init__(self, facets: Optional[Dict[str, "JsonFacetType"]] = None): + pass + + +class JsonFacetType(abc.ABC): + pass + + +class JsonTermsFacet(JsonFacetType): + """ + Do a terms facet on a field + + :param field: The field to facet on + :param offset: The offset into the list of terms + :param limit: The maximum number of terms to return + :param sort: The sort order for the terms + """ + + def __init__( + self, + field: str, + offset: Optional[int] = None, + limit: Optional[int] = None, + sort: Optional[str] = None, + facets: Optional[Dict[str, JsonFacetType]] = None, + ): + pass + + +class JsonQueryFacet(JsonFacetType): + """ + Do a query facet + + :param q: The query to facet on + :param limit: The maximum number of terms to return + :param offset: The offset into the list of terms + :param sort: The sort order for the terms + :param fq: A list of filters to apply to the query + :param facets: A list of sub-facets to apply to the query + """ + + def __init__( + self, + q: str, + limit: Optional[int] = None, + offset: Optional[int] = None, + sort: Optional[str] = None, + fq: Optional[str] = None, + facets: Optional[Dict[str, JsonFacetType]] = None, + ): + pass + + +class JsonStatFacet(JsonFacetType): + """ + Do a stat facet + + :param query: The query to facet on + """ + + def __init__(self, query: str): + pass + + +#endregion + +#region hosts +class SolrHost(ABC): + """Base class for Solr hosts""" + + +class SolrSingleServerHost(SolrHost): + """Solr host for a single Solr instance + + :param host: Hostname of the Solr instance + """ + + def __init__(self, host: str) -> None: + pass + + +class SolrMultipleServerHost(SolrHost): + """Solr host for multiple solr instances + + :param hosts: List of Solr instances + :param timeout: Amount of seconds before declaring a node not responding, and going to the next + """ + + def __init__(self, hosts: List[str], timeout: float) -> None: + pass + + +class ZookeeperEnsembleHost(SolrHost): + """Zookeeper ensemble connection. Cannot be constructed directly, use ZookeeperEnsembleHostConnector instead""" + + +class ZookeeperEnsembleHostConnector: + """The builder for a Zookeeper ensemble host + + :param hosts: List of Zookeeper instances + :param timeout: Timeout for connecting to Zookeeper + """ + + def __init__(self, hosts: List[str], timeout: float) -> None: + pass + + async def connect(self) -> ZookeeperEnsembleHost: + """Connect to the Zookeeper ensemble""" + pass + + def connect_blocking(self) -> ZookeeperEnsembleHost: + """Connect to the Zookeeper ensemble""" + pass + + +class LoggingPolicy(abc.ABC): + """Policy describing how to log solr queries. Valid values are :class:`OffLoggingPolicy`, :class:`FastLoggingPolicy`, and :class:`PrettyLoggingPolicy`""" + + pass + + +class OffLoggingPolicy(LoggingPolicy): + """Do not log requests""" + + def __init__(self) -> None: + pass + + +class FastLoggingPolicy(LoggingPolicy): + """For each request create a logging::DEBUG message with url, headers, and body + + :param max_body_length: How long to allow the body to be before dropping to log it + """ + + def __init__(self, max_body_length: int) -> None: + pass + + +class PrettyLoggingPolicy(LoggingPolicy): + """For each request create a logging::DEBUG message with url, headers, and a pretty body + + :param max_body_length: How long to allow the body to be before dropping to log it + """ + + def __init__(self, max_body_length: int) -> None: + pass + + +class SolrServerContext: + """The context for a connection to a solr instance + + :param host: An instance of SolrHost specifying how to connect to a solr instance. If given as a string it creates a :class:`SolrSingleServerHost` + :param auth: An instance of SolrAuth specifying how to authenticate with the solr instance + :param logging_policy: How to log solr queries, valid values are :class:`OffLoggingPolicy`, :class:`FastLoggingPolicy`, and :class:`PrettyLoggingPolicy` + """ + + def __init__( + self, + host: Union[SolrHost, str], + auth: Optional[SolrAuth] = None, + logging_policy: Optional[LoggingPolicy] = None, + ): + pass + + +#endregion + +#region group +class GroupFormatting(Enum): + Simple = "Simple" + Grouped = "Grouped" + + +class GroupingComponent: + """ + Grouping component, used in conjunction with SelectQuery + + :param fields: Fields to group results by + :param queries: Queries to group by + :param limit: Limit the number of groups returned for each set of grouped documents + :param offset: Offset the number of groups returned for each set of grouped documents + :param sort: Sort the groups + :param format: The group format, either Simple, or Grouped + :param main: Should the group result be the main result + :param n_groups: Should the number of groups be counted + :param truncate: Truncate + :param facet: Facet + """ + + def __init__( + self, + fields: Optional[List[str]] = None, + queries: Optional[List[str]] = None, + limit: Optional[int] = None, + offset: Optional[int] = None, + sort: Optional[List[str]] = None, + format: Optional[GroupFormatting] = None, + main: Optional[bool] = None, + n_groups: Optional[bool] = None, + truncate: Optional[bool] = None, + facet: Optional[bool] = None, + ): + pass + + +#endregion + +#region queries +class SelectQuery: + """Builder for a select query + + :param q: The query string + :param fq: The filter queries + :param fl: The fields to return + :param sort: The sort order + :param rows: The number of rows to return + :param start: Set the start index + :param cursor_mark: Set the cursor mark + :param grouping: Set the grouping component + :param def_type: Set the query type + :param facet_set: Facet counts + :param json_facet: Json facets + """ + + def __init__( + self, + q: Optional[str] = None, + fq: Optional[List[str]] = None, + fl: Optional[List[str]] = None, + sort: Optional[List[str]] = None, + rows: Optional[int] = None, + start: Optional[int] = None, + cursor_mark: Optional[str] = None, + grouping: Optional["GroupingComponent"] = None, + def_type: Optional["DefType"] = None, + facet_set: Optional["FacetSetComponent"] = None, + json_facet: Optional["JsonFacetComponent"] = None, + ) -> None: + pass + + async def execute( + self, context: "SolrServerContext", collection: str + ) -> "SolrResponse": + """Execute the query + + :param context: The context for the connection to the solr instance + :param collection: The collection to query + """ + + def execute_blocking( + self, context: "SolrServerContext", collection: str + ) -> "SolrResponse": + """Execute the query + + :param context: The context for the connection to the solr instance + :param collection: The collection to query + """ + + +class CommitType(Enum): + Hard = ("Hard",) + Soft = "Soft" + + +class UpdateQuery: + """Builder for an update query + + :param handler: The handler for the update query + :param commit_type: The commit type for the update query + """ + + def __init__( + self, + handler: Optional[str] = "update", + commit_type: Optional[CommitType] = CommitType.Hard, + ) -> None: + pass + + async def execute( + self, context: "SolrServerContext", collection: str, data: List[Dict[str, Any]] + ) -> "SolrResponse": + """Execute the query + + :param context: The context for the connection to the solr instance + :param collection: The collection to update + :param data: The data to update + """ + + def execute_blocking( + self, context: "SolrServerContext", collection: str, data: List[Dict[str, Any]] + ) -> "SolrResponse": + """Execute the query + + :param context: The context for the connection to the solr instance + :param collection: The collection to update + :param data: The data to update + """ + + +class DeleteQuery: + """Builder for a delete query + + :param handler: The handler for the delete query + :param commit_type: The commit type for the delete query + """ + + def __init__( + self, + handler: Optional[str] = "update", + commit_type: Optional[CommitType] = CommitType.Hard, + ids: Optional[List[str]] = None, + queries: Optional[List[str]] = None, + ) -> None: + pass + + async def execute( + self, context: "SolrServerContext", collection: str + ) -> "SolrResponse": + """Execute the query + + :param context: The context for the connection to the solr instance + :param collection: The collection to delete from + """ + + def execute_blocking( + self, context: "SolrServerContext", collection: str + ) -> "SolrResponse": + """Execute the query + + :param context: The context for the connection to the solr instance + :param collection: The collection to delete from + """ + + +#endregion + +#region clients + +class AsyncSolrCloudClient: + """ + A client for interacting with a SolrCloud cluster asynchronously. + + :param context: The context of the Solr server. + """ + + def __init__(self, context: "SolrServerContext"): + pass + + async def upload_config(self, config_name: str, config_path: Union[PathLike[str], str]) -> None: + """Uploads a Solr config to a Solr instance + + :param config_name: Name of the config + :param config_path: Path to the config + """ + pass + + async def get_configs(self) -> List[str]: + """Gets a list of Solr configs on a Solr instance""" + + pass + + async def config_exists(self, config_name: str) -> bool: + """Checks if a Solr config exists on a Solr instance + + :param config_name: Name of the config + """ + + pass + + async def delete_config(self, config_name: str) -> None: + """Deletes a Solr config from a Solr instance + + :param config_name: Name of the config + """ + + pass + + async def create_collection( + self, + name: str, + config: str, + shards: Optional[int] = 1, + replication_factor: Optional[int] = 1, + ) -> None: + """ + Create a collection on the Solr server. + + :param name: The name of the collection to create. + :param config: The name of the config to use for the collection. + :param shards: The number of shards to create. + :param replication_factor: The replication factor to use. + """ + + async def get_collections(self) -> List[str]: + """ + Get the list of collections on the Solr server. + + :return: The list of collections on the Solr server. + """ + + async def collection_exists(self, name: str) -> bool: + """ + Check if a collection exists on the Solr server. + + :param name: The name of the collection to check. + :return: True if the collection exists, False otherwise. + """ + + async def delete_collection(self, name: str) -> None: + """ + Delete a config from the Solr server. + :param name: The name of the collection to delete. + """ + + async def create_alias(self, name: str, collections: List[str]) -> None: + """ + Create an alias for a collection on the Solr server + + :param name: The name of the alias to create + :param collections: The collections to alias + """ + + async def get_aliases(self) -> Dict[str, List[str]]: + """ + Get all aliases on the Solr server + + :return: A dictionary of aliases to collections + """ + + async def alias_exists(self, name: str) -> bool: + """ + Check if an alias exists on the Solr server + + :param name: The name of the alias to check + :return: True if the alias exists, False otherwise + """ + + async def delete_alias(self, name: str) -> None: + """ + Delete an alias from the Solr server + + :param name: The name of the alias to delete + """ + + async def select(self, builder: "SelectQuery", collection: str) -> "SolrResponse": + """Execute a select query + + :param builder: The query builder + :param collection: The collection to query + """ + + async def index( + self, builder: "UpdateQuery", collection: str, data: List[Dict[str, Any]] + ) -> "SolrResponse": + """Execute an index query + + :param builder: The query builder + :param collection: The collection to index + :param data: The data to index + """ + + async def delete(self, builder: "DeleteQuery", collection: str) -> "SolrResponse": + """Execute a delete query + + :param builder: The query builder + :param collection: The collection to delete from + """ + + +class BlockingSolrCloudClient: + """ + A client for interacting with a SolrCloud cluster non-asynchronously. + + :param context: The context of the Solr server. + """ + + def __init__(self, context: "SolrServerContext"): + pass + + def upload_config(self, config_name: str, config_path: Union[PathLike[str], str]) -> None: + """Uploads a Solr config to a Solr instance + + :param config_name: Name of the config + :param config_path: Path to the config + """ + pass + + def get_configs(self) -> List[str]: + """Gets a list of Solr configs on a Solr instance""" + + pass + + def config_exists(self, config_name: str) -> bool: + """Checks if a Solr config exists on a Solr instance + + :param config_name: Name of the config + """ + + pass + + def delete_config(self, config_name: str) -> None: + """Deletes a Solr config from a Solr instance + + :param config_name: Name of the config + """ + + pass + + def create_collection( + self, + name: str, + config: str, + shards: Optional[int] = 1, + replication_factor: Optional[int] = 1, + ) -> None: + """ + Create a collection on the Solr server. + + :param name: The name of the collection to create. + :param config: The name of the config to use for the collection. + :param shards: The number of shards to create. + :param replication_factor: The replication factor to use. + """ + + def get_collections(self) -> List[str]: + """ + Get the list of collections on the Solr server. + + :return: The list of collections on the Solr server. + """ + + def collection_exists(self, name: str) -> bool: + """ + Check if a collection exists on the Solr server. + + :param name: The name of the collection to check. + :return: True if the collection exists, False otherwise. + """ + + def delete_collection(self, name: str) -> None: + """ + Delete a config from the Solr server. + + :param context: The Solr server context. + :param name: The name of the collection to delete. + """ + + def create_alias(self, name: str, collections: List[str]) -> None: + """ + Create an alias for a collection on the Solr server + + :param name: The name of the alias to create + :param collections: The collections to alias + """ + + def get_aliases(self) -> Dict[str, List[str]]: + """ + Get all aliases on the Solr server + + :return: A dictionary of aliases to collections + """ + + def alias_exists(self, name: str) -> bool: + """ + Check if an alias exists on the Solr server + + :param name: The name of the alias to check + :return: True if the alias exists, False otherwise + """ + + def delete_alias(self, name: str) -> None: + """ + Delete an alias from the Solr server + + :param name: The name of the alias to delete + """ + + def select(self, builder: "SelectQuery", collection: str) -> "SolrResponse": + """Execute a select query + + :param builder: The query builder + :param collection: The collection to query + """ + + def index( + self, builder: "UpdateQuery", collection: str, data: List[Dict[str, Any]] + ) -> "SolrResponse": + """Execute an index query + + :param builder: The query builder + :param collection: The collection to index + :param data: The data to index + """ + + def delete(self, builder: "DeleteQuery", collection: str) -> "SolrResponse": + """Execute a delete query + + :param builder: The query builder + :param collection: The collection to delete from + """ + + +#endregion + +__all__ = [ + "SolrAuth", + "SolrBasicAuth", + "QueryOperator", + "DefType", + "LuceneQuery", + "DismaxQuery", + "EdismaxQuery", + + "FacetSetComponent", + "PivotFacetComponent", + "FieldFacetComponent", + "FieldFacetSort", + "FieldFacetMethod", + "FieldFacetEntry", + + "JsonFacetComponent", + "JsonFacetType", + "JsonTermsFacet", + "JsonQueryFacet", + "JsonStatFacet", + + "SolrHost", + "SolrSingleServerHost", + "SolrMultipleServerHost", + "ZookeeperEnsembleHost", + "ZookeeperEnsembleHostConnector", + "LoggingPolicy", + "OffLoggingPolicy", + "FastLoggingPolicy", + "PrettyLoggingPolicy", + "SolrServerContext", + + "GroupFormatting", + "GroupingComponent", + + "SelectQuery", + "CommitType", + "UpdateQuery", + "DeleteQuery", + + "AsyncSolrCloudClient", + "BlockingSolrCloudClient", +] diff --git a/wrappers/python/solrstice/alias.pyi b/wrappers/python/solrstice/alias.pyi index a445ae2..dceca0d 100644 --- a/wrappers/python/solrstice/alias.pyi +++ b/wrappers/python/solrstice/alias.pyi @@ -1,9 +1,10 @@ from typing import Dict, List -from solrstice.hosts import SolrServerContext +from solrstice import SolrServerContext + async def create_alias( - context: SolrServerContext, name: str, collections: List[str] + context: SolrServerContext, name: str, collections: List[str] ) -> None: """ Create an alias for a collection on the Solr server @@ -13,8 +14,9 @@ async def create_alias( :param collections: The collections to alias """ + def create_alias_blocking( - context: SolrServerContext, name: str, collections: List[str] + context: SolrServerContext, name: str, collections: List[str] ) -> None: """ Create an alias for a collection on the Solr server @@ -24,6 +26,7 @@ def create_alias_blocking( :param collections: The collections to alias """ + async def get_aliases(context: SolrServerContext) -> Dict[str, List[str]]: """ Get all aliases on the Solr server @@ -32,6 +35,7 @@ async def get_aliases(context: SolrServerContext) -> Dict[str, List[str]]: :return: A dictionary of aliases to collections """ + def get_aliases_blocking(context: SolrServerContext) -> Dict[str, List[str]]: """ Get all aliases on the Solr server @@ -40,6 +44,7 @@ def get_aliases_blocking(context: SolrServerContext) -> Dict[str, List[str]]: :return: A dictionary of aliases to collections """ + async def alias_exists(context: SolrServerContext, name: str) -> bool: """ Check if an alias exists on the Solr server @@ -49,6 +54,7 @@ async def alias_exists(context: SolrServerContext, name: str) -> bool: :return: True if the alias exists, False otherwise """ + def alias_exists_blocking(context: SolrServerContext, name: str) -> bool: """ Check if an alias exists on the Solr server @@ -58,6 +64,7 @@ def alias_exists_blocking(context: SolrServerContext, name: str) -> bool: :return: True if the alias exists, False otherwise """ + async def delete_alias(context: SolrServerContext, name: str) -> None: """ Delete an alias from the Solr server @@ -66,6 +73,7 @@ async def delete_alias(context: SolrServerContext, name: str) -> None: :param name: The name of the alias to delete """ + def delete_alias_blocking(context: SolrServerContext, name: str) -> None: """ Delete an alias from the Solr server diff --git a/wrappers/python/solrstice/auth.pyi b/wrappers/python/solrstice/auth.pyi deleted file mode 100644 index b932530..0000000 --- a/wrappers/python/solrstice/auth.pyi +++ /dev/null @@ -1,15 +0,0 @@ -from abc import ABC -from typing import Optional - -class SolrAuth(ABC): - """Base class for Solr authentication""" - -class SolrBasicAuth(SolrAuth): - """Basic authentication for Solr - - :param username: Username for Solr - :param password: Password for Solr - """ - - def __init__(self, username: str, password: Optional[str] = None) -> None: - pass diff --git a/wrappers/python/solrstice/clients.pyi b/wrappers/python/solrstice/clients.pyi deleted file mode 100644 index aeedc55..0000000 --- a/wrappers/python/solrstice/clients.pyi +++ /dev/null @@ -1,240 +0,0 @@ -from os import PathLike -from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union - -if TYPE_CHECKING: - from solrstice.hosts import SolrServerContext - from solrstice.queries import DeleteQuery, SelectQuery, UpdateQuery - from solrstice.response import SolrResponse -Somepath = Union[PathLike, str] - -class AsyncSolrCloudClient: - """ - A client for interacting with a SolrCloud cluster asynchronously. - - :param context: The context of the Solr server. - """ - - def __init__(self, context: "SolrServerContext"): - pass - async def upload_config(self, config_name: str, config_path: Somepath) -> None: - """Uploads a Solr config to a Solr instance - - :param config_name: Name of the config - :param config_path: Path to the config - """ - pass - async def get_configs(self) -> List[str]: - """Gets a list of Solr configs on a Solr instance""" - pass - - async def config_exists(self, config_name: str) -> bool: - """Checks if a Solr config exists on a Solr instance - - :param config_name: Name of the config - """ - pass - - async def delete_config(self, config_name: str) -> None: - """Deletes a Solr config from a Solr instance - - :param config_name: Name of the config - """ - pass - - async def create_collection( - self, - name: str, - config: str, - shards: Optional[int] = 1, - replication_factor: Optional[int] = 1, - ) -> None: - """ - Create a collection on the Solr server. - - :param name: The name of the collection to create. - :param config: The name of the config to use for the collection. - :param shards: The number of shards to create. - :param replication_factor: The replication factor to use. - """ - async def get_collections(self) -> List[str]: - """ - Get the list of collections on the Solr server. - - :return: The list of collections on the Solr server. - """ - async def collection_exists(self, name: str) -> bool: - """ - Check if a collection exists on the Solr server. - - :param name: The name of the collection to check. - :return: True if the collection exists, False otherwise. - """ - async def delete_collection(self, name: str) -> None: - """ - Delete a config from the Solr server. - :param name: The name of the collection to delete. - """ - async def create_alias(self, name: str, collections: List[str]) -> None: - """ - Create an alias for a collection on the Solr server - - :param name: The name of the alias to create - :param collections: The collections to alias - """ - async def get_aliases(self) -> Dict[str, List[str]]: - """ - Get all aliases on the Solr server - - :return: A dictionary of aliases to collections - """ - async def alias_exists(self, name: str) -> bool: - """ - Check if an alias exists on the Solr server - - :param name: The name of the alias to check - :return: True if the alias exists, False otherwise - """ - async def delete_alias(self, name: str) -> None: - """ - Delete an alias from the Solr server - - :param name: The name of the alias to delete - """ - async def select(self, builder: "SelectQuery", collection: str) -> "SolrResponse": - """Execute a select query - - :param builder: The query builder - :param collection: The collection to query - """ - async def index( - self, builder: "UpdateQuery", collection: str, data: List[Dict[str, Any]] - ) -> "SolrResponse": - """Execute an index query - - :param builder: The query builder - :param collection: The collection to index - :param data: The data to index - """ - async def delete(self, builder: "DeleteQuery", collection: str) -> "SolrResponse": - """Execute a delete query - - :param builder: The query builder - :param collection: The collection to delete from - """ - -class BlockingSolrCloudClient: - """ - A client for interacting with a SolrCloud cluster non-asynchronously. - - :param context: The context of the Solr server. - """ - - def __init__(self, context: "SolrServerContext"): - pass - def upload_config(self, config_name: str, config_path: Somepath) -> None: - """Uploads a Solr config to a Solr instance - - :param config_name: Name of the config - :param config_path: Path to the config - """ - pass - def get_configs(self) -> List[str]: - """Gets a list of Solr configs on a Solr instance""" - pass - - def config_exists(self, config_name: str) -> bool: - """Checks if a Solr config exists on a Solr instance - - :param config_name: Name of the config - """ - pass - - def delete_config(self, config_name: str) -> None: - """Deletes a Solr config from a Solr instance - - :param config_name: Name of the config - """ - pass - - def create_collection( - self, - name: str, - config: str, - shards: Optional[int] = 1, - replication_factor: Optional[int] = 1, - ) -> None: - """ - Create a collection on the Solr server. - - :param name: The name of the collection to create. - :param config: The name of the config to use for the collection. - :param shards: The number of shards to create. - :param replication_factor: The replication factor to use. - """ - def get_collections(self) -> List[str]: - """ - Get the list of collections on the Solr server. - - :return: The list of collections on the Solr server. - """ - def collection_exists(self, name: str) -> bool: - """ - Check if a collection exists on the Solr server. - - :param name: The name of the collection to check. - :return: True if the collection exists, False otherwise. - """ - def delete_collection(self, name: str) -> None: - """ - Delete a config from the Solr server. - - :param context: The Solr server context. - :param name: The name of the collection to delete. - """ - def create_alias(self, name: str, collections: List[str]) -> None: - """ - Create an alias for a collection on the Solr server - - :param name: The name of the alias to create - :param collections: The collections to alias - """ - def get_aliases(self) -> Dict[str, List[str]]: - """ - Get all aliases on the Solr server - - :return: A dictionary of aliases to collections - """ - def alias_exists(self, name: str) -> bool: - """ - Check if an alias exists on the Solr server - - :param name: The name of the alias to check - :return: True if the alias exists, False otherwise - """ - def delete_alias(self, name: str) -> None: - """ - Delete an alias from the Solr server - - :param name: The name of the alias to delete - """ - def select(self, builder: "SelectQuery", collection: str) -> "SolrResponse": - """Execute a select query - - :param builder: The query builder - :param collection: The collection to query - """ - def index( - self, builder: "UpdateQuery", collection: str, data: List[Dict[str, Any]] - ) -> "SolrResponse": - """Execute an index query - - :param builder: The query builder - :param collection: The collection to index - :param data: The data to index - """ - def delete(self, builder: "DeleteQuery", collection: str) -> "SolrResponse": - """Execute a delete query - - :param builder: The query builder - :param collection: The collection to delete from - """ diff --git a/wrappers/python/solrstice/collection.pyi b/wrappers/python/solrstice/collection.pyi index a715ec5..8243063 100644 --- a/wrappers/python/solrstice/collection.pyi +++ b/wrappers/python/solrstice/collection.pyi @@ -1,13 +1,14 @@ from typing import List, Optional -from solrstice.hosts import SolrServerContext +from solrstice import SolrServerContext + async def create_collection( - context: SolrServerContext, - name: str, - config: str, - shards: Optional[int] = 1, - replication_factor: Optional[int] = 1, + context: SolrServerContext, + name: str, + config: str, + shards: Optional[int] = 1, + replication_factor: Optional[int] = 1, ) -> None: """ Create a collection on the Solr server. @@ -19,12 +20,13 @@ async def create_collection( :param replication_factor: The replication factor to use. """ + def create_collection_blocking( - context: SolrServerContext, - name: str, - config: str, - shards: Optional[int] = 1, - replication_factor: Optional[int] = 1, + context: SolrServerContext, + name: str, + config: str, + shards: Optional[int] = 1, + replication_factor: Optional[int] = 1, ) -> None: """ Create a collection on the Solr server. @@ -36,6 +38,7 @@ def create_collection_blocking( :param replication_factor: The replication factor to use. """ + async def get_collections(context: SolrServerContext) -> List[str]: """ Get the list of collections on the Solr server. @@ -44,6 +47,7 @@ async def get_collections(context: SolrServerContext) -> List[str]: :return: The list of collections on the Solr server. """ + def get_collections_blocking(context: SolrServerContext) -> List[str]: """ Get the list of collections on the Solr server. @@ -52,6 +56,7 @@ def get_collections_blocking(context: SolrServerContext) -> List[str]: :return: The list of collections on the Solr server. """ + async def collection_exists(context: SolrServerContext, name: str) -> bool: """ Check if a collection exists on the Solr server. @@ -61,6 +66,7 @@ async def collection_exists(context: SolrServerContext, name: str) -> bool: :return: True if the collection exists, False otherwise. """ + def collection_exists_blocking(context: SolrServerContext, name: str) -> bool: """ Check if a collection exists on the Solr server. @@ -70,6 +76,7 @@ def collection_exists_blocking(context: SolrServerContext, name: str) -> bool: :return: True if the collection exists, False otherwise. """ + async def delete_collection(context: SolrServerContext, name: str) -> None: """ Delete a config from the Solr server. @@ -78,6 +85,7 @@ async def delete_collection(context: SolrServerContext, name: str) -> None: :param name: The name of the collection to delete. """ + def delete_collection_blocking(context: SolrServerContext, name: str) -> None: """ Delete a config from the Solr server. diff --git a/wrappers/python/solrstice/config.pyi b/wrappers/python/solrstice/config.pyi index ae9f2f7..e8dc88e 100644 --- a/wrappers/python/solrstice/config.pyi +++ b/wrappers/python/solrstice/config.pyi @@ -1,15 +1,16 @@ from os import PathLike from typing import TYPE_CHECKING, List, Union -from solrstice.hosts import SolrServerContext +from solrstice import SolrServerContext if TYPE_CHECKING: Somepath = Union[PathLike[str], str] else: Somepath = Union[PathLike, str] + async def upload_config( - context: SolrServerContext, config_name: str, config_path: Somepath + context: SolrServerContext, config_name: str, config_path: Somepath ) -> None: """Uploads a Solr config to a Solr instance @@ -19,8 +20,9 @@ async def upload_config( """ pass + def upload_config_blocking( - context: SolrServerContext, config_name: str, config_path: Somepath + context: SolrServerContext, config_name: str, config_path: Somepath ) -> None: """Uploads a Solr config to a Solr instance @@ -30,6 +32,7 @@ def upload_config_blocking( """ pass + async def delete_config(context: SolrServerContext, config_name: str) -> None: """Deletes a Solr config from a Solr instance @@ -38,6 +41,7 @@ async def delete_config(context: SolrServerContext, config_name: str) -> None: """ pass + def delete_config_blocking(context: SolrServerContext, config_name: str) -> None: """Deletes a Solr config from a Solr instance @@ -46,6 +50,7 @@ def delete_config_blocking(context: SolrServerContext, config_name: str) -> None """ pass + async def config_exists(context: SolrServerContext, config_name: str) -> bool: """Checks if a Solr config exists on a Solr instance @@ -54,6 +59,7 @@ async def config_exists(context: SolrServerContext, config_name: str) -> bool: """ pass + def config_exists_blocking(context: SolrServerContext, config_name: str) -> bool: """Checks if a Solr config exists on a Solr instance @@ -62,6 +68,7 @@ def config_exists_blocking(context: SolrServerContext, config_name: str) -> bool """ pass + async def get_configs(context: SolrServerContext) -> List[str]: """Gets a list of Solr configs on a Solr instance @@ -69,6 +76,7 @@ async def get_configs(context: SolrServerContext) -> List[str]: """ pass + def get_configs_blocking(context: SolrServerContext) -> List[str]: """Gets a list of Solr configs on a Solr instance diff --git a/wrappers/python/solrstice/def_type.pyi b/wrappers/python/solrstice/def_type.pyi deleted file mode 100644 index 82d8c20..0000000 --- a/wrappers/python/solrstice/def_type.pyi +++ /dev/null @@ -1,105 +0,0 @@ -import abc -from enum import Enum -from typing import List, Optional - -class QueryOperator(Enum): - AND = "AND" - OR = "OR" - -class DefType(abc.ABC): - pass - -class LuceneQuery(DefType): - """ - Create a Lucene query builder. - - :param q_op: Query operator. - :param df: Default field - :param sow: Split on whitespace - """ - - def __init__( - self, - q_op: Optional[QueryOperator] = None, - df: Optional[str] = None, - sow: Optional[bool] = None, - ): - pass - -class DismaxQuery(DefType): - """ - Create a DisMax query builder. - - :param q_alt: Alternate query - :param qf: Query fields - :param mm: Minimum match - :param pf: Phrase fields - :param ps: Phrase slop - :param qs: Query slop - :param tie: Tie breaker - :param bq: Boost query - :param bf: Boost functions - """ - - def __init__( - self, - q_alt: Optional[str] = None, - qf: Optional[str] = None, - mm: Optional[str] = None, - pf: Optional[str] = None, - ps: Optional[str] = None, - qs: Optional[str] = None, - tie: Optional[str] = None, - bq: Optional[List[str]] = None, - bf: Optional[List[str]] = None, - ): - pass - -class EdismaxQuery(DefType): - """ - Create an Edismax query builder. - - :param q_alt: Alternate query - :param qf: Query fields - :param mm: Minimum match - :param mm_auto_relax: Automatically relax mm - :param pf: Phrase fields - :param pf2: Phrase fields 2 - :param pf3: Phrase fields 3 - :param ps: Phrase slop - :param ps2: Phrase slop 2 - :param ps3: Phrase slop 3 - :param qs: Query slop - :param tie: Tie breaker - :param bq: Boost query - :param bf: Boost functions - :param sow: Split on whitespace - :param boost: Boost - :param lowercase_operators: Lowercase operators - :param stopwords: Stopwords - :param uf: User fields - """ - - def __init__( - self, - q_alt: Optional[str] = None, - qf: Optional[str] = None, - mm: Optional[str] = None, - mm_auto_relax: Optional[bool] = None, - pf: Optional[str] = None, - pf2: Optional[str] = None, - pf3: Optional[str] = None, - ps: Optional[str] = None, - ps2: Optional[str] = None, - ps3: Optional[str] = None, - qs: Optional[str] = None, - tie: Optional[str] = None, - bq: Optional[List[str]] = None, - bf: Optional[List[str]] = None, - sow: Optional[bool] = None, - boost: Optional[List[str]] = None, - lowercase_operators: Optional[bool] = None, - stopwords: Optional[bool] = None, - uf: Optional[str] = None, - ): - pass diff --git a/wrappers/python/solrstice/facet_set.pyi b/wrappers/python/solrstice/facet_set.pyi deleted file mode 100644 index 47470bd..0000000 --- a/wrappers/python/solrstice/facet_set.pyi +++ /dev/null @@ -1,164 +0,0 @@ -from enum import Enum -from typing import Any, Dict, List, Optional - -class FacetSetComponent: - """ - Creates a facet set component allowing for counting of facets of different types - - :param queries: A list of queries to facet on - :param fields: A list of fields to facet on - :param pivots: A list of pivots to facet on - """ - - def __init__( - self, - queries: Optional[List[str]] = None, - fields: Optional["FieldFacetComponent"] = None, - pivots: Optional["PivotFacetComponent"] = None, - ): - pass - -class PivotFacetComponent: - """ - Allows faceting using pivots - - :param pivots: A list of pivots to facet on - :param min_count: The minimum count for a facet to be returned - """ - - def __init__(self, pivots: List[str], min_count: Optional[str]): - pass - -class FieldFacetComponent: - """ - Allows faceting using fields - - :param fields: A list of fields to facet on - :param exclude_terms: Comma separated list of terms to exclude from the facet. Escaping needs to be done manually - """ - - def __init__( - self, - fields: List["FieldFacetEntry"], - exclude_terms: Optional[str] = None, - ): - pass - -class FieldFacetSort(Enum): - """ - The sort order for a field facet - """ - - Count = "Count" - Index = "Index" - -class FieldFacetMethod(Enum): - """ - The method for a field facet - """ - - Enum = "Enum" - Fc = "Fc" - Fcs = "Fcs" - -class FieldFacetEntry: - """ - - :param field: The field to facet on - :param prefix: Limit the terms to those starting with the given prefix - :param contains: Limit the terms to those containing the given substring - :param contains_ignore_case: Whether to ignore case when filtering by contains - :param sort: The sort order for the facet - :param limit: The maximum number of facet entries to return - :param offset: The offset into the facet entries to return - :param min_count: The minimum count needed for a facet to be returned - :param missing: Whether to include a facet for missing values - :param method: The method to use for the facet. Default is Fc - :param enum_cache_min_df: The minimum document frequency for a term to be included in the facet cache. Only used for Enum method - :param exists: Cap facet counts by 1 - """ - - def __init__( - self, - field: str, - prefix: Optional[str] = None, - contains: Optional[str] = None, - contains_ignore_case: Optional[bool] = None, - sort: Optional["FieldFacetSort"] = None, - limit: Optional[int] = None, - offset: Optional[int] = None, - min_count: Optional[int] = None, - missing: Optional[bool] = None, - method: Optional["FieldFacetMethod"] = None, - enum_cache_min_df: Optional[int] = None, - exists: Optional[bool] = None, - ): - pass - -class SolrFacetSetResult: - """ - Gets the facet counts from a query - """ - - def get_queries(self) -> Dict[str, int]: - """ - Gets the query facets - - :return: The query facets - """ - pass - def get_pivots(self) -> Dict[str, List["SolrPivotFacetResult"]]: - """ - Gets the pivot facets - - :return: The pivot facets - """ - pass - def get_fields(self) -> Dict[str, List["SolrFieldFacetResult"]]: - """ - Gets the field facets - - :return: The field facets - """ - -class SolrPivotFacetResult: - """ - Gets the pivot facet counts from a query - """ - - def get_value(self) -> Any: - """ - Gets the value of the pivot - - :return: The value of the pivot - """ - pass - def get_pivots(self) -> List["SolrPivotFacetResult"]: - """ - Gets additional pivots - :return: The additional pivots - """ - def get_queries(self) -> Dict[str, int]: - """ - Gets the query facets - :return: The query facets - """ - def get_count(self) -> int: - """ - Gets the count of the pivot - :return: The count of the pivot - """ - -class SolrFieldFacetResult: - def get_key(self) -> Any: - """ - Gets the key of the facet - - :return: The key of the facet - """ - pass - def get_count(self) -> int: - """ - Gets the count of the facet - :return: The count of the facet - """ diff --git a/wrappers/python/solrstice/group.pyi b/wrappers/python/solrstice/group.pyi deleted file mode 100644 index ddd8833..0000000 --- a/wrappers/python/solrstice/group.pyi +++ /dev/null @@ -1,86 +0,0 @@ -from enum import Enum -from typing import Any, List, Optional - -from solrstice.response import SolrDocsResponse - -class GroupFormatting(Enum): - Simple = "Simple" - Grouped = "Grouped" - -class GroupingComponent: - """ - Grouping component, used in conjunction with SelectQuery - - :param fields: Fields to group results by - :param queries: Queries to group by - :param limit: Limit the number of groups returned for each set of grouped documents - :param offset: Offset the number of groups returned for each set of grouped documents - :param sort: Sort the groups - :param format: The group format, either Simple, or Grouped - :param main: Should the group result be the main result - :param n_groups: Should the number of groups be counted - :param truncate: Truncate - :param facet: Facet - """ - - def __init__( - self, - fields: Optional[List[str]] = None, - queries: Optional[List[str]] = None, - limit: Optional[int] = None, - offset: Optional[int] = None, - sort: Optional[List[str]] = None, - format: Optional[GroupFormatting] = None, - main: Optional[bool] = None, - n_groups: Optional[bool] = None, - truncate: Optional[bool] = None, - facet: Optional[bool] = None, - ): - pass - -class SolrGroupFieldResult: - """ - Represents a group field result - """ - - def get_group_value(self) -> Any: - """ - Gets the group value - :return: Group value - """ - def get_doc_list(self) -> SolrDocsResponse: - """ - Gets the document response from solr - :return: Document response - """ - -class SolrGroupResult: - """ - Represents a group result - """ - - def get_field_result(self) -> Optional[List[SolrGroupFieldResult]]: - """ - Gets the field results form a group query - :return: List of group field results - """ - def get_query_result(self) -> Optional[SolrDocsResponse]: - """ - Gets the query result from a group query - :return: Query result - """ - def get_simple_result(self) -> Optional[SolrDocsResponse]: - """ - Gets the result from a group query where `GroupFormatting.Simple` was used - :return: Simple result - """ - def get_matches(self) -> int: - """ - Gets the number of matches for a group query - :return: Number of matches - """ - def get_n_groups(self) -> int: - """ - Gets the number of groups for a group query - :return: Number of groups - """ diff --git a/wrappers/python/solrstice/hosts.pyi b/wrappers/python/solrstice/hosts.pyi deleted file mode 100644 index 0374add..0000000 --- a/wrappers/python/solrstice/hosts.pyi +++ /dev/null @@ -1,91 +0,0 @@ -import abc -from abc import ABC -from typing import List, Optional, Union - -from solrstice.auth import SolrAuth - -class SolrHost(ABC): - """Base class for Solr hosts""" - -class SolrSingleServerHost(SolrHost): - """Solr host for a single Solr instance - - :param host: Hostname of the Solr instance - """ - - def __init__(self, host: str) -> None: - pass - -class SolrMultipleServerHost(SolrHost): - """Solr host for multiple solr instances - - :param hosts: List of Solr instances - :param timeout: Amount of seconds before declaring a node not responding, and going to the next - """ - - def __init__(self, hosts: List[str], timeout: float) -> None: - pass - -class ZookeeperEnsembleHost(SolrHost): - """Zookeeper ensemble connection. Cannot be constructed directly, use ZookeeperEnsembleHostConnector instead""" - -class ZookeeperEnsembleHostConnector: - """The builder for a Zookeeper ensemble host - - :param hosts: List of Zookeeper instances - :param timeout: Timeout for connecting to Zookeeper - """ - - def __init__(self, hosts: List[str], timeout: float) -> None: - pass - async def connect(self) -> ZookeeperEnsembleHost: - """Connect to the Zookeeper ensemble""" - pass - def connect_blocking(self) -> ZookeeperEnsembleHost: - """Connect to the Zookeeper ensemble""" - pass - -class LoggingPolicy(abc.ABC): - """Policy describing how to log solr queries. Valid values are :class:`OffLoggingPolicy`, :class:`FastLoggingPolicy`, and :class:`PrettyLoggingPolicy`""" - - pass - -class OffLoggingPolicy(LoggingPolicy): - """Do not log requests""" - - def __init__(self): - pass - -class FastLoggingPolicy(LoggingPolicy): - """For each request create a logging::DEBUG message with url, headers, and body - - :param max_body_length: How long to allow the body to be before dropping to log it - """ - - def __init__(self, max_body_length: int) -> None: - pass - -class PrettyLoggingPolicy(LoggingPolicy): - """For each request create a logging::DEBUG message with url, headers, and a pretty body - - :param max_body_length: How long to allow the body to be before dropping to log it - """ - - def __init__(self, max_body_length: int) -> None: - pass - -class SolrServerContext: - """The context for a connection to a solr instance - - :param host: An instance of SolrHost specifying how to connect to a solr instance. If given as a string it creates a :class:`SolrSingleServerHost` - :param auth: An instance of SolrAuth specifying how to authenticate with the solr instance - :param logging_policy: How to log solr queries, valid values are :class:`OffLoggingPolicy`, :class:`FastLoggingPolicy`, and :class:`PrettyLoggingPolicy` - """ - - def __init__( - self, - host: Union[SolrHost, str], - auth: Optional[SolrAuth] = None, - logging_policy: Optional[LoggingPolicy] = None, - ): - pass diff --git a/wrappers/python/solrstice/json_facet.pyi b/wrappers/python/solrstice/json_facet.pyi deleted file mode 100644 index a86e7d8..0000000 --- a/wrappers/python/solrstice/json_facet.pyi +++ /dev/null @@ -1,99 +0,0 @@ -import abc -from typing import Any, Dict, List, Optional, Union - -class JsonFacetComponent: - """ - Json faceting component - - :param facets: A dictionary of facets to apply to the query - """ - - def __init__(self, facets: Optional[Dict[str, "JsonFacetType"]] = None): - pass - -class JsonFacetType(abc.ABC): - pass - -class JsonTermsFacet(JsonFacetType): - """ - Do a terms facet on a field - - :param field: The field to facet on - :param offset: The offset into the list of terms - :param limit: The maximum number of terms to return - :param sort: The sort order for the terms - """ - - def __init__( - self, - field: str, - offset: Optional[int] = None, - limit: Optional[int] = None, - sort: Optional[str] = None, - facets: Optional[Dict[str, JsonFacetType]] = None, - ): - pass - -class JsonQueryFacet(JsonFacetType): - """ - Do a query facet - - :param q: The query to facet on - :param limit: The maximum number of terms to return - :param offset: The offset into the list of terms - :param sort: The sort order for the terms - :param fq: A list of filters to apply to the query - :param facets: A list of sub-facets to apply to the query - """ - - def __init__( - self, - q: str, - limit: Optional[int] = None, - offset: Optional[int] = None, - sort: Optional[str] = None, - fq: Optional[str] = None, - facets: Optional[Dict[str, JsonFacetType]] = None, - ): - pass - -class JsonStatFacet(JsonFacetType): - """ - Do a stat facet - - :param query: The query to facet on - """ - - def __init__(self, query: str): - pass - -class SolrJsonFacetResponse: - """ - A response from a json facet query - """ - - def get_buckets(self) -> List["SolrJsonFacetResponse"]: - """ - Get the buckets for this facet - :return: A list of buckets - """ - def get_flat_facets(self) -> Dict[str, Any]: - """ - Get stat counts for this facet - :return: A dictionary of stat counts - """ - def get_nested_facets(self) -> Dict[str, "SolrJsonFacetResponse"]: - """ - Get the nested facets for this facet - :return: A dictionary of nested facets - """ - def get_count(self) -> Optional[int]: - """ - Get the count for this facet - :return: The count for this facet - """ - def get_val(self) -> Optional[Any]: - """ - If a bucket facet, this value will be set - :return: The value for this facet - """ diff --git a/wrappers/python/solrstice/models.pyi b/wrappers/python/solrstice/models.pyi new file mode 100644 index 0000000..17f4375 --- /dev/null +++ b/wrappers/python/solrstice/models.pyi @@ -0,0 +1,201 @@ +from typing import Any, Dict, List, Optional + + +class SolrFacetSetResult: + """ + Gets the facet counts from a query + """ + + def get_queries(self) -> Dict[str, int]: + """ + Gets the query facets + + :return: The query facets + """ + pass + + def get_pivots(self) -> Dict[str, List["SolrPivotFacetResult"]]: + """ + Gets the pivot facets + + :return: The pivot facets + """ + pass + + def get_fields(self) -> Dict[str, List["SolrFieldFacetResult"]]: + """ + Gets the field facets + + :return: The field facets + """ + + +class SolrPivotFacetResult: + """ + Gets the pivot facet counts from a query + """ + + def get_value(self) -> Any: + """ + Gets the value of the pivot + + :return: The value of the pivot + """ + pass + + def get_pivots(self) -> List["SolrPivotFacetResult"]: + """ + Gets additional pivots + :return: The additional pivots + """ + + def get_queries(self) -> Dict[str, int]: + """ + Gets the query facets + :return: The query facets + """ + + def get_count(self) -> int: + """ + Gets the count of the pivot + :return: The count of the pivot + """ + + +class SolrFieldFacetResult: + def get_key(self) -> Any: + """ + Gets the key of the facet + + :return: The key of the facet + """ + pass + + def get_count(self) -> int: + """ + Gets the count of the facet + :return: The count of the facet + """ + + +class SolrGroupFieldResult: + """ + Represents a group field result + """ + + def get_group_value(self) -> Any: + """ + Gets the group value + :return: Group value + """ + + def get_doc_list(self) -> SolrDocsResponse: + """ + Gets the document response from solr + :return: Document response + """ + + +class SolrGroupResult: + """ + Represents a group result + """ + + def get_field_result(self) -> Optional[List[SolrGroupFieldResult]]: + """ + Gets the field results form a group query + :return: List of group field results + """ + + def get_query_result(self) -> Optional[SolrDocsResponse]: + """ + Gets the query result from a group query + :return: Query result + """ + + def get_simple_result(self) -> Optional[SolrDocsResponse]: + """ + Gets the result from a group query where `GroupFormatting.Simple` was used + :return: Simple result + """ + + def get_matches(self) -> int: + """ + Gets the number of matches for a group query + :return: Number of matches + """ + + def get_n_groups(self) -> int: + """ + Gets the number of groups for a group query + :return: Number of groups + """ + + +class SolrJsonFacetResponse: + """ + A response from a json facet query + """ + + def get_buckets(self) -> List["SolrJsonFacetResponse"]: + """ + Get the buckets for this facet + :return: A list of buckets + """ + + def get_flat_facets(self) -> Dict[str, Any]: + """ + Get stat counts for this facet + :return: A dictionary of stat counts + """ + + def get_nested_facets(self) -> Dict[str, "SolrJsonFacetResponse"]: + """ + Get the nested facets for this facet + :return: A dictionary of nested facets + """ + + def get_count(self) -> Optional[int]: + """ + Get the count for this facet + :return: The count for this facet + """ + + def get_val(self) -> Optional[Any]: + """ + If a bucket facet, this value will be set + :return: The value for this facet + """ + + +class SolrDocsResponse: + def get_num_found(self) -> int: + """Get the number of documents found in the query""" + + def get_start(self) -> int: + """Get the start index of the query""" + + def get_num_found_exact(self) -> bool: + """Get whether the number of documents found is exact. This field only exists on Solr 8.6+. On older versions, this will always be true.""" + + def get_docs(self) -> List[Dict[str, Any]]: + """Get the documents from the query""" + + +class SolrResponse: + """The response from a solr query""" + + def get_docs_response(self) -> Optional[SolrDocsResponse]: + """Get the response from a solr query""" + + def get_groups(self) -> Dict[str, "SolrGroupResult"]: + """Get the groups from a solr query""" + + def get_next_cursor_mark(self) -> Optional[str]: + """Get the next cursor mark from a solr query""" + + def get_facet_set(self) -> "SolrFacetSetResult": + """Get facet counts""" + + def get_json_facets(self) -> Optional["SolrJsonFacetResponse"]: + """Get json facets""" diff --git a/wrappers/python/solrstice/queries.pyi b/wrappers/python/solrstice/queries.pyi deleted file mode 100644 index 97abb1b..0000000 --- a/wrappers/python/solrstice/queries.pyi +++ /dev/null @@ -1,126 +0,0 @@ -from enum import Enum -from typing import TYPE_CHECKING, Dict, List, Optional - -if TYPE_CHECKING: - from solrstice.def_type import DefType - from solrstice.facet_set import FacetSetComponent - from solrstice.group import GroupingComponent - from solrstice.hosts import SolrServerContext - from solrstice.json_facet import JsonFacetComponent - from solrstice.response import SolrResponse - -class SelectQuery: - """Builder for a select query - - :param q: The query string - :param fq: The filter queries - :param fl: The fields to return - :param sort: The sort order - :param rows: The number of rows to return - :param start: Set the start index - :param cursor_mark: Set the cursor mark - :param grouping: Set the grouping component - :param def_type: Set the query type - :param facet_set: Facet counts - :param json_facet: Json facets - """ - - def __init__( - self, - q: Optional[str] = None, - fq: Optional[List[str]] = None, - fl: Optional[List[str]] = None, - sort: Optional[List[str]] = None, - rows: Optional[int] = None, - start: Optional[int] = None, - cursor_mark: Optional[str] = None, - grouping: Optional["GroupingComponent"] = None, - def_type: Optional["DefType"] = None, - facet_set: Optional["FacetSetComponent"] = None, - json_facet: Optional["JsonFacetComponent"] = None, - ) -> None: - pass - async def execute( - self, context: "SolrServerContext", collection: str - ) -> "SolrResponse": - """Execute the query - - :param context: The context for the connection to the solr instance - :param collection: The collection to query - """ - def execute_blocking( - self, context: "SolrServerContext", collection: str - ) -> "SolrResponse": - """Execute the query - - :param context: The context for the connection to the solr instance - :param collection: The collection to query - """ - -class CommitType(Enum): - Hard = ("Hard",) - Soft = "Soft" - -class UpdateQuery: - """Builder for an update query - - :param handler: The handler for the update query - :param commit_type: The commit type for the update query - """ - - def __init__( - self, - handler: Optional[str] = "update", - commit_type: Optional[CommitType] = CommitType.Hard, - ) -> None: - pass - async def execute( - self, context: "SolrServerContext", collection: str, data: List[Dict] - ) -> "SolrResponse": - """Execute the query - - :param context: The context for the connection to the solr instance - :param collection: The collection to update - :param data: The data to update - """ - def execute_blocking( - self, context: "SolrServerContext", collection: str, data: List[Dict] - ) -> "SolrResponse": - """Execute the query - - :param context: The context for the connection to the solr instance - :param collection: The collection to update - :param data: The data to update - """ - -class DeleteQuery: - """Builder for a delete query - - :param handler: The handler for the delete query - :param commit_type: The commit type for the delete query - """ - - def __init__( - self, - handler: Optional[str] = "update", - commit_type: Optional[CommitType] = CommitType.Hard, - ids: Optional[List[str]] = None, - queries: Optional[List[str]] = None, - ) -> None: - pass - async def execute( - self, context: "SolrServerContext", collection: str - ) -> "SolrResponse": - """Execute the query - - :param context: The context for the connection to the solr instance - :param collection: The collection to delete from - """ - def execute_blocking( - self, context: "SolrServerContext", collection: str - ) -> "SolrResponse": - """Execute the query - - :param context: The context for the connection to the solr instance - :param collection: The collection to delete from - """ diff --git a/wrappers/python/solrstice/response.pyi b/wrappers/python/solrstice/response.pyi deleted file mode 100644 index 081c20b..0000000 --- a/wrappers/python/solrstice/response.pyi +++ /dev/null @@ -1,30 +0,0 @@ -from typing import TYPE_CHECKING, Any, Dict, List, Optional - -if TYPE_CHECKING: - from solrstice.facet_set import SolrFacetSetResult - from solrstice.group import SolrGroupResult - from solrstice.json_facet import SolrJsonFacetResponse - -class SolrDocsResponse: - def get_num_found(self) -> int: - """Get the number of documents found in the query""" - def get_start(self) -> int: - """Get the start index of the query""" - def get_num_found_exact(self) -> bool: - """Get whether the number of documents found is exact. This field only exists on Solr 8.6+. On older versions, this will always be true.""" - def get_docs(self) -> List[Dict[str, Any]]: - """Get the documents from the query""" - -class SolrResponse: - """The response from a solr query""" - - def get_docs_response(self) -> Optional[SolrDocsResponse]: - """Get the response from a solr query""" - def get_groups(self) -> Dict[str, "SolrGroupResult"]: - """Get the groups from a solr query""" - def get_next_cursor_mark(self) -> Optional[str]: - """Get the next cursor mark from a solr query""" - def get_facet_set(self) -> "SolrFacetSetResult": - """Get facet counts""" - def get_json_facets(self) -> Optional["SolrJsonFacetResponse"]: - """Get json facets""" diff --git a/wrappers/python/src/clients.rs b/wrappers/python/src/clients.rs index cba520c..3d231be 100644 --- a/wrappers/python/src/clients.rs +++ b/wrappers/python/src/clients.rs @@ -18,14 +18,7 @@ use pyo3::prelude::*; use std::collections::HashMap; use std::path::PathBuf; -#[pymodule] -pub fn clients(_py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> { - m.add_class::()?; - m.add_class::()?; - Ok(()) -} - -#[pyclass(name = "AsyncSolrCloudClient", module = "solrstice.clients", subclass)] +#[pyclass(name = "AsyncSolrCloudClient", module = "solrstice", subclass)] #[derive(Clone)] pub struct AsyncSolrCloudClientWrapper(SolrServerContextWrapper); @@ -148,11 +141,7 @@ impl AsyncSolrCloudClientWrapper { } } -#[pyclass( - name = "BlockingSolrCloudClient", - module = "solrstice.clients", - subclass -)] +#[pyclass(name = "BlockingSolrCloudClient", module = "solrstice", subclass)] #[derive(Clone)] pub struct BlockingSolrCloudClientWrapper(SolrServerContextWrapper); diff --git a/wrappers/python/src/hosts.rs b/wrappers/python/src/hosts.rs index 3dc2d5a..54b55e1 100644 --- a/wrappers/python/src/hosts.rs +++ b/wrappers/python/src/hosts.rs @@ -1,7 +1,3 @@ -use crate::models::context::{ - FastLoggingPolicyWrapper, LoggingPolicyWrapper, OffLoggingPolicyWrapper, - PrettyLoggingPolicyWrapper, SolrServerContextWrapper, -}; use crate::models::error::PyErrWrapper; use async_trait::async_trait; use pyo3::prelude::*; @@ -13,23 +9,7 @@ use std::borrow::Cow; use std::sync::Arc; use std::time::Duration; -#[pymodule] -pub fn hosts(_py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> { - m.add_class::()?; - m.add_class::()?; - m.add_class::()?; - m.add_class::()?; - m.add_class::()?; - m.add_class::()?; - - m.add_class::()?; - m.add_class::()?; - m.add_class::()?; - m.add_class::()?; - Ok(()) -} - -#[pyclass(name = "SolrHost", module = "solrstice.hosts", subclass)] +#[pyclass(name = "SolrHost", module = "solrstice", subclass)] #[derive(Clone)] pub struct SolrHostWrapper { pub solr_host: Arc, @@ -42,7 +22,7 @@ impl SolrHost for SolrHostWrapper { } } -#[pyclass(name = "SolrSingleServerHost", extends = SolrHostWrapper, module= "solrstice.hosts", subclass)] +#[pyclass(name = "SolrSingleServerHost", extends = SolrHostWrapper, module = "solrstice", subclass)] #[derive(Clone)] pub struct SolrSingleServerHostWrapper; @@ -59,7 +39,7 @@ impl SolrSingleServerHostWrapper { } } -#[pyclass(name = "SolrMultipleServerHost", extends = SolrHostWrapper, module= "solrstice.hosts", subclass)] +#[pyclass(name = "SolrMultipleServerHost", extends = SolrHostWrapper, module = "solrstice", subclass)] #[derive(Clone)] pub struct SolrMultipleServerHostWrapper; @@ -79,11 +59,15 @@ impl SolrMultipleServerHostWrapper { } } -#[pyclass(name = "ZookeeperEnsembleHost", extends = SolrHostWrapper, module= "solrstice.hosts", subclass)] +#[pyclass(name = "ZookeeperEnsembleHost", extends = SolrHostWrapper, module = "solrstice", subclass)] #[derive(Clone)] pub struct ZookeeperEnsembleHostWrapper; -#[pyclass(name = "ZookeeperEnsembleHostConnector", subclass)] +#[pyclass( + name = "ZookeeperEnsembleHostConnector", + module = "solrstice", + subclass +)] #[derive(Clone)] pub struct ZookeeperEnsembleHostConnectorWrapper(ZookeeperEnsembleHostConnector); diff --git a/wrappers/python/src/lib.rs b/wrappers/python/src/lib.rs index fc5a0fc..eb357cd 100644 --- a/wrappers/python/src/lib.rs +++ b/wrappers/python/src/lib.rs @@ -3,17 +3,36 @@ pub mod hosts; pub mod models; pub mod queries; -use crate::clients::clients as clients_module; -use crate::hosts::hosts as hosts_module; -use crate::models::auth::auth as auth_module; -use crate::models::facet_set::facet_set as facet_set_module; -use crate::models::group::group as group_module; -use crate::models::json_facet::json_facet as json_facet_module; -use crate::models::response::response as response_module; +use crate::clients::{AsyncSolrCloudClientWrapper, BlockingSolrCloudClientWrapper}; +use crate::hosts::{ + SolrHostWrapper, SolrMultipleServerHostWrapper, SolrSingleServerHostWrapper, + ZookeeperEnsembleHostConnectorWrapper, ZookeeperEnsembleHostWrapper, +}; +use crate::models::auth::{SolrAuthWrapper, SolrBasicAuthWrapper}; +use crate::models::context::{ + FastLoggingPolicyWrapper, LoggingPolicyWrapper, OffLoggingPolicyWrapper, + PrettyLoggingPolicyWrapper, SolrServerContextWrapper, +}; +use crate::models::facet_set::{SolrFacetSetResultWrapper, SolrPivotFacetResultWrapper}; +use crate::models::group::{SolrGroupFieldResultWrapper, SolrGroupResultWrapper}; +use crate::models::json_facet::SolrJsonFacetResponseWrapper; +use crate::models::response::{SolrDocsResponseWrapper, SolrResponseWrapper}; use crate::queries::alias::alias as alias_module; use crate::queries::collection::collection as collection_module; +use crate::queries::components::facet_set::{ + FacetSetComponentWrapper, FieldFacetComponentWrapper, FieldFacetEntryWrapper, + FieldFacetMethodWrapper, FieldFacetSortWrapper, PivotFacetComponentWrapper, +}; +use crate::queries::components::grouping::{GroupFormattingWrapper, GroupingComponentWrapper}; +use crate::queries::components::json_facet::{ + JsonFacetComponentWrapper, JsonFacetTypeWrapper, JsonQueryFacetWrapper, JsonStatFacetWrapper, + JsonTermsFacetWrapper, +}; use crate::queries::config::config as config_module; -use crate::queries::def_type::def_type as def_type_module; +use crate::queries::def_type::{ + DefTypeWrapper, DismaxQueryWrapper, EdismaxQueryWrapper, LuceneQueryWrapper, + QueryOperatorWrapper, +}; use crate::queries::index::{CommitTypeWrapper, DeleteQueryWrapper, UpdateQueryWrapper}; use crate::queries::select::SelectQueryWrapper; use pyo3::prelude::*; @@ -21,12 +40,17 @@ use pyo3::types::PyDict; use pyo3::wrap_pymodule; #[pymodule] -#[pyo3(name = "queries")] -fn queries_module(_py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> { - m.add_class::()?; - m.add_class::()?; - m.add_class::()?; - m.add_class::()?; +#[pyo3(name = "models")] +fn models_module(_py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> { + m.add_class::()?; + m.add_class::()?; + m.add_class::()?; + m.add_class::()?; + m.add_class::()?; + m.add_class::()?; + m.add_class::()?; + m.add_class::()?; + m.add_class::()?; Ok(()) } @@ -39,6 +63,51 @@ fn solrstice(_py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> { let sys_modules = sys.getattr("modules")?; let sys_modules: &Bound<'_, PyDict> = sys_modules.downcast()?; + m.add_class::()?; + m.add_class::()?; + m.add_class::()?; + m.add_class::()?; + m.add_class::()?; + + m.add_class::()?; + m.add_class::()?; + m.add_class::()?; + + m.add_class::()?; + m.add_class::()?; + m.add_class::()?; + m.add_class::()?; + m.add_class::()?; + m.add_class::()?; + + m.add_class::()?; + m.add_class::()?; + m.add_class::()?; + m.add_class::()?; + m.add_class::()?; + + m.add_class::()?; + m.add_class::()?; + m.add_class::()?; + m.add_class::()?; + m.add_class::()?; + m.add_class::()?; + m.add_class::()?; + m.add_class::()?; + m.add_class::()?; + m.add_class::()?; + + m.add_class::()?; + m.add_class::()?; + + m.add_class::()?; + m.add_class::()?; + m.add_class::()?; + m.add_class::()?; + + m.add_class::()?; + m.add_class::()?; + m.add_wrapped(wrap_pymodule!(config_module))?; sys_modules.set_item("solrstice.config", m.getattr("config")?)?; @@ -48,31 +117,8 @@ fn solrstice(_py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> { m.add_wrapped(wrap_pymodule!(alias_module))?; sys_modules.set_item("solrstice.alias", m.getattr("alias")?)?; - m.add_wrapped(wrap_pymodule!(clients_module))?; - sys_modules.set_item("solrstice.clients", m.getattr("clients")?)?; - - m.add_wrapped(wrap_pymodule!(hosts_module))?; - sys_modules.set_item("solrstice.hosts", m.getattr("hosts")?)?; - - m.add_wrapped(wrap_pymodule!(auth_module))?; - sys_modules.set_item("solrstice.auth", m.getattr("auth")?)?; - - m.add_wrapped(wrap_pymodule!(queries_module))?; - sys_modules.set_item("solrstice.queries", m.getattr("queries")?)?; - - m.add_wrapped(wrap_pymodule!(response_module))?; - sys_modules.set_item("solrstice.response", m.getattr("response")?)?; - - m.add_wrapped(wrap_pymodule!(group_module))?; - sys_modules.set_item("solrstice.group", m.getattr("group")?)?; - - m.add_wrapped(wrap_pymodule!(def_type_module))?; - sys_modules.set_item("solrstice.def_type", m.getattr("def_type")?)?; - - m.add_wrapped(wrap_pymodule!(facet_set_module))?; - sys_modules.set_item("solrstice.facet_set", m.getattr("facet_set")?)?; + m.add_wrapped(wrap_pymodule!(models_module))?; + sys_modules.set_item("solrstice.models", m.getattr("models")?)?; - m.add_wrapped(wrap_pymodule!(json_facet_module))?; - sys_modules.set_item("solrstice.json_facet", m.getattr("json_facet")?)?; Ok(()) } diff --git a/wrappers/python/src/models/auth.rs b/wrappers/python/src/models/auth.rs index 904d824..d92c38a 100644 --- a/wrappers/python/src/models/auth.rs +++ b/wrappers/python/src/models/auth.rs @@ -2,14 +2,7 @@ use pyo3::prelude::*; use solrstice::{SolrAuth, SolrBasicAuth}; use std::sync::Arc; -#[pymodule] -pub fn auth(_py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> { - m.add_class::()?; - m.add_class::()?; - Ok(()) -} - -#[pyclass(name = "SolrAuth", module = "solrstice.auth", subclass)] +#[pyclass(name = "SolrAuth", module = "solrstice", subclass)] #[derive(Clone)] pub struct SolrAuthWrapper { pub solr_auth: Arc, @@ -21,7 +14,7 @@ impl SolrAuth for SolrAuthWrapper { } } -#[pyclass(name = "SolrBasicAuth", extends=SolrAuthWrapper, module = "solrstice.auth", subclass)] +#[pyclass(name = "SolrBasicAuth", extends=SolrAuthWrapper, module = "solrstice", subclass)] #[derive(Clone)] pub struct SolrBasicAuthWrapper {} diff --git a/wrappers/python/src/models/context.rs b/wrappers/python/src/models/context.rs index 36561ce..a94ef21 100644 --- a/wrappers/python/src/models/context.rs +++ b/wrappers/python/src/models/context.rs @@ -11,7 +11,7 @@ pub enum SolrHostUnion { String(String), } -#[pyclass(name = "SolrServerContext", module = "solrstice.hosts", subclass)] +#[pyclass(name = "SolrServerContext", module = "solrstice", subclass)] #[derive(Clone)] pub struct SolrServerContextWrapper(SolrServerContext); @@ -52,7 +52,7 @@ impl<'a> From<&'a SolrServerContextWrapper> for &'a SolrServerContext { } } -#[pyclass(name = "LoggingPolicy", module = "solrstice.hosts", subclass)] +#[pyclass(name = "LoggingPolicy", module = "solrstice", subclass)] #[derive(Clone)] pub struct LoggingPolicyWrapper(LoggingPolicy); @@ -68,7 +68,7 @@ impl From for LoggingPolicyWrapper { } } -#[pyclass(name = "OffLoggingPolicy", extends=LoggingPolicyWrapper, module = "solrstice.hosts", subclass)] +#[pyclass(name = "OffLoggingPolicy", extends=LoggingPolicyWrapper, module = "solrstice", subclass)] #[derive(Clone, Serialize, Deserialize)] pub struct OffLoggingPolicyWrapper {} @@ -80,7 +80,7 @@ impl OffLoggingPolicyWrapper { } } -#[pyclass(name = "FastLoggingPolicy", extends=LoggingPolicyWrapper, module = "solrstice.hosts", subclass)] +#[pyclass(name = "FastLoggingPolicy", extends=LoggingPolicyWrapper, module = "solrstice", subclass)] #[derive(Clone, Serialize, Deserialize)] pub struct FastLoggingPolicyWrapper {} @@ -95,7 +95,7 @@ impl FastLoggingPolicyWrapper { } } -#[pyclass(name = "PrettyLoggingPolicy", extends=LoggingPolicyWrapper, module = "solrstice.hosts", subclass)] +#[pyclass(name = "PrettyLoggingPolicy", extends=LoggingPolicyWrapper, module = "solrstice", subclass)] #[derive(Clone, Serialize, Deserialize)] pub struct PrettyLoggingPolicyWrapper {} diff --git a/wrappers/python/src/models/facet_set.rs b/wrappers/python/src/models/facet_set.rs index 7a9cf1d..931b9c4 100644 --- a/wrappers/python/src/models/facet_set.rs +++ b/wrappers/python/src/models/facet_set.rs @@ -1,28 +1,11 @@ use crate::models::error::PyErrWrapper; -use crate::queries::components::facet_set::{ - FacetSetComponentWrapper, FieldFacetComponentWrapper, FieldFacetEntryWrapper, - FieldFacetMethodWrapper, FieldFacetSortWrapper, PivotFacetComponentWrapper, -}; use pyo3::prelude::*; use pythonize::pythonize; use solrstice::models::{SolrFacetSetResult, SolrFieldFacetResult, SolrPivotFacetResult}; use std::collections::HashMap; -#[pymodule] -pub fn facet_set(_py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> { - m.add_class::()?; - m.add_class::()?; - m.add_class::()?; - m.add_class::()?; - m.add_class::()?; - m.add_class::()?; - m.add_class::()?; - m.add_class::()?; - Ok(()) -} - #[derive(Clone, Debug, PartialEq, Default)] -#[pyclass(name = "SolrFacetSetResult", module = "solrstice.facet_set", subclass)] +#[pyclass(name = "SolrFacetSetResult", module = "solrstice.models", subclass)] pub struct SolrFacetSetResultWrapper(SolrFacetSetResult); #[pymethods] @@ -73,11 +56,7 @@ impl From<&SolrFacetSetResult> for SolrFacetSetResultWrapper { } #[derive(Clone, Debug, PartialEq)] -#[pyclass( - name = "SolrPivotFacetResult", - module = "solrstice.facet_set", - subclass -)] +#[pyclass(name = "SolrPivotFacetResult", module = "solrstice.models", subclass)] pub struct SolrPivotFacetResultWrapper(SolrPivotFacetResult); #[pymethods] @@ -130,11 +109,7 @@ impl From<&SolrPivotFacetResult> for SolrPivotFacetResultWrapper { } #[derive(Clone, Debug, PartialEq)] -#[pyclass( - name = "SolrFieldFacetResult", - module = "solrstice.facet_set", - subclass -)] +#[pyclass(name = "SolrFieldFacetResult", module = "solrstice.models", subclass)] pub struct SolrFieldFacetResultWrapper(SolrFieldFacetResult); #[pymethods] diff --git a/wrappers/python/src/models/group.rs b/wrappers/python/src/models/group.rs index c0214ae..65615e5 100644 --- a/wrappers/python/src/models/group.rs +++ b/wrappers/python/src/models/group.rs @@ -1,21 +1,11 @@ use crate::models::error::PyErrWrapper; use crate::models::response::SolrDocsResponseWrapper; -use crate::queries::components::grouping::{GroupFormattingWrapper, GroupingComponentWrapper}; use pyo3::prelude::*; use pythonize::pythonize; use solrstice::models::{SolrGroupFieldResult, SolrGroupResult}; -#[pymodule] -pub fn group(_py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> { - m.add_class::()?; - m.add_class::()?; - m.add_class::()?; - m.add_class::()?; - Ok(()) -} - #[derive(Clone)] -#[pyclass(name = "SolrGroupResult", module = "solrstice.group", subclass)] +#[pyclass(name = "SolrGroupResult", module = "solrstice.models", subclass)] pub struct SolrGroupResultWrapper(SolrGroupResult); #[pymethods] @@ -62,7 +52,7 @@ impl From for SolrGroupResult { } #[derive(Clone)] -#[pyclass(name = "SolrGroupFieldResult", module = "solrstice.group", subclass)] +#[pyclass(name = "SolrGroupFieldResult", module = "solrstice.models", subclass)] pub struct SolrGroupFieldResultWrapper(SolrGroupFieldResult); #[pymethods] diff --git a/wrappers/python/src/models/json_facet.rs b/wrappers/python/src/models/json_facet.rs index f957510..b4c4714 100644 --- a/wrappers/python/src/models/json_facet.rs +++ b/wrappers/python/src/models/json_facet.rs @@ -1,30 +1,11 @@ use crate::models::error::PyErrWrapper; -use crate::queries::components::json_facet::{ - JsonFacetComponentWrapper, JsonFacetTypeWrapper, JsonQueryFacetWrapper, JsonStatFacetWrapper, - JsonTermsFacetWrapper, -}; use pyo3::prelude::*; use pythonize::pythonize; use solrstice::models::SolrJsonFacetResponse; use std::collections::HashMap; -#[pymodule] -pub fn json_facet(_py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> { - m.add_class::()?; - m.add_class::()?; - m.add_class::()?; - m.add_class::()?; - m.add_class::()?; - m.add_class::()?; - Ok(()) -} - #[derive(Clone, Debug, PartialEq)] -#[pyclass( - name = "SolrJsonFacetResponse", - module = "solrstice.json_facet", - subclass -)] +#[pyclass(name = "SolrJsonFacetResponse", module = "solrstice.models", subclass)] pub struct SolrJsonFacetResponseWrapper(SolrJsonFacetResponse); #[pymethods] diff --git a/wrappers/python/src/models/response.rs b/wrappers/python/src/models/response.rs index 7858a55..321e66d 100644 --- a/wrappers/python/src/models/response.rs +++ b/wrappers/python/src/models/response.rs @@ -1,23 +1,14 @@ use crate::models::error::PyErrWrapper; use crate::models::facet_set::SolrFacetSetResultWrapper; -use crate::models::group::{SolrGroupFieldResultWrapper, SolrGroupResultWrapper}; +use crate::models::group::SolrGroupResultWrapper; use crate::models::json_facet::SolrJsonFacetResponseWrapper; use pyo3::prelude::*; use pythonize::pythonize; use solrstice::models::{SolrDocsResponse, SolrResponse}; use std::collections::HashMap; -#[pymodule] -pub fn response(_py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> { - m.add_class::()?; - m.add_class::()?; - m.add_class::()?; - m.add_class::()?; - Ok(()) -} - #[derive(Clone)] -#[pyclass(name = "SolrDocsResponse", module = "solrstice.response", subclass)] +#[pyclass(name = "SolrDocsResponse", module = "solrstice.models", subclass)] pub struct SolrDocsResponseWrapper(SolrDocsResponse); impl From for SolrDocsResponseWrapper { @@ -73,7 +64,7 @@ impl SolrDocsResponseWrapper { } #[derive(Clone)] -#[pyclass(name = "SolrResponse", module = "solrstice.response", subclass)] +#[pyclass(name = "SolrResponse", module = "solrstice.models", subclass)] pub struct SolrResponseWrapper(SolrResponse); impl From for SolrResponseWrapper { diff --git a/wrappers/python/src/queries/components/facet_set.rs b/wrappers/python/src/queries/components/facet_set.rs index 78dd934..2e3d528 100644 --- a/wrappers/python/src/queries/components/facet_set.rs +++ b/wrappers/python/src/queries/components/facet_set.rs @@ -5,7 +5,7 @@ use solrstice::{ }; #[derive(Clone, Debug, PartialEq)] -#[pyclass(name = "FacetSetComponent", module = "solrstice.facet_set", subclass)] +#[pyclass(name = "FacetSetComponent", module = "solrstice", subclass)] pub struct FacetSetComponentWrapper(FacetSetComponent); #[pymethods] @@ -55,7 +55,7 @@ impl From<&FacetSetComponent> for FacetSetComponentWrapper { } #[derive(Clone, Debug, PartialEq)] -#[pyclass(name = "PivotFacetComponent", module = "solrstice.facet_set", subclass)] +#[pyclass(name = "PivotFacetComponent", module = "solrstice", subclass)] pub struct PivotFacetComponentWrapper(PivotFacetComponent); #[pymethods] @@ -95,7 +95,7 @@ impl From<&PivotFacetComponent> for PivotFacetComponentWrapper { } #[derive(Clone, Debug, PartialEq)] -#[pyclass(name = "FieldFacetComponent", module = "solrstice.facet_set", subclass)] +#[pyclass(name = "FieldFacetComponent", module = "solrstice", subclass)] pub struct FieldFacetComponentWrapper(FieldFacetComponent); #[pymethods] @@ -135,7 +135,7 @@ impl From<&FieldFacetComponent> for FieldFacetComponentWrapper { } #[derive(Clone, Copy, Debug, PartialEq)] -#[pyclass(name = "FieldFacetSort", module = "solrstice.facet_set")] +#[pyclass(name = "FieldFacetSort")] pub enum FieldFacetSortWrapper { Count, Index, @@ -160,7 +160,7 @@ impl From for FieldFacetSortWrapper { } #[derive(Clone, Copy, Debug, PartialEq)] -#[pyclass(name = "FieldFacetMethod", module = "solrstice.facet_set")] +#[pyclass(name = "FieldFacetMethod")] pub enum FieldFacetMethodWrapper { Enum, Fc, @@ -188,7 +188,7 @@ impl From for FieldFacetMethodWrapper { } #[derive(Clone, Debug, PartialEq)] -#[pyclass(name = "FieldFacetEntry", module = "solrstice.facet_set", subclass)] +#[pyclass(name = "FieldFacetEntry", module = "solrstice", subclass)] pub struct FieldFacetEntryWrapper(FieldFacetEntry); #[pymethods] diff --git a/wrappers/python/src/queries/components/grouping.rs b/wrappers/python/src/queries/components/grouping.rs index c384d28..d4c5cf8 100644 --- a/wrappers/python/src/queries/components/grouping.rs +++ b/wrappers/python/src/queries/components/grouping.rs @@ -2,7 +2,7 @@ use pyo3::prelude::*; use serde::{Deserialize, Serialize}; use solrstice::{GroupFormatting, GroupingComponent}; -#[pyclass(name = "GroupingComponent", module = "solrstice.group", subclass)] +#[pyclass(name = "GroupingComponent", module = "solrstice", subclass)] #[derive(Clone, Serialize, Deserialize)] pub struct GroupingComponentWrapper(GroupingComponent); @@ -19,7 +19,7 @@ impl<'a> From<&'a GroupingComponentWrapper> for &'a GroupingComponent { } #[derive(Clone, Copy, Serialize, Deserialize)] -#[pyclass(name = "GroupFormatting", module = "solrstice.group")] +#[pyclass(name = "GroupFormatting")] pub enum GroupFormattingWrapper { Simple, Grouped, diff --git a/wrappers/python/src/queries/components/json_facet.rs b/wrappers/python/src/queries/components/json_facet.rs index d8e8164..0dd5d0c 100644 --- a/wrappers/python/src/queries/components/json_facet.rs +++ b/wrappers/python/src/queries/components/json_facet.rs @@ -3,7 +3,7 @@ use solrstice::{JsonFacetComponent, JsonFacetType, JsonQueryFacet, JsonStatFacet use std::collections::HashMap; #[derive(Clone, Debug, PartialEq)] -#[pyclass(name = "JsonFacetComponent", module = "solrstice.json_facet", subclass)] +#[pyclass(name = "JsonFacetComponent", module = "solrstice", subclass)] pub struct JsonFacetComponentWrapper(JsonFacetComponent); #[pymethods] @@ -43,7 +43,7 @@ impl From<&JsonFacetComponent> for JsonFacetComponentWrapper { } #[derive(Clone, Debug, PartialEq)] -#[pyclass(name = "JsonFacetType", module = "solrstice.json_facet", subclass)] +#[pyclass(name = "JsonFacetType", module = "solrstice", subclass)] pub struct JsonFacetTypeWrapper(JsonFacetType); impl From for JsonFacetType { @@ -71,7 +71,7 @@ impl From<&JsonFacetType> for JsonFacetTypeWrapper { } #[derive(Clone, Debug, PartialEq)] -#[pyclass(name = "JsonTermsFacet", extends = JsonFacetTypeWrapper, module = "solrstice.json_facet", subclass)] +#[pyclass(name = "JsonTermsFacet", extends = JsonFacetTypeWrapper, module = "solrstice", subclass)] pub struct JsonTermsFacetWrapper {} #[pymethods] @@ -105,7 +105,7 @@ impl JsonTermsFacetWrapper { } #[derive(Clone, Debug, PartialEq)] -#[pyclass(name = "JsonQueryFacet", extends = JsonFacetTypeWrapper ,module = "solrstice.json_facet", subclass)] +#[pyclass(name = "JsonQueryFacet", extends = JsonFacetTypeWrapper, module = "solrstice", subclass)] pub struct JsonQueryFacetWrapper {} #[pymethods] @@ -145,7 +145,7 @@ impl JsonQueryFacetWrapper { } #[derive(Clone, Debug, PartialEq)] -#[pyclass(name = "JsonStatFacet", extends = JsonFacetTypeWrapper, module = "solrstice.json_facet", subclass)] +#[pyclass(name = "JsonStatFacet", extends = JsonFacetTypeWrapper, module = "solrstice", subclass)] pub struct JsonStatFacetWrapper {} #[pymethods] diff --git a/wrappers/python/src/queries/def_type.rs b/wrappers/python/src/queries/def_type.rs index a59beae..64696c1 100644 --- a/wrappers/python/src/queries/def_type.rs +++ b/wrappers/python/src/queries/def_type.rs @@ -2,18 +2,8 @@ use pyo3::prelude::*; use serde::{Deserialize, Serialize}; use solrstice::{DefType, DismaxQuery, EdismaxQuery, LuceneQuery, QueryOperator}; -#[pymodule] -pub fn def_type(_py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> { - m.add_class::()?; - m.add_class::()?; - m.add_class::()?; - m.add_class::()?; - m.add_class::()?; - Ok(()) -} - #[derive(Debug, Copy, Clone, Deserialize, Serialize, PartialEq)] -#[pyclass(name = "QueryOperator", module = "solrstice.def_type")] +#[pyclass(name = "QueryOperator")] pub enum QueryOperatorWrapper { AND, OR, @@ -37,7 +27,7 @@ impl From for QueryOperatorWrapper { } } -#[pyclass(name = "DefType", module = "solrstice.def_type", subclass)] +#[pyclass(name = "DefType", module = "solrstice", subclass)] #[derive(Clone, Serialize, Deserialize)] pub struct DefTypeWrapper(DefType); @@ -63,7 +53,7 @@ impl DefTypeWrapper { } } -#[pyclass(name = "LuceneQuery", extends=DefTypeWrapper, module = "solrstice.def_type", subclass)] +#[pyclass(name = "LuceneQuery", extends=DefTypeWrapper, module = "solrstice", subclass)] #[derive(Clone, Serialize, Deserialize)] pub struct LuceneQueryWrapper {} @@ -83,7 +73,7 @@ impl LuceneQueryWrapper { } } -#[pyclass(name = "DismaxQuery", extends=DefTypeWrapper, module = "solrstice.def_type", subclass)] +#[pyclass(name = "DismaxQuery", extends=DefTypeWrapper, module = "solrstice", subclass)] #[derive(Clone, Serialize, Deserialize)] pub struct DismaxQueryWrapper {} @@ -116,7 +106,7 @@ impl DismaxQueryWrapper { } } -#[pyclass(name = "EdismaxQuery", extends=DefTypeWrapper, module = "solrstice.def_type", subclass)] +#[pyclass(name = "EdismaxQuery", extends=DefTypeWrapper, module = "solrstice", subclass)] #[derive(Clone, Serialize, Deserialize)] pub struct EdismaxQueryWrapper {} diff --git a/wrappers/python/src/queries/index.rs b/wrappers/python/src/queries/index.rs index 3366e2d..a763f5f 100644 --- a/wrappers/python/src/queries/index.rs +++ b/wrappers/python/src/queries/index.rs @@ -18,7 +18,7 @@ pub enum CommitTypeWrapper { } #[derive(Clone, Default, Serialize, Deserialize)] -#[pyclass(name = "UpdateQuery", module = "solrstice.queries", subclass)] +#[pyclass(name = "UpdateQuery", module = "solrstice", subclass)] pub struct UpdateQueryWrapper(UpdateQuery); #[pymethods] @@ -123,7 +123,7 @@ impl From for CommitTypeWrapper { } #[derive(Clone, Default, Serialize, Deserialize)] -#[pyclass(name = "DeleteQuery", module = "solrstice.queries", subclass)] +#[pyclass(name = "DeleteQuery", module = "solrstice", subclass)] pub struct DeleteQueryWrapper(DeleteQuery); #[pymethods] diff --git a/wrappers/python/src/queries/select.rs b/wrappers/python/src/queries/select.rs index e8a1ceb..1ac16b2 100644 --- a/wrappers/python/src/queries/select.rs +++ b/wrappers/python/src/queries/select.rs @@ -16,7 +16,7 @@ use solrstice::JsonFacetComponent; use solrstice::SelectQuery; use solrstice::SolrServerContext; -#[pyclass(name = "SelectQuery", module = "solrstice.queries", subclass)] +#[pyclass(name = "SelectQuery", module = "solrstice", subclass)] #[derive(Clone, Serialize, Deserialize)] pub struct SelectQueryWrapper(SelectQuery); diff --git a/wrappers/python/tests/helpers.py b/wrappers/python/tests/helpers.py index 2430c0f..c35264d 100644 --- a/wrappers/python/tests/helpers.py +++ b/wrappers/python/tests/helpers.py @@ -8,12 +8,9 @@ from dataclasses_json import DataClassJsonMixin, dataclass_json from dotenv import load_dotenv -from solrstice.auth import SolrBasicAuth -from solrstice.clients import AsyncSolrCloudClient -from solrstice.collection import create_collection, delete_collection +from solrstice import SolrBasicAuth, SolrServerContext, AsyncSolrCloudClient, SolrSingleServerHost, UpdateQuery +from solrstice.collection import delete_collection, create_collection from solrstice.config import delete_config, upload_config -from solrstice.hosts import SolrServerContext, SolrSingleServerHost -from solrstice.queries import UpdateQuery @dataclass @@ -65,7 +62,7 @@ def wait_for_solr(host: str, max_time: int): while time.time() < end: try: with urlopen( - f'{host}{"/solr/admin/collections"}?action=CLUSTERSTATUS' + f'{host}{"/solr/admin/collections"}?action=CLUSTERSTATUS' ) as response: if response.status == 200: return @@ -107,7 +104,7 @@ async def index_test_data(context: SolrServerContext, name: str) -> None: async def setup_collection( - context: SolrServerContext, name: str, config_path: str + context: SolrServerContext, name: str, config_path: str ) -> None: try: await delete_collection(context, name) diff --git a/wrappers/python/tests/test_clients.py b/wrappers/python/tests/test_clients.py index f3e074b..890b1bf 100644 --- a/wrappers/python/tests/test_clients.py +++ b/wrappers/python/tests/test_clients.py @@ -4,10 +4,8 @@ from helpers import Config, create_config from typing_extensions import Optional -from solrstice.auth import SolrAuth, SolrBasicAuth -from solrstice.clients import AsyncSolrCloudClient, BlockingSolrCloudClient -from solrstice.hosts import SolrServerContext, SolrSingleServerHost -from solrstice.queries import DeleteQuery, SelectQuery, UpdateQuery +from solrstice import AsyncSolrCloudClient, UpdateQuery, SelectQuery, DeleteQuery, BlockingSolrCloudClient, \ + SolrServerContext, SolrSingleServerHost, SolrAuth, SolrBasicAuth @pytest.fixture() diff --git a/wrappers/python/tests/test_def_type.py b/wrappers/python/tests/test_def_type.py index 0581f31..b79fbdb 100644 --- a/wrappers/python/tests/test_def_type.py +++ b/wrappers/python/tests/test_def_type.py @@ -8,8 +8,8 @@ wait_for_solr, ) -from solrstice.def_type import DismaxQuery, EdismaxQuery, LuceneQuery -from solrstice.queries import SelectQuery +from solrstice import DismaxQuery, EdismaxQuery, LuceneQuery +from solrstice import SelectQuery @pytest.fixture() diff --git a/wrappers/python/tests/test_facetset.py b/wrappers/python/tests/test_facetset.py index 538d91b..aa5d7d4 100644 --- a/wrappers/python/tests/test_facetset.py +++ b/wrappers/python/tests/test_facetset.py @@ -8,13 +8,13 @@ wait_for_solr, ) -from solrstice.facet_set import ( +from solrstice import ( FacetSetComponent, FieldFacetComponent, FieldFacetEntry, PivotFacetComponent, ) -from solrstice.queries import SelectQuery +from solrstice import SelectQuery @pytest.fixture() diff --git a/wrappers/python/tests/test_group.py b/wrappers/python/tests/test_group.py index a3db82f..e9d90af 100644 --- a/wrappers/python/tests/test_group.py +++ b/wrappers/python/tests/test_group.py @@ -8,8 +8,8 @@ wait_for_solr, ) -from solrstice.group import GroupingComponent -from solrstice.queries import SelectQuery +from solrstice import GroupingComponent +from solrstice import SelectQuery @pytest.fixture() diff --git a/wrappers/python/tests/test_hosts.py b/wrappers/python/tests/test_hosts.py index 7d56943..14cef7f 100644 --- a/wrappers/python/tests/test_hosts.py +++ b/wrappers/python/tests/test_hosts.py @@ -7,9 +7,9 @@ from dotenv import load_dotenv from helpers import wait_for_solr -from solrstice.auth import SolrBasicAuth +from solrstice import SolrBasicAuth from solrstice.config import get_configs, get_configs_blocking -from solrstice.hosts import ( +from solrstice import ( SolrMultipleServerHost, SolrServerContext, SolrSingleServerHost, diff --git a/wrappers/python/tests/test_index.py b/wrappers/python/tests/test_index.py index d4b829d..961227b 100644 --- a/wrappers/python/tests/test_index.py +++ b/wrappers/python/tests/test_index.py @@ -7,7 +7,7 @@ wait_for_solr, ) -from solrstice.queries import CommitType, UpdateQuery +from solrstice import CommitType, UpdateQuery @pytest.fixture() diff --git a/wrappers/python/tests/test_json_facet.py b/wrappers/python/tests/test_json_facet.py index b14d0cd..cbab630 100644 --- a/wrappers/python/tests/test_json_facet.py +++ b/wrappers/python/tests/test_json_facet.py @@ -8,13 +8,13 @@ wait_for_solr, ) -from solrstice.json_facet import ( +from solrstice import ( JsonFacetComponent, JsonQueryFacet, JsonStatFacet, JsonTermsFacet, ) -from solrstice.queries import SelectQuery +from solrstice import SelectQuery @pytest.fixture() diff --git a/wrappers/python/tests/test_latency.py b/wrappers/python/tests/test_latency.py index 987b383..e57990d 100644 --- a/wrappers/python/tests/test_latency.py +++ b/wrappers/python/tests/test_latency.py @@ -7,9 +7,9 @@ import pytest from helpers import Config, create_config -from solrstice.auth import SolrBasicAuth -from solrstice.clients import AsyncSolrCloudClient, BlockingSolrCloudClient -from solrstice.hosts import SolrServerContext, SolrSingleServerHost +from solrstice import SolrBasicAuth +from solrstice import AsyncSolrCloudClient, BlockingSolrCloudClient +from solrstice import SolrServerContext, SolrSingleServerHost @pytest.fixture() @@ -67,7 +67,7 @@ def get_configs_blocking(host: str, username: Optional[str], password: Optional[ async def get_configs_async( - host: str, username: Optional[str], password: Optional[str] + host: str, username: Optional[str], password: Optional[str] ): auth = None if not username else SolrBasicAuth(username, password) client = AsyncSolrCloudClient(SolrServerContext(SolrSingleServerHost(host), auth)) diff --git a/wrappers/python/tests/test_logging.py b/wrappers/python/tests/test_logging.py index c8dd6cc..ee8cbb0 100644 --- a/wrappers/python/tests/test_logging.py +++ b/wrappers/python/tests/test_logging.py @@ -4,8 +4,8 @@ from _pytest.logging import LogCaptureFixture from helpers import Config, create_config, wait_for_solr -from solrstice.clients import AsyncSolrCloudClient -from solrstice.hosts import OffLoggingPolicy, SolrServerContext +from solrstice import AsyncSolrCloudClient +from solrstice import OffLoggingPolicy, SolrServerContext @pytest.fixture() @@ -30,7 +30,7 @@ def config() -> Config: @pytest.mark.asyncio async def test_logging_does_not_log_message_if_disabled( - config: Config, caplog: LogCaptureFixture + config: Config, caplog: LogCaptureFixture ): wait_for_solr(config.solr_host, 30) diff --git a/wrappers/python/tests/test_multiprocessing.py b/wrappers/python/tests/test_multiprocessing.py index f1c35e2..ca2771b 100644 --- a/wrappers/python/tests/test_multiprocessing.py +++ b/wrappers/python/tests/test_multiprocessing.py @@ -6,10 +6,10 @@ import pytest from helpers import Config, create_config -from solrstice.auth import SolrBasicAuth -from solrstice.clients import BlockingSolrCloudClient -from solrstice.hosts import SolrServerContext, SolrSingleServerHost -from solrstice.queries import UpdateQuery +from solrstice import SolrBasicAuth +from solrstice import BlockingSolrCloudClient +from solrstice import SolrServerContext, SolrSingleServerHost +from solrstice import UpdateQuery @pytest.fixture() diff --git a/wrappers/python/tests/test_pickle.py b/wrappers/python/tests/test_pickle.py index b8b59ec..7410407 100644 --- a/wrappers/python/tests/test_pickle.py +++ b/wrappers/python/tests/test_pickle.py @@ -1,7 +1,7 @@ import pickle -from solrstice.group import GroupingComponent -from solrstice.queries import CommitType, DeleteQuery, SelectQuery, UpdateQuery +from solrstice import GroupingComponent +from solrstice import CommitType, DeleteQuery, SelectQuery, UpdateQuery def test_pickle_works_select_query_builder(): diff --git a/wrappers/python/tests/test_select.py b/wrappers/python/tests/test_select.py index 9115ea1..3a60943 100644 --- a/wrappers/python/tests/test_select.py +++ b/wrappers/python/tests/test_select.py @@ -8,7 +8,7 @@ wait_for_solr, ) -from solrstice.queries import SelectQuery +from solrstice import SelectQuery @pytest.fixture() From 72a7112c7b69c5f8d7ede0f8ce90beaaba6bf8c4 Mon Sep 17 00:00:00 2001 From: Sh1nku <42642351+Sh1nku@users.noreply.github.com> Date: Fri, 26 Jul 2024 13:14:01 +0200 Subject: [PATCH 3/5] Fix type checking errors in python module --- .github/workflows/test_python.yml | 12 +- wrappers/python/README.md | 241 ++++++++----- wrappers/python/mypy.ini | 2 +- wrappers/python/pyrightconfig.json | 4 +- wrappers/python/solrstice/__init__.pyi | 333 ++++++++---------- wrappers/python/solrstice/alias.pyi | 12 +- wrappers/python/solrstice/collection.pyi | 28 +- wrappers/python/solrstice/config.pyi | 12 +- wrappers/python/solrstice/models.pyi | 8 - wrappers/python/tests/__init__.py | 0 wrappers/python/tests/helpers.py | 17 +- wrappers/python/tests/test_alias.py | 11 +- wrappers/python/tests/test_clients.py | 44 ++- wrappers/python/tests/test_collection.py | 11 +- wrappers/python/tests/test_config.py | 11 +- wrappers/python/tests/test_def_type.py | 20 +- wrappers/python/tests/test_facetset.py | 37 +- wrappers/python/tests/test_group.py | 18 +- wrappers/python/tests/test_hosts.py | 37 +- wrappers/python/tests/test_index.py | 13 +- wrappers/python/tests/test_json_facet.py | 50 +-- wrappers/python/tests/test_latency.py | 29 +- wrappers/python/tests/test_logging.py | 13 +- wrappers/python/tests/test_multiprocessing.py | 24 +- wrappers/python/tests/test_pickle.py | 15 +- wrappers/python/tests/test_select.py | 21 +- 26 files changed, 545 insertions(+), 478 deletions(-) create mode 100644 wrappers/python/tests/__init__.py diff --git a/.github/workflows/test_python.yml b/.github/workflows/test_python.yml index c6d9e63..ddc395d 100644 --- a/.github/workflows/test_python.yml +++ b/.github/workflows/test_python.yml @@ -1,5 +1,5 @@ name: Test python wrapper -on: [push] +on: [ push ] jobs: checks: runs-on: ubuntu-latest @@ -35,18 +35,18 @@ jobs: - name: Start docker containers run: docker-compose up -d working-directory: ./docker/${{ matrix.docker-version }} - - name: Run tests + - name: Run pyright working-directory: ./wrappers/python run: | source venv/bin/activate - pytest + pyright - name: Run mypy working-directory: ./wrappers/python run: | source venv/bin/activate - mypy solrstice/ - - name: Run pyright + mypy + - name: Run tests working-directory: ./wrappers/python run: | source venv/bin/activate - pyright solrstice/ \ No newline at end of file + pytest \ No newline at end of file diff --git a/wrappers/python/README.md b/wrappers/python/README.md index f684bb8..57e2daf 100644 --- a/wrappers/python/README.md +++ b/wrappers/python/README.md @@ -31,7 +31,7 @@ pip install solrstice ```python import asyncio -from solrstice import SolrBasicAuth, SolrServerContext, SolrSingleServerHost, AsyncSolrCloudClient, UpdateQuery, +from solrstice import SolrBasicAuth, SolrServerContext, SolrSingleServerHost, AsyncSolrCloudClient, UpdateQuery, \ SelectQuery, DeleteQuery # A SolrServerContext specifies how the library should interact with Solr @@ -61,7 +61,7 @@ asyncio.run(main()) ### Blocking ```python -from solrstice import SolrBasicAuth, BlockingSolrCloudClient, SolrServerContext, SolrSingleServerHost, DeleteQuery, +from solrstice import SolrBasicAuth, BlockingSolrCloudClient, SolrServerContext, SolrSingleServerHost, DeleteQuery, \ SelectQuery, UpdateQuery # A SolrServerContext specifies how the library should interact with Solr @@ -88,22 +88,30 @@ client.delete(DeleteQuery(ids=['example_document']), 'example_collection') ### Field grouping ```python -group_builder = GroupingComponent(fields=["age"], limit=10) -select_builder = SelectQuery(fq=["age:[* TO *]"], grouping=group_builder) -groups = await client.select(select_builder, "example_collection").get_groups() -age_group = groups["age"] -docs = age_group.get_field_result() +from solrstice import GroupingComponent, SelectQuery, SolrServerContext, AsyncSolrCloudClient +client = AsyncSolrCloudClient(SolrServerContext('localhost:8983')) + +async def main(): + group_builder = GroupingComponent(fields=["age"], limit=10) + select_builder = SelectQuery(fq=["age:[* TO *]"], grouping=group_builder) + groups = (await client.select(select_builder, "example_collection")).get_groups() + age_group = groups["age"] + docs = age_group.get_field_result() ``` ### Query grouping ```python -group_builder = GroupingComponent(queries=["age:[0 TO 59]", "age:[60 TO *]"], limit=10) -select_builder = SelectQuery(fq=["age:[* TO *]"], grouping=group_builder) -groups = await client.select(select_builder, "example_collection").get_groups() -age_group = groups["age:[0 TO 59]"] -group = age_group.get_query_result() -docs = group.get_docs() +from solrstice import GroupingComponent, SelectQuery, SolrServerContext, AsyncSolrCloudClient +client = AsyncSolrCloudClient(SolrServerContext('localhost:8983')) + +async def main(): + group_builder = GroupingComponent(queries=["age:[0 TO 59]", "age:[60 TO *]"], limit=10) + select_builder = SelectQuery(fq=["age:[* TO *]"], grouping=group_builder) + groups = (await client.select(select_builder, "example_collection")).get_groups() + age_group = groups["age:[0 TO 59]"] + group = age_group.get_query_result() + docs = group.get_docs() ``` ## Query parsers @@ -111,28 +119,43 @@ docs = group.get_docs() ### Lucene ```python -query_parser = LuceneQuery(df="population") -select_builder = SelectQuery(q="outdoors", def_type=query_parser) -await client.select(select_builder, "example_collection") -docs = response.get_docs_response().get_docs() +from solrstice import LuceneQuery, SelectQuery, SolrServerContext, AsyncSolrCloudClient +client = AsyncSolrCloudClient(SolrServerContext('localhost:8983')) + +async def main(): + query_parser = LuceneQuery(df="population") + select_builder = SelectQuery(q="outdoors", def_type=query_parser) + response = (await client.select(select_builder, "example_collection")).get_docs_response() + assert response is not None + docs = response.get_docs() ``` ### Dismax ```python -query_parser = DismaxQuery(qf="interests^20", bq=["interests:cars^20"]) -select_builder = SelectQuery(q="outdoors", def_type=query_parser) -await client.select(select_builder, "example_collection") -docs = response.get_docs_response().get_docs() +from solrstice import DismaxQuery, SelectQuery, SolrServerContext, AsyncSolrCloudClient +client = AsyncSolrCloudClient(SolrServerContext('localhost:8983')) + +async def main(): + query_parser = DismaxQuery(qf="interests^20", bq=["interests:cars^20"]) + select_builder = SelectQuery(q="outdoors", def_type=query_parser) + response = (await client.select(select_builder, "example_collection")).get_docs_response() + assert response is not None + docs = response.get_docs() ``` ### Edismax ```python -query_parser = EdismaxQuery(qf="interests^20", bq=["interests:cars^20"]) -select_builder = SelectQuery(q="outdoors", def_type=query_parser) -await client.select(select_builder, "example_collection") -docs = response.get_docs_response().get_docs() +from solrstice import EdismaxQuery, SelectQuery, SolrServerContext, AsyncSolrCloudClient +client = AsyncSolrCloudClient(SolrServerContext('localhost:8983')) + +async def main(): + query_parser = EdismaxQuery(qf="interests^20", bq=["interests:cars^20"]) + select_builder = SelectQuery(q="outdoors", def_type=query_parser) + response = (await client.select(select_builder, "example_collection")).get_docs_response() + assert response is not None + docs = response.get_docs() ``` ## FacetSet Component @@ -140,32 +163,44 @@ docs = response.get_docs_response().get_docs() ### Pivot facet ```python -select_builder = SelectQuery(facet_set=FacetSetComponent(pivots=PivotFacetComponent(["interests,age"]))) -await client.select(select_builder, "example_collection") -facets = response.get_facet_set() -pivots = facets.get_pivots() -interests_age = pivot.get("interests,age") +from solrstice import FacetSetComponent, PivotFacetComponent, SelectQuery, SolrServerContext, AsyncSolrCloudClient +client = AsyncSolrCloudClient(SolrServerContext('localhost:8983')) + +async def main(): + select_builder = SelectQuery(facet_set=FacetSetComponent(pivots=PivotFacetComponent(["interests,age"]))) + response = await client.select(select_builder, "example_collection") + facets = response.get_facet_set() + pivots = facets.get_pivots() + interests_age = pivots.get("interests,age") ``` ### Field facet ```python -facet_set = FacetSetComponent(fields=FieldFacetComponent(fields=[FieldFacetEntry("age")])) -select_builder = SelectQuery(facet_set=facet_set) -response = await client.select(select_builder, "example_collection") -facets = response.get_facet_set() -fields = facets.get_fields() -age = fields.get("age") +from solrstice import FacetSetComponent, FieldFacetComponent, FieldFacetEntry, SelectQuery, SolrServerContext, AsyncSolrCloudClient +client = AsyncSolrCloudClient(SolrServerContext('localhost:8983')) + +async def main(): + facet_set = FacetSetComponent(fields=FieldFacetComponent(fields=[FieldFacetEntry("age")])) + select_builder = SelectQuery(facet_set=facet_set) + response = await client.select(select_builder, "example_collection") + facets = response.get_facet_set() + fields = facets.get_fields() + age = fields.get("age") ``` ### Query facet ```python -select_builder = SelectQuery(facet_set=FacetSetComponent(queries=["age:[0 TO 59]"])) -response = await client.select(select_builder, name) -facets = response.get_facet_set() -queries = facets.get_queries() -query = queries.get("age:[0 TO 59]") +from solrstice import AsyncSolrCloudClient, SolrServerContext, SelectQuery, FacetSetComponent, FacetSetComponent +client = AsyncSolrCloudClient(SolrServerContext('localhost:8983')) + +async def main(): + select_builder = SelectQuery(facet_set=FacetSetComponent(queries=["age:[0 TO 59]"])) + response = await client.select(select_builder, "example_collection") + facets = response.get_facet_set() + queries = facets.get_queries() + query = queries.get("age:[0 TO 59]") ``` ## Json Facet Component @@ -173,65 +208,80 @@ query = queries.get("age:[0 TO 59]") ### Query ```python -select_builder = SelectQuery( - json_facet=JsonFacetComponent( - facets={"below_60": JsonQueryFacet("age:[0 TO 59]")} - ) -) -response = await client.select(select_builder, "example_collection"") -facets = response.get_json_facets() -below_60 = facets.get_nested_facets().get("below_60") -assert below_60.get_count() == 4 +from solrstice import JsonFacetComponent, JsonQueryFacet, SelectQuery, SolrServerContext, AsyncSolrCloudClient +async def main(): + client = AsyncSolrCloudClient(SolrServerContext('localhost:8983')) + select_builder = SelectQuery( + json_facet=JsonFacetComponent( + facets={"below_60": JsonQueryFacet("age:[0 TO 59]")} + ) + ) + response = await client.select(select_builder, "example_collection") + facets = response.get_json_facets() + below_60 = facets.get_nested_facets().get("below_60") + assert below_60.get_count() == 4 ``` ### Stat ```python -select_builder = SelectQuery( - json_facet=JsonFacetComponent( - facets={"total_people": JsonStatFacet("sum(count)")} - ) -) -response = await client.select(select_builder, "example_collection") -facets = response.get_json_facets() -total_people = facets.get_flat_facets().get("total_people") -assert total_people == 1000 +from solrstice import JsonFacetComponent, JsonStatFacet, SelectQuery, SolrServerContext, AsyncSolrCloudClient +client = AsyncSolrCloudClient(SolrServerContext('localhost:8983')) + +async def main(): + select_builder = SelectQuery( + json_facet=JsonFacetComponent( + facets={"total_people": JsonStatFacet("sum(count)")} + ) + ) + response = await client.select(select_builder, "example_collection") + facets = response.get_json_facets() + total_people = facets.get_flat_facets().get("total_people") + assert total_people == 1000 ``` ### Terms ```python -select_builder = SelectQuery( - json_facet=JsonFacetComponent(facets={"age": JsonTermsFacet("age")}) -) -response = await config.async_client.select(select_builder, name) -facets = response.get_json_facets() -age_buckets = facets.get_nested_facets().get("age").get_buckets() -assert len(age_buckets) == 3 +from solrstice import AsyncSolrCloudClient, SolrServerContext, SelectQuery, JsonFacetComponent, JsonTermsFacet +client = AsyncSolrCloudClient(SolrServerContext('localhost:8983')) + +async def main(): + select_builder = SelectQuery( + json_facet=JsonFacetComponent(facets={"age": JsonTermsFacet("age")}) + ) + response = await client.select(select_builder, "example_collection") + facets = response.get_json_facets() + age_buckets = facets.get_nested_facets().get("age").get_buckets() + assert len(age_buckets) == 3 ``` ### Nested ```python -select_builder = SelectQuery( - json_facet=JsonFacetComponent( - facets={ - "below_60": JsonQueryFacet( - "age:[0 TO 59]", - facets={"total_people": JsonStatFacet("sum(count)")}, - ) - } - ) -) -response = await client.select(select_builder, "example_collection") -facets = response.get_json_facets() -total_people = ( - facets.get_nested_facets() - .get("below_60") - .get_flat_facets() - .get("total_people") -) -assert total_people == 750.0 +from solrstice import AsyncSolrCloudClient, SolrServerContext, SelectQuery, JsonFacetComponent, JsonQueryFacet, JsonStatFacet +client = AsyncSolrCloudClient(SolrServerContext('localhost:8983')) + +async def main(): + select_builder = SelectQuery( + json_facet=JsonFacetComponent( + facets={ + "below_60": JsonQueryFacet( + "age:[0 TO 59]", + facets={"total_people": JsonStatFacet("sum(count)")}, + ) + } + ) + ) + response = await client.select(select_builder, "example_collection") + facets = response.get_json_facets() + total_people = ( + facets.get_nested_facets() + .get("below_60") + .get_flat_facets() + .get("total_people") + ) + assert total_people == 750.0 ``` ## Hosts @@ -239,6 +289,8 @@ assert total_people == 750.0 ### Single Server ```python +from solrstice import SolrServerContext, SolrSingleServerHost, SolrBasicAuth, AsyncSolrCloudClient + context = SolrServerContext(SolrSingleServerHost('localhost:8983'), SolrBasicAuth('solr', 'SolrRocks')) client = AsyncSolrCloudClient(context) ``` @@ -246,6 +298,8 @@ client = AsyncSolrCloudClient(context) ### Multiple servers ```python +from solrstice import SolrServerContext, SolrMultipleServerHost, SolrBasicAuth, AsyncSolrCloudClient + # The client will randomly select a server to send requests to. It will wait 5 seconds for a response, before trying another server. context = SolrServerContext( SolrMultipleServerHost(["localhost:8983", "localhost:8984"], 5), @@ -257,11 +311,14 @@ client = AsyncSolrCloudClient(context) ### Zookeeper ```python -context = SolrServerContext( - await ZookeeperEnsembleHostConnector(["localhost:2181"], 30).connect(), - SolrBasicAuth('solr', 'SolrRocks'), -) -client = AsyncSolrCloudClient(context) +from solrstice import SolrServerContext, ZookeeperEnsembleHostConnector, SolrBasicAuth, AsyncSolrCloudClient + +async def main(): + context = SolrServerContext( + await ZookeeperEnsembleHostConnector(["localhost:2181"], 30).connect(), + SolrBasicAuth('solr', 'SolrRocks'), + ) + client = AsyncSolrCloudClient(context) ``` ## Notes @@ -272,9 +329,11 @@ client = AsyncSolrCloudClient(context) For example, if you want to create a simpler way to create a client ```python + from typing import Optional + from solrstice import SolrServerContext, SolrSingleServerHost, SolrBasicAuth, AsyncSolrCloudClient, SolrAuth class SolrClient(AsyncSolrCloudClient): def __new__(cls, host: str, auth: Optional[SolrAuth] = None): context = SolrServerContext(SolrSingleServerHost(host), auth) return super().__new__(cls, context=context) - client = SolrClient(config.solr_host, SolrBasicAuth("username", "password")) + client = SolrClient("localhost:8983", SolrBasicAuth("username", "password")) ``` \ No newline at end of file diff --git a/wrappers/python/mypy.ini b/wrappers/python/mypy.ini index 79a8fa0..42f51d7 100644 --- a/wrappers/python/mypy.ini +++ b/wrappers/python/mypy.ini @@ -1,5 +1,5 @@ [mypy] -files=solrstice +files=solrstice,tests warn_unused_configs=True # Dynamic typing diff --git a/wrappers/python/pyrightconfig.json b/wrappers/python/pyrightconfig.json index dd6ab21..2263cbf 100644 --- a/wrappers/python/pyrightconfig.json +++ b/wrappers/python/pyrightconfig.json @@ -1,6 +1,8 @@ { "include": [ - "solrstice" + "solrstice/**/*.py", + "solrstice/**/*.pyi", + "tests/**/*.py" ], "exclude": [ "**/__pycache__" diff --git a/wrappers/python/solrstice/__init__.pyi b/wrappers/python/solrstice/__init__.pyi index 5f44006..a1c4483 100644 --- a/wrappers/python/solrstice/__init__.pyi +++ b/wrappers/python/solrstice/__init__.pyi @@ -2,17 +2,15 @@ import abc from abc import ABC from enum import Enum from os import PathLike -from typing import Optional, List, Dict, Union, TYPE_CHECKING, Any +from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union if TYPE_CHECKING: from solrstice.models import SolrResponse - -#region auth +# region auth class SolrAuth(ABC): """Base class for Solr authentication""" - class SolrBasicAuth(SolrAuth): """Basic authentication for Solr @@ -23,19 +21,16 @@ class SolrBasicAuth(SolrAuth): def __init__(self, username: str, password: Optional[str] = None) -> None: pass +# endregion -#endregion - -#region def_type +# region def_type class QueryOperator(Enum): AND = "AND" OR = "OR" - class DefType(abc.ABC): pass - class LuceneQuery(DefType): """ Create a Lucene query builder. @@ -46,14 +41,13 @@ class LuceneQuery(DefType): """ def __init__( - self, - q_op: Optional[QueryOperator] = None, - df: Optional[str] = None, - sow: Optional[bool] = None, + self, + q_op: Optional[QueryOperator] = None, + df: Optional[str] = None, + sow: Optional[bool] = None, ): pass - class DismaxQuery(DefType): """ Create a DisMax query builder. @@ -70,20 +64,19 @@ class DismaxQuery(DefType): """ def __init__( - self, - q_alt: Optional[str] = None, - qf: Optional[str] = None, - mm: Optional[str] = None, - pf: Optional[str] = None, - ps: Optional[str] = None, - qs: Optional[str] = None, - tie: Optional[str] = None, - bq: Optional[List[str]] = None, - bf: Optional[List[str]] = None, + self, + q_alt: Optional[str] = None, + qf: Optional[str] = None, + mm: Optional[str] = None, + pf: Optional[str] = None, + ps: Optional[str] = None, + qs: Optional[str] = None, + tie: Optional[str] = None, + bq: Optional[List[str]] = None, + bf: Optional[List[str]] = None, ): pass - class EdismaxQuery(DefType): """ Create an Edismax query builder. @@ -110,33 +103,32 @@ class EdismaxQuery(DefType): """ def __init__( - self, - q_alt: Optional[str] = None, - qf: Optional[str] = None, - mm: Optional[str] = None, - mm_auto_relax: Optional[bool] = None, - pf: Optional[str] = None, - pf2: Optional[str] = None, - pf3: Optional[str] = None, - ps: Optional[str] = None, - ps2: Optional[str] = None, - ps3: Optional[str] = None, - qs: Optional[str] = None, - tie: Optional[str] = None, - bq: Optional[List[str]] = None, - bf: Optional[List[str]] = None, - sow: Optional[bool] = None, - boost: Optional[List[str]] = None, - lowercase_operators: Optional[bool] = None, - stopwords: Optional[bool] = None, - uf: Optional[str] = None, + self, + q_alt: Optional[str] = None, + qf: Optional[str] = None, + mm: Optional[str] = None, + mm_auto_relax: Optional[bool] = None, + pf: Optional[str] = None, + pf2: Optional[str] = None, + pf3: Optional[str] = None, + ps: Optional[str] = None, + ps2: Optional[str] = None, + ps3: Optional[str] = None, + qs: Optional[str] = None, + tie: Optional[str] = None, + bq: Optional[List[str]] = None, + bf: Optional[List[str]] = None, + sow: Optional[bool] = None, + boost: Optional[List[str]] = None, + lowercase_operators: Optional[bool] = None, + stopwords: Optional[bool] = None, + uf: Optional[str] = None, ): pass +# endregion -#endregion - -#region facet_set +# region facet_set class FacetSetComponent: """ @@ -148,14 +140,13 @@ class FacetSetComponent: """ def __init__( - self, - queries: Optional[List[str]] = None, - fields: Optional["FieldFacetComponent"] = None, - pivots: Optional["PivotFacetComponent"] = None, + self, + queries: Optional[List[str]] = None, + fields: Optional["FieldFacetComponent"] = None, + pivots: Optional["PivotFacetComponent"] = None, ): pass - class PivotFacetComponent: """ Allows faceting using pivots @@ -164,10 +155,9 @@ class PivotFacetComponent: :param min_count: The minimum count for a facet to be returned """ - def __init__(self, pivots: List[str], min_count: Optional[str]): + def __init__(self, pivots: List[str], min_count: Optional[str] = None): pass - class FieldFacetComponent: """ Allows faceting using fields @@ -177,13 +167,12 @@ class FieldFacetComponent: """ def __init__( - self, - fields: List["FieldFacetEntry"], - exclude_terms: Optional[str] = None, + self, + fields: List["FieldFacetEntry"], + exclude_terms: Optional[str] = None, ): pass - class FieldFacetSort(Enum): """ The sort order for a field facet @@ -192,7 +181,6 @@ class FieldFacetSort(Enum): Count = "Count" Index = "Index" - class FieldFacetMethod(Enum): """ The method for a field facet @@ -202,7 +190,6 @@ class FieldFacetMethod(Enum): Fc = "Fc" Fcs = "Fcs" - class FieldFacetEntry: """ @@ -221,26 +208,25 @@ class FieldFacetEntry: """ def __init__( - self, - field: str, - prefix: Optional[str] = None, - contains: Optional[str] = None, - contains_ignore_case: Optional[bool] = None, - sort: Optional["FieldFacetSort"] = None, - limit: Optional[int] = None, - offset: Optional[int] = None, - min_count: Optional[int] = None, - missing: Optional[bool] = None, - method: Optional["FieldFacetMethod"] = None, - enum_cache_min_df: Optional[int] = None, - exists: Optional[bool] = None, + self, + field: str, + prefix: Optional[str] = None, + contains: Optional[str] = None, + contains_ignore_case: Optional[bool] = None, + sort: Optional["FieldFacetSort"] = None, + limit: Optional[int] = None, + offset: Optional[int] = None, + min_count: Optional[int] = None, + missing: Optional[bool] = None, + method: Optional["FieldFacetMethod"] = None, + enum_cache_min_df: Optional[int] = None, + exists: Optional[bool] = None, ): pass +# endregion -#endregion - -#region json_facet +# region json_facet class JsonFacetComponent: """ @@ -252,11 +238,9 @@ class JsonFacetComponent: def __init__(self, facets: Optional[Dict[str, "JsonFacetType"]] = None): pass - class JsonFacetType(abc.ABC): pass - class JsonTermsFacet(JsonFacetType): """ Do a terms facet on a field @@ -268,16 +252,15 @@ class JsonTermsFacet(JsonFacetType): """ def __init__( - self, - field: str, - offset: Optional[int] = None, - limit: Optional[int] = None, - sort: Optional[str] = None, - facets: Optional[Dict[str, JsonFacetType]] = None, + self, + field: str, + offset: Optional[int] = None, + limit: Optional[int] = None, + sort: Optional[str] = None, + facets: Optional[Dict[str, JsonFacetType]] = None, ): pass - class JsonQueryFacet(JsonFacetType): """ Do a query facet @@ -291,17 +274,16 @@ class JsonQueryFacet(JsonFacetType): """ def __init__( - self, - q: str, - limit: Optional[int] = None, - offset: Optional[int] = None, - sort: Optional[str] = None, - fq: Optional[str] = None, - facets: Optional[Dict[str, JsonFacetType]] = None, + self, + q: str, + limit: Optional[int] = None, + offset: Optional[int] = None, + sort: Optional[str] = None, + fq: Optional[str] = None, + facets: Optional[Dict[str, JsonFacetType]] = None, ): pass - class JsonStatFacet(JsonFacetType): """ Do a stat facet @@ -312,14 +294,12 @@ class JsonStatFacet(JsonFacetType): def __init__(self, query: str): pass +# endregion -#endregion - -#region hosts +# region hosts class SolrHost(ABC): """Base class for Solr hosts""" - class SolrSingleServerHost(SolrHost): """Solr host for a single Solr instance @@ -329,7 +309,6 @@ class SolrSingleServerHost(SolrHost): def __init__(self, host: str) -> None: pass - class SolrMultipleServerHost(SolrHost): """Solr host for multiple solr instances @@ -340,11 +319,9 @@ class SolrMultipleServerHost(SolrHost): def __init__(self, hosts: List[str], timeout: float) -> None: pass - class ZookeeperEnsembleHost(SolrHost): """Zookeeper ensemble connection. Cannot be constructed directly, use ZookeeperEnsembleHostConnector instead""" - class ZookeeperEnsembleHostConnector: """The builder for a Zookeeper ensemble host @@ -363,20 +340,17 @@ class ZookeeperEnsembleHostConnector: """Connect to the Zookeeper ensemble""" pass - class LoggingPolicy(abc.ABC): """Policy describing how to log solr queries. Valid values are :class:`OffLoggingPolicy`, :class:`FastLoggingPolicy`, and :class:`PrettyLoggingPolicy`""" pass - class OffLoggingPolicy(LoggingPolicy): """Do not log requests""" def __init__(self) -> None: pass - class FastLoggingPolicy(LoggingPolicy): """For each request create a logging::DEBUG message with url, headers, and body @@ -386,7 +360,6 @@ class FastLoggingPolicy(LoggingPolicy): def __init__(self, max_body_length: int) -> None: pass - class PrettyLoggingPolicy(LoggingPolicy): """For each request create a logging::DEBUG message with url, headers, and a pretty body @@ -396,7 +369,6 @@ class PrettyLoggingPolicy(LoggingPolicy): def __init__(self, max_body_length: int) -> None: pass - class SolrServerContext: """The context for a connection to a solr instance @@ -406,22 +378,20 @@ class SolrServerContext: """ def __init__( - self, - host: Union[SolrHost, str], - auth: Optional[SolrAuth] = None, - logging_policy: Optional[LoggingPolicy] = None, + self, + host: Union[SolrHost, str], + auth: Optional[SolrAuth] = None, + logging_policy: Optional[LoggingPolicy] = None, ): pass +# endregion -#endregion - -#region group +# region group class GroupFormatting(Enum): Simple = "Simple" Grouped = "Grouped" - class GroupingComponent: """ Grouping component, used in conjunction with SelectQuery @@ -439,24 +409,23 @@ class GroupingComponent: """ def __init__( - self, - fields: Optional[List[str]] = None, - queries: Optional[List[str]] = None, - limit: Optional[int] = None, - offset: Optional[int] = None, - sort: Optional[List[str]] = None, - format: Optional[GroupFormatting] = None, - main: Optional[bool] = None, - n_groups: Optional[bool] = None, - truncate: Optional[bool] = None, - facet: Optional[bool] = None, + self, + fields: Optional[List[str]] = None, + queries: Optional[List[str]] = None, + limit: Optional[int] = None, + offset: Optional[int] = None, + sort: Optional[List[str]] = None, + format: Optional[GroupFormatting] = None, + main: Optional[bool] = None, + n_groups: Optional[bool] = None, + truncate: Optional[bool] = None, + facet: Optional[bool] = None, ): pass +# endregion -#endregion - -#region queries +# region queries class SelectQuery: """Builder for a select query @@ -474,23 +443,23 @@ class SelectQuery: """ def __init__( - self, - q: Optional[str] = None, - fq: Optional[List[str]] = None, - fl: Optional[List[str]] = None, - sort: Optional[List[str]] = None, - rows: Optional[int] = None, - start: Optional[int] = None, - cursor_mark: Optional[str] = None, - grouping: Optional["GroupingComponent"] = None, - def_type: Optional["DefType"] = None, - facet_set: Optional["FacetSetComponent"] = None, - json_facet: Optional["JsonFacetComponent"] = None, + self, + q: Optional[str] = None, + fq: Optional[List[str]] = None, + fl: Optional[List[str]] = None, + sort: Optional[List[str]] = None, + rows: Optional[int] = None, + start: Optional[int] = None, + cursor_mark: Optional[str] = None, + grouping: Optional["GroupingComponent"] = None, + def_type: Optional["DefType"] = None, + facet_set: Optional["FacetSetComponent"] = None, + json_facet: Optional["JsonFacetComponent"] = None, ) -> None: pass async def execute( - self, context: "SolrServerContext", collection: str + self, context: "SolrServerContext", collection: str ) -> "SolrResponse": """Execute the query @@ -499,7 +468,7 @@ class SelectQuery: """ def execute_blocking( - self, context: "SolrServerContext", collection: str + self, context: "SolrServerContext", collection: str ) -> "SolrResponse": """Execute the query @@ -507,12 +476,10 @@ class SelectQuery: :param collection: The collection to query """ - class CommitType(Enum): Hard = ("Hard",) Soft = "Soft" - class UpdateQuery: """Builder for an update query @@ -521,14 +488,14 @@ class UpdateQuery: """ def __init__( - self, - handler: Optional[str] = "update", - commit_type: Optional[CommitType] = CommitType.Hard, + self, + handler: Optional[str] = "update", + commit_type: Optional[CommitType] = CommitType.Hard, ) -> None: pass async def execute( - self, context: "SolrServerContext", collection: str, data: List[Dict[str, Any]] + self, context: "SolrServerContext", collection: str, data: List[Dict[str, Any]] ) -> "SolrResponse": """Execute the query @@ -538,7 +505,7 @@ class UpdateQuery: """ def execute_blocking( - self, context: "SolrServerContext", collection: str, data: List[Dict[str, Any]] + self, context: "SolrServerContext", collection: str, data: List[Dict[str, Any]] ) -> "SolrResponse": """Execute the query @@ -547,7 +514,6 @@ class UpdateQuery: :param data: The data to update """ - class DeleteQuery: """Builder for a delete query @@ -556,16 +522,16 @@ class DeleteQuery: """ def __init__( - self, - handler: Optional[str] = "update", - commit_type: Optional[CommitType] = CommitType.Hard, - ids: Optional[List[str]] = None, - queries: Optional[List[str]] = None, + self, + handler: Optional[str] = "update", + commit_type: Optional[CommitType] = CommitType.Hard, + ids: Optional[List[str]] = None, + queries: Optional[List[str]] = None, ) -> None: pass async def execute( - self, context: "SolrServerContext", collection: str + self, context: "SolrServerContext", collection: str ) -> "SolrResponse": """Execute the query @@ -574,7 +540,7 @@ class DeleteQuery: """ def execute_blocking( - self, context: "SolrServerContext", collection: str + self, context: "SolrServerContext", collection: str ) -> "SolrResponse": """Execute the query @@ -582,10 +548,9 @@ class DeleteQuery: :param collection: The collection to delete from """ +# endregion -#endregion - -#region clients +# region clients class AsyncSolrCloudClient: """ @@ -597,7 +562,9 @@ class AsyncSolrCloudClient: def __init__(self, context: "SolrServerContext"): pass - async def upload_config(self, config_name: str, config_path: Union[PathLike[str], str]) -> None: + async def upload_config( + self, config_name: str, config_path: Union[PathLike[str], str] + ) -> None: """Uploads a Solr config to a Solr instance :param config_name: Name of the config @@ -607,7 +574,6 @@ class AsyncSolrCloudClient: async def get_configs(self) -> List[str]: """Gets a list of Solr configs on a Solr instance""" - pass async def config_exists(self, config_name: str) -> bool: @@ -615,7 +581,6 @@ class AsyncSolrCloudClient: :param config_name: Name of the config """ - pass async def delete_config(self, config_name: str) -> None: @@ -623,15 +588,14 @@ class AsyncSolrCloudClient: :param config_name: Name of the config """ - pass async def create_collection( - self, - name: str, - config: str, - shards: Optional[int] = 1, - replication_factor: Optional[int] = 1, + self, + name: str, + config: str, + shards: Optional[int] = 1, + replication_factor: Optional[int] = 1, ) -> None: """ Create a collection on the Solr server. @@ -701,7 +665,7 @@ class AsyncSolrCloudClient: """ async def index( - self, builder: "UpdateQuery", collection: str, data: List[Dict[str, Any]] + self, builder: "UpdateQuery", collection: str, data: List[Dict[str, Any]] ) -> "SolrResponse": """Execute an index query @@ -717,7 +681,6 @@ class AsyncSolrCloudClient: :param collection: The collection to delete from """ - class BlockingSolrCloudClient: """ A client for interacting with a SolrCloud cluster non-asynchronously. @@ -728,7 +691,9 @@ class BlockingSolrCloudClient: def __init__(self, context: "SolrServerContext"): pass - def upload_config(self, config_name: str, config_path: Union[PathLike[str], str]) -> None: + def upload_config( + self, config_name: str, config_path: Union[PathLike[str], str] + ) -> None: """Uploads a Solr config to a Solr instance :param config_name: Name of the config @@ -738,7 +703,6 @@ class BlockingSolrCloudClient: def get_configs(self) -> List[str]: """Gets a list of Solr configs on a Solr instance""" - pass def config_exists(self, config_name: str) -> bool: @@ -746,7 +710,6 @@ class BlockingSolrCloudClient: :param config_name: Name of the config """ - pass def delete_config(self, config_name: str) -> None: @@ -754,15 +717,14 @@ class BlockingSolrCloudClient: :param config_name: Name of the config """ - pass def create_collection( - self, - name: str, - config: str, - shards: Optional[int] = 1, - replication_factor: Optional[int] = 1, + self, + name: str, + config: str, + shards: Optional[int] = 1, + replication_factor: Optional[int] = 1, ) -> None: """ Create a collection on the Solr server. @@ -834,7 +796,7 @@ class BlockingSolrCloudClient: """ def index( - self, builder: "UpdateQuery", collection: str, data: List[Dict[str, Any]] + self, builder: "UpdateQuery", collection: str, data: List[Dict[str, Any]] ) -> "SolrResponse": """Execute an index query @@ -850,8 +812,7 @@ class BlockingSolrCloudClient: :param collection: The collection to delete from """ - -#endregion +# endregion __all__ = [ "SolrAuth", @@ -861,20 +822,17 @@ __all__ = [ "LuceneQuery", "DismaxQuery", "EdismaxQuery", - "FacetSetComponent", "PivotFacetComponent", "FieldFacetComponent", "FieldFacetSort", "FieldFacetMethod", "FieldFacetEntry", - "JsonFacetComponent", "JsonFacetType", "JsonTermsFacet", "JsonQueryFacet", "JsonStatFacet", - "SolrHost", "SolrSingleServerHost", "SolrMultipleServerHost", @@ -885,15 +843,12 @@ __all__ = [ "FastLoggingPolicy", "PrettyLoggingPolicy", "SolrServerContext", - "GroupFormatting", "GroupingComponent", - "SelectQuery", "CommitType", "UpdateQuery", "DeleteQuery", - "AsyncSolrCloudClient", "BlockingSolrCloudClient", ] diff --git a/wrappers/python/solrstice/alias.pyi b/wrappers/python/solrstice/alias.pyi index dceca0d..21f14e7 100644 --- a/wrappers/python/solrstice/alias.pyi +++ b/wrappers/python/solrstice/alias.pyi @@ -2,9 +2,8 @@ from typing import Dict, List from solrstice import SolrServerContext - async def create_alias( - context: SolrServerContext, name: str, collections: List[str] + context: SolrServerContext, name: str, collections: List[str] ) -> None: """ Create an alias for a collection on the Solr server @@ -14,9 +13,8 @@ async def create_alias( :param collections: The collections to alias """ - def create_alias_blocking( - context: SolrServerContext, name: str, collections: List[str] + context: SolrServerContext, name: str, collections: List[str] ) -> None: """ Create an alias for a collection on the Solr server @@ -26,7 +24,6 @@ def create_alias_blocking( :param collections: The collections to alias """ - async def get_aliases(context: SolrServerContext) -> Dict[str, List[str]]: """ Get all aliases on the Solr server @@ -35,7 +32,6 @@ async def get_aliases(context: SolrServerContext) -> Dict[str, List[str]]: :return: A dictionary of aliases to collections """ - def get_aliases_blocking(context: SolrServerContext) -> Dict[str, List[str]]: """ Get all aliases on the Solr server @@ -44,7 +40,6 @@ def get_aliases_blocking(context: SolrServerContext) -> Dict[str, List[str]]: :return: A dictionary of aliases to collections """ - async def alias_exists(context: SolrServerContext, name: str) -> bool: """ Check if an alias exists on the Solr server @@ -54,7 +49,6 @@ async def alias_exists(context: SolrServerContext, name: str) -> bool: :return: True if the alias exists, False otherwise """ - def alias_exists_blocking(context: SolrServerContext, name: str) -> bool: """ Check if an alias exists on the Solr server @@ -64,7 +58,6 @@ def alias_exists_blocking(context: SolrServerContext, name: str) -> bool: :return: True if the alias exists, False otherwise """ - async def delete_alias(context: SolrServerContext, name: str) -> None: """ Delete an alias from the Solr server @@ -73,7 +66,6 @@ async def delete_alias(context: SolrServerContext, name: str) -> None: :param name: The name of the alias to delete """ - def delete_alias_blocking(context: SolrServerContext, name: str) -> None: """ Delete an alias from the Solr server diff --git a/wrappers/python/solrstice/collection.pyi b/wrappers/python/solrstice/collection.pyi index 8243063..c4ebe27 100644 --- a/wrappers/python/solrstice/collection.pyi +++ b/wrappers/python/solrstice/collection.pyi @@ -2,13 +2,12 @@ from typing import List, Optional from solrstice import SolrServerContext - async def create_collection( - context: SolrServerContext, - name: str, - config: str, - shards: Optional[int] = 1, - replication_factor: Optional[int] = 1, + context: SolrServerContext, + name: str, + config: str, + shards: Optional[int] = 1, + replication_factor: Optional[int] = 1, ) -> None: """ Create a collection on the Solr server. @@ -20,13 +19,12 @@ async def create_collection( :param replication_factor: The replication factor to use. """ - def create_collection_blocking( - context: SolrServerContext, - name: str, - config: str, - shards: Optional[int] = 1, - replication_factor: Optional[int] = 1, + context: SolrServerContext, + name: str, + config: str, + shards: Optional[int] = 1, + replication_factor: Optional[int] = 1, ) -> None: """ Create a collection on the Solr server. @@ -38,7 +36,6 @@ def create_collection_blocking( :param replication_factor: The replication factor to use. """ - async def get_collections(context: SolrServerContext) -> List[str]: """ Get the list of collections on the Solr server. @@ -47,7 +44,6 @@ async def get_collections(context: SolrServerContext) -> List[str]: :return: The list of collections on the Solr server. """ - def get_collections_blocking(context: SolrServerContext) -> List[str]: """ Get the list of collections on the Solr server. @@ -56,7 +52,6 @@ def get_collections_blocking(context: SolrServerContext) -> List[str]: :return: The list of collections on the Solr server. """ - async def collection_exists(context: SolrServerContext, name: str) -> bool: """ Check if a collection exists on the Solr server. @@ -66,7 +61,6 @@ async def collection_exists(context: SolrServerContext, name: str) -> bool: :return: True if the collection exists, False otherwise. """ - def collection_exists_blocking(context: SolrServerContext, name: str) -> bool: """ Check if a collection exists on the Solr server. @@ -76,7 +70,6 @@ def collection_exists_blocking(context: SolrServerContext, name: str) -> bool: :return: True if the collection exists, False otherwise. """ - async def delete_collection(context: SolrServerContext, name: str) -> None: """ Delete a config from the Solr server. @@ -85,7 +78,6 @@ async def delete_collection(context: SolrServerContext, name: str) -> None: :param name: The name of the collection to delete. """ - def delete_collection_blocking(context: SolrServerContext, name: str) -> None: """ Delete a config from the Solr server. diff --git a/wrappers/python/solrstice/config.pyi b/wrappers/python/solrstice/config.pyi index e8dc88e..1e9d7c1 100644 --- a/wrappers/python/solrstice/config.pyi +++ b/wrappers/python/solrstice/config.pyi @@ -8,9 +8,8 @@ if TYPE_CHECKING: else: Somepath = Union[PathLike, str] - async def upload_config( - context: SolrServerContext, config_name: str, config_path: Somepath + context: SolrServerContext, config_name: str, config_path: Somepath ) -> None: """Uploads a Solr config to a Solr instance @@ -20,9 +19,8 @@ async def upload_config( """ pass - def upload_config_blocking( - context: SolrServerContext, config_name: str, config_path: Somepath + context: SolrServerContext, config_name: str, config_path: Somepath ) -> None: """Uploads a Solr config to a Solr instance @@ -32,7 +30,6 @@ def upload_config_blocking( """ pass - async def delete_config(context: SolrServerContext, config_name: str) -> None: """Deletes a Solr config from a Solr instance @@ -41,7 +38,6 @@ async def delete_config(context: SolrServerContext, config_name: str) -> None: """ pass - def delete_config_blocking(context: SolrServerContext, config_name: str) -> None: """Deletes a Solr config from a Solr instance @@ -50,7 +46,6 @@ def delete_config_blocking(context: SolrServerContext, config_name: str) -> None """ pass - async def config_exists(context: SolrServerContext, config_name: str) -> bool: """Checks if a Solr config exists on a Solr instance @@ -59,7 +54,6 @@ async def config_exists(context: SolrServerContext, config_name: str) -> bool: """ pass - def config_exists_blocking(context: SolrServerContext, config_name: str) -> bool: """Checks if a Solr config exists on a Solr instance @@ -68,7 +62,6 @@ def config_exists_blocking(context: SolrServerContext, config_name: str) -> bool """ pass - async def get_configs(context: SolrServerContext) -> List[str]: """Gets a list of Solr configs on a Solr instance @@ -76,7 +69,6 @@ async def get_configs(context: SolrServerContext) -> List[str]: """ pass - def get_configs_blocking(context: SolrServerContext) -> List[str]: """Gets a list of Solr configs on a Solr instance diff --git a/wrappers/python/solrstice/models.pyi b/wrappers/python/solrstice/models.pyi index 17f4375..8566ec4 100644 --- a/wrappers/python/solrstice/models.pyi +++ b/wrappers/python/solrstice/models.pyi @@ -1,6 +1,5 @@ from typing import Any, Dict, List, Optional - class SolrFacetSetResult: """ Gets the facet counts from a query @@ -29,7 +28,6 @@ class SolrFacetSetResult: :return: The field facets """ - class SolrPivotFacetResult: """ Gets the pivot facet counts from a query @@ -61,7 +59,6 @@ class SolrPivotFacetResult: :return: The count of the pivot """ - class SolrFieldFacetResult: def get_key(self) -> Any: """ @@ -77,7 +74,6 @@ class SolrFieldFacetResult: :return: The count of the facet """ - class SolrGroupFieldResult: """ Represents a group field result @@ -95,7 +91,6 @@ class SolrGroupFieldResult: :return: Document response """ - class SolrGroupResult: """ Represents a group result @@ -131,7 +126,6 @@ class SolrGroupResult: :return: Number of groups """ - class SolrJsonFacetResponse: """ A response from a json facet query @@ -167,7 +161,6 @@ class SolrJsonFacetResponse: :return: The value for this facet """ - class SolrDocsResponse: def get_num_found(self) -> int: """Get the number of documents found in the query""" @@ -181,7 +174,6 @@ class SolrDocsResponse: def get_docs(self) -> List[Dict[str, Any]]: """Get the documents from the query""" - class SolrResponse: """The response from a solr query""" diff --git a/wrappers/python/tests/__init__.py b/wrappers/python/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/wrappers/python/tests/helpers.py b/wrappers/python/tests/helpers.py index c35264d..a10eef3 100644 --- a/wrappers/python/tests/helpers.py +++ b/wrappers/python/tests/helpers.py @@ -8,8 +8,14 @@ from dataclasses_json import DataClassJsonMixin, dataclass_json from dotenv import load_dotenv -from solrstice import SolrBasicAuth, SolrServerContext, AsyncSolrCloudClient, SolrSingleServerHost, UpdateQuery -from solrstice.collection import delete_collection, create_collection +from solrstice import ( + AsyncSolrCloudClient, + SolrBasicAuth, + SolrServerContext, + SolrSingleServerHost, + UpdateQuery, +) +from solrstice.collection import create_collection, delete_collection from solrstice.config import delete_config, upload_config @@ -41,6 +47,7 @@ def create_config() -> Config: if solr_username: solr_auth = SolrBasicAuth(solr_username, solr_password) host = os.getenv("SOLR_HOST") + assert host is not None speedbump_host = os.getenv("SPEEDBUMP_HOST") solr_host = SolrSingleServerHost(host) context = SolrServerContext(solr_host, solr_auth) @@ -57,12 +64,12 @@ def create_config() -> Config: ) -def wait_for_solr(host: str, max_time: int): +def wait_for_solr(host: str, max_time: int) -> None: end = time.time() + max_time while time.time() < end: try: with urlopen( - f'{host}{"/solr/admin/collections"}?action=CLUSTERSTATUS' + f'{host}{"/solr/admin/collections"}?action=CLUSTERSTATUS' ) as response: if response.status == 200: return @@ -104,7 +111,7 @@ async def index_test_data(context: SolrServerContext, name: str) -> None: async def setup_collection( - context: SolrServerContext, name: str, config_path: str + context: SolrServerContext, name: str, config_path: str ) -> None: try: await delete_collection(context, name) diff --git a/wrappers/python/tests/test_alias.py b/wrappers/python/tests/test_alias.py index 81b78f7..19468a1 100644 --- a/wrappers/python/tests/test_alias.py +++ b/wrappers/python/tests/test_alias.py @@ -1,5 +1,6 @@ +from typing import Generator + import pytest -from helpers import Config, create_config from solrstice.alias import ( alias_exists, @@ -26,14 +27,16 @@ upload_config_blocking, ) +from .helpers import Config, create_config + @pytest.fixture() -def config() -> Config: +def config() -> Generator[Config, None, None]: yield create_config() @pytest.mark.asyncio -async def test_alias_all_async_functions_exported(config: Config): +async def test_alias_all_async_functions_exported(config: Config) -> None: name = "AliasConfig" functions = [ @@ -63,7 +66,7 @@ async def test_alias_all_async_functions_exported(config: Config): await delete_config(config.context, name) -def test_alias_all_blocking_functions_exported(config: Config): +def test_alias_all_blocking_functions_exported(config: Config) -> None: name = "AliasBlockingConfig" functions = [ diff --git a/wrappers/python/tests/test_clients.py b/wrappers/python/tests/test_clients.py index 890b1bf..9d80c8f 100644 --- a/wrappers/python/tests/test_clients.py +++ b/wrappers/python/tests/test_clients.py @@ -1,20 +1,31 @@ import asyncio +from typing import Generator import pytest -from helpers import Config, create_config from typing_extensions import Optional -from solrstice import AsyncSolrCloudClient, UpdateQuery, SelectQuery, DeleteQuery, BlockingSolrCloudClient, \ - SolrServerContext, SolrSingleServerHost, SolrAuth, SolrBasicAuth +from solrstice import ( + AsyncSolrCloudClient, + BlockingSolrCloudClient, + DeleteQuery, + SelectQuery, + SolrAuth, + SolrBasicAuth, + SolrServerContext, + SolrSingleServerHost, + UpdateQuery, +) + +from .helpers import Config, create_config @pytest.fixture() -def config() -> Config: +def config() -> Generator[Config, None, None]: yield create_config() @pytest.mark.asyncio -async def test_async_client_works(config: Config): +async def test_async_client_works(config: Config) -> None: name = "AsyncClientWorks" client = AsyncSolrCloudClient(config.context) @@ -32,18 +43,20 @@ async def test_async_client_works(config: Config): await client.index(UpdateQuery(), name, [{"id": "example_document"}]) response = await client.select(SelectQuery(fq=["id:example_document"]), name) docs = response.get_docs_response() + assert docs is not None assert docs.get_num_found() == 1 await client.delete(DeleteQuery(ids=["example_document"]), name) response = await client.select(SelectQuery(fq=["id:example_document"]), name) docs = response.get_docs_response() + assert docs is not None assert docs.get_num_found() == 0 await client.delete_collection(name) await client.delete_config(name) -def test_blocking_client_works(config: Config): +def test_blocking_client_works(config: Config) -> None: name = "BlockingClientWorks" client = BlockingSolrCloudClient(config.context) @@ -61,11 +74,13 @@ def test_blocking_client_works(config: Config): client.index(UpdateQuery(), name, [{"id": "example_document"}]) response = client.select(SelectQuery(fq=["id:example_document"]), name) docs = response.get_docs_response() + assert docs is not None assert docs.get_num_found() == 1 client.delete(DeleteQuery(ids=["example_document"]), name) response = client.select(SelectQuery(fq=["id:example_document"]), name) docs = response.get_docs_response() + assert docs is not None assert docs.get_num_found() == 0 client.delete_collection(name) @@ -73,7 +88,7 @@ def test_blocking_client_works(config: Config): @pytest.mark.asyncio -async def test_multiple_clients_works(): +async def test_multiple_clients_works() -> None: name = "MultipleClientWorks" config_1 = create_config() @@ -97,11 +112,11 @@ async def test_multiple_clients_works(): @pytest.mark.asyncio -async def test_subclassing_client_works(): +async def test_subclassing_client_works() -> None: class SolrClient(AsyncSolrCloudClient): - def __new__(cls, host: str, auth: Optional[SolrAuth] = None): + def __new__(cls, host: str, auth: Optional[SolrAuth] = None): # type: ignore context = SolrServerContext(SolrSingleServerHost(host), auth) - return super().__new__(cls, context=context) + return super().__new__(cls, context=context) # type: ignore def test_method(self) -> str: return "test" @@ -111,8 +126,13 @@ def test_method(self) -> str: config = create_config() client = SolrClient( - config.solr_host, SolrBasicAuth(config.solr_username, config.solr_password) - ) + config.solr_host, + ( + SolrBasicAuth(config.solr_username, config.solr_password) + if (config.solr_username and config.solr_password) # type: ignore + else None + ), + ) # type: ignore try: await client.delete_config(name) diff --git a/wrappers/python/tests/test_collection.py b/wrappers/python/tests/test_collection.py index 414eec1..2a3178e 100644 --- a/wrappers/python/tests/test_collection.py +++ b/wrappers/python/tests/test_collection.py @@ -1,5 +1,6 @@ +from typing import Generator + import pytest -from helpers import Config, create_config from solrstice.collection import ( collection_exists, @@ -18,14 +19,16 @@ upload_config_blocking, ) +from .helpers import Config, create_config + @pytest.fixture() -def config() -> Config: +def config() -> Generator[Config, None, None]: yield create_config() @pytest.mark.asyncio -async def test_collection_all_async_functions_exported(config: Config): +async def test_collection_all_async_functions_exported(config: Config) -> None: name = "CollectionConfig" try: @@ -49,7 +52,7 @@ async def test_collection_all_async_functions_exported(config: Config): await delete_config(config.context, name) -def test_collection_all_blocking_functions_exported(config: Config): +def test_collection_all_blocking_functions_exported(config: Config) -> None: name = "CollectionBlockingConfig" try: diff --git a/wrappers/python/tests/test_config.py b/wrappers/python/tests/test_config.py index 2e9880c..45ae941 100644 --- a/wrappers/python/tests/test_config.py +++ b/wrappers/python/tests/test_config.py @@ -1,5 +1,6 @@ +from typing import Generator + import pytest -from helpers import Config, create_config from solrstice.config import ( config_exists, @@ -10,14 +11,16 @@ upload_config_blocking, ) +from .helpers import Config, create_config + @pytest.fixture() -def config() -> Config: +def config() -> Generator[Config, None, None]: yield create_config() @pytest.mark.asyncio -async def test_config_all_async_functions_exported(config: Config): +async def test_config_all_async_functions_exported(config: Config) -> None: try: await delete_config(config.context, "UploadConfig") except RuntimeError: @@ -32,7 +35,7 @@ async def test_config_all_async_functions_exported(config: Config): await delete_config(config.context, "UploadConfig") -def test_config_all_blocking_functions_exported(config: Config): +def test_config_all_blocking_functions_exported(config: Config) -> None: try: delete_config_blocking(config.context, "UploadConfig") except RuntimeError: diff --git a/wrappers/python/tests/test_def_type.py b/wrappers/python/tests/test_def_type.py index b79fbdb..114f635 100644 --- a/wrappers/python/tests/test_def_type.py +++ b/wrappers/python/tests/test_def_type.py @@ -1,5 +1,10 @@ +from typing import Generator + import pytest -from helpers import ( + +from solrstice import DismaxQuery, EdismaxQuery, LuceneQuery, SelectQuery + +from .helpers import ( Config, create_config, index_test_data, @@ -8,17 +13,14 @@ wait_for_solr, ) -from solrstice import DismaxQuery, EdismaxQuery, LuceneQuery -from solrstice import SelectQuery - @pytest.fixture() -def config() -> Config: +def config() -> Generator[Config, None, None]: yield create_config() @pytest.mark.asyncio -async def test_lucene_query_parser(config: Config): +async def test_lucene_query_parser(config: Config) -> None: name = "LuceneQueryParser" wait_for_solr(config.solr_host, 30) @@ -34,7 +36,7 @@ async def test_lucene_query_parser(config: Config): @pytest.mark.asyncio -async def test_dismax_query_parser(config: Config): +async def test_dismax_query_parser(config: Config) -> None: name = "DismaxQueryParser" wait_for_solr(config.solr_host, 30) @@ -47,6 +49,7 @@ async def test_dismax_query_parser(config: Config): response = ( await select_builder.execute(config.context, name) ).get_docs_response() + assert response is not None first_doc = response.get_docs()[0] assert first_doc["id"] == "city_Alta_20" finally: @@ -54,7 +57,7 @@ async def test_dismax_query_parser(config: Config): @pytest.mark.asyncio -async def test_edismax_query_parser(config: Config): +async def test_edismax_query_parser(config: Config) -> None: name = "EdismaxQueryParser" wait_for_solr(config.solr_host, 30) @@ -67,6 +70,7 @@ async def test_edismax_query_parser(config: Config): response = ( await select_builder.execute(config.context, name) ).get_docs_response() + assert response is not None first_doc = response.get_docs()[0] assert first_doc["id"] == "city_Alta_20" finally: diff --git a/wrappers/python/tests/test_facetset.py b/wrappers/python/tests/test_facetset.py index aa5d7d4..771d1fb 100644 --- a/wrappers/python/tests/test_facetset.py +++ b/wrappers/python/tests/test_facetset.py @@ -1,29 +1,32 @@ +from typing import Generator + import pytest -from helpers import ( - Config, - create_config, - index_test_data, - setup_collection, - teardown_collection, - wait_for_solr, -) from solrstice import ( FacetSetComponent, FieldFacetComponent, FieldFacetEntry, PivotFacetComponent, + SelectQuery, +) + +from .helpers import ( + Config, + create_config, + index_test_data, + setup_collection, + teardown_collection, + wait_for_solr, ) -from solrstice import SelectQuery @pytest.fixture() -def config() -> Config: +def config() -> Generator[Config, None, None]: yield create_config() @pytest.mark.asyncio -async def test_facet_pivot_works(config: Config): +async def test_facet_pivot_works(config: Config) -> None: name = "FacetPivot" wait_for_solr(config.solr_host, 30) @@ -36,8 +39,8 @@ async def test_facet_pivot_works(config: Config): select_builder = SelectQuery(facet_set=facet_set) response = await config.async_client.select(select_builder, name) facets = response.get_facet_set() - pivot = facets.get_pivots() - interests_age = pivot.get("interests,age") + pivot_result = facets.get_pivots() + interests_age = pivot_result["interests,age"] cars_pivot = next(p for p in interests_age if p.get_value() == "cars") assert cars_pivot.get_count() == 1 age_pivot = cars_pivot.get_pivots()[0] @@ -47,7 +50,7 @@ async def test_facet_pivot_works(config: Config): @pytest.mark.asyncio -async def test_facet_query_works(config: Config): +async def test_facet_query_works(config: Config) -> None: name = "FacetQuery" wait_for_solr(config.solr_host, 30) @@ -67,7 +70,7 @@ async def test_facet_query_works(config: Config): @pytest.mark.asyncio -async def test_facet_field_works(config: Config): +async def test_facet_field_works(config: Config) -> None: name = "FacetField" wait_for_solr(config.solr_host, 30) @@ -80,8 +83,8 @@ async def test_facet_field_works(config: Config): select_builder = SelectQuery(facet_set=facet_set) response = await config.async_client.select(select_builder, name) facets = response.get_facet_set() - fields = facets.get_fields() - age = fields.get("age") + fields_result = facets.get_fields() + age = fields_result["age"] assert len(age) == 3 finally: await teardown_collection(config.context, name) diff --git a/wrappers/python/tests/test_group.py b/wrappers/python/tests/test_group.py index e9d90af..d619827 100644 --- a/wrappers/python/tests/test_group.py +++ b/wrappers/python/tests/test_group.py @@ -1,5 +1,10 @@ +from typing import Generator + import pytest -from helpers import ( + +from solrstice import GroupingComponent, SelectQuery + +from .helpers import ( Config, create_config, index_test_data, @@ -8,17 +13,14 @@ wait_for_solr, ) -from solrstice import GroupingComponent -from solrstice import SelectQuery - @pytest.fixture() -def config() -> Config: +def config() -> Generator[Config, None, None]: yield create_config() @pytest.mark.asyncio -async def test_get_group_field_result_works(config: Config): +async def test_get_group_field_result_works(config: Config) -> None: name = "GroupFieldQuery" wait_for_solr(config.solr_host, 30) @@ -31,6 +33,7 @@ async def test_get_group_field_result_works(config: Config): groups = (await select_builder.execute(config.context, name)).get_groups() age_group = groups["age"] group = age_group.get_field_result() + assert group is not None assert age_group.get_n_groups() is None assert age_group.get_matches() > 0 assert len(group) > 0 @@ -39,7 +42,7 @@ async def test_get_group_field_result_works(config: Config): @pytest.mark.asyncio -async def test_get_group_query_result_works(config: Config): +async def test_get_group_query_result_works(config: Config) -> None: name = "GroupQueryQuery" wait_for_solr(config.solr_host, 30) @@ -54,6 +57,7 @@ async def test_get_group_query_result_works(config: Config): groups = (await select_builder.execute(config.context, name)).get_groups() age_group = groups["age:[0 TO 59]"] group = age_group.get_query_result() + assert group is not None assert len(group.get_docs()) > 0 finally: await teardown_collection(config.context, name) diff --git a/wrappers/python/tests/test_hosts.py b/wrappers/python/tests/test_hosts.py index 14cef7f..2a4d43a 100644 --- a/wrappers/python/tests/test_hosts.py +++ b/wrappers/python/tests/test_hosts.py @@ -1,20 +1,21 @@ import os from dataclasses import dataclass from pathlib import Path -from typing import Optional +from typing import Generator, Optional import pytest from dotenv import load_dotenv -from helpers import wait_for_solr -from solrstice import SolrBasicAuth -from solrstice.config import get_configs, get_configs_blocking from solrstice import ( + SolrBasicAuth, SolrMultipleServerHost, SolrServerContext, SolrSingleServerHost, ZookeeperEnsembleHostConnector, ) +from solrstice.config import get_configs, get_configs_blocking + +from .helpers import wait_for_solr @dataclass @@ -25,22 +26,28 @@ class Config: @pytest.fixture() -def config() -> Config: +def config() -> Generator[Config, None, None]: path = Path("../../test_setup/.env").resolve() load_dotenv(path) solr_auth = None - if os.getenv("SOLR_USERNAME") is not None and os.getenv("SOLR_PASSWORD") is not "": + solr_username = os.getenv("SOLR_USERNAME") + solr_password = os.getenv("SOLR_PASSWORD") + + if solr_username is not None and solr_password is not "": solr_auth = SolrBasicAuth( - os.getenv("SOLR_USERNAME"), - os.getenv("SOLR_PASSWORD"), + solr_username, + solr_password, ) host = os.getenv("SOLR_HOST") + assert host is not None + zookeeper_host = os.getenv("ZK_HOST") + assert zookeeper_host is not None - yield Config(host, os.getenv("ZK_HOST"), solr_auth) + yield Config(host, zookeeper_host, solr_auth) @pytest.mark.asyncio -async def test_zookeeper_connection_works(config: Config): +async def test_zookeeper_connection_works(config: Config) -> None: wait_for_solr(config.host, 30) context = SolrServerContext( await ZookeeperEnsembleHostConnector([config.zookeeper_host], 30).connect(), @@ -49,7 +56,7 @@ async def test_zookeeper_connection_works(config: Config): await get_configs(context) -def test_zookeeper_connection_works_blocking(config: Config): +def test_zookeeper_connection_works_blocking(config: Config) -> None: wait_for_solr(config.host, 30) context = SolrServerContext( ZookeeperEnsembleHostConnector([config.zookeeper_host], 30).connect_blocking(), @@ -59,27 +66,27 @@ def test_zookeeper_connection_works_blocking(config: Config): @pytest.mark.asyncio -async def test_solr_single_server_works(config: Config): +async def test_solr_single_server_works(config: Config) -> None: wait_for_solr(config.host, 30) context = SolrServerContext(SolrSingleServerHost(config.host), config.auth) await get_configs(context) @pytest.mark.asyncio -async def test_solr_single_server_works_with_string(config: Config): +async def test_solr_single_server_works_with_string(config: Config) -> None: wait_for_solr(config.host, 30) context = SolrServerContext(config.host, config.auth) await get_configs(context) @pytest.mark.asyncio -async def test_multiple_server_works(config: Config): +async def test_multiple_server_works(config: Config) -> None: wait_for_solr(config.host, 30) context = SolrServerContext(SolrMultipleServerHost([config.host], 5), config.auth) await get_configs(context) -def test_solr_multiple_server_works_blocking(config: Config): +def test_solr_multiple_server_works_blocking(config: Config) -> None: wait_for_solr(config.host, 30) context = SolrServerContext(SolrMultipleServerHost([config.host], 5), config.auth) get_configs_blocking(context) diff --git a/wrappers/python/tests/test_index.py b/wrappers/python/tests/test_index.py index 961227b..0dcd28b 100644 --- a/wrappers/python/tests/test_index.py +++ b/wrappers/python/tests/test_index.py @@ -1,5 +1,10 @@ +from typing import Generator + import pytest -from helpers import ( + +from solrstice import CommitType, UpdateQuery + +from .helpers import ( Config, create_config, setup_collection, @@ -7,16 +12,14 @@ wait_for_solr, ) -from solrstice import CommitType, UpdateQuery - @pytest.fixture() -def config() -> Config: +def config() -> Generator[Config, None, None]: yield create_config() @pytest.mark.asyncio -async def test_index_indexes_documents(config: Config): +async def test_index_indexes_documents(config: Config) -> None: name = "IndexIndexesDocuments" wait_for_solr(config.solr_host, 30) diff --git a/wrappers/python/tests/test_json_facet.py b/wrappers/python/tests/test_json_facet.py index cbab630..d11d31b 100644 --- a/wrappers/python/tests/test_json_facet.py +++ b/wrappers/python/tests/test_json_facet.py @@ -1,29 +1,32 @@ +from typing import Generator + import pytest -from helpers import ( - Config, - create_config, - index_test_data, - setup_collection, - teardown_collection, - wait_for_solr, -) from solrstice import ( JsonFacetComponent, JsonQueryFacet, JsonStatFacet, JsonTermsFacet, + SelectQuery, +) + +from .helpers import ( + Config, + create_config, + index_test_data, + setup_collection, + teardown_collection, + wait_for_solr, ) -from solrstice import SelectQuery @pytest.fixture() -def config() -> Config: +def config() -> Generator[Config, None, None]: yield create_config() @pytest.mark.asyncio -async def test_json_query_facet_works(config: Config): +async def test_json_query_facet_works(config: Config) -> None: name = "JsonQueryFacet" wait_for_solr(config.solr_host, 30) @@ -38,14 +41,15 @@ async def test_json_query_facet_works(config: Config): ) response = await config.async_client.select(select_builder, name) facets = response.get_json_facets() - below_60 = facets.get_nested_facets().get("below_60") + assert facets is not None + below_60 = facets.get_nested_facets()["below_60"] assert below_60.get_count() == 4 finally: await teardown_collection(config.context, name) @pytest.mark.asyncio -async def test_json_terms_facet_works(config: Config): +async def test_json_terms_facet_works(config: Config) -> None: name = "JsonTermsFacet" wait_for_solr(config.solr_host, 30) @@ -58,14 +62,15 @@ async def test_json_terms_facet_works(config: Config): ) response = await config.async_client.select(select_builder, name) facets = response.get_json_facets() - age_buckets = facets.get_nested_facets().get("age").get_buckets() + assert facets is not None + age_buckets = facets.get_nested_facets()["age"].get_buckets() assert len(age_buckets) == 3 finally: await teardown_collection(config.context, name) @pytest.mark.asyncio -async def test_json_stat_facet_works(config: Config): +async def test_json_stat_facet_works(config: Config) -> None: name = "JsonStatFacet" wait_for_solr(config.solr_host, 30) @@ -80,14 +85,15 @@ async def test_json_stat_facet_works(config: Config): ) response = await config.async_client.select(select_builder, name) facets = response.get_json_facets() - total_people = facets.get_flat_facets().get("total_people") + assert facets is not None + total_people = facets.get_flat_facets()["total_people"] assert total_people == 1000 finally: await teardown_collection(config.context, name) @pytest.mark.asyncio -async def test_json_facet_sub_works(config: Config): +async def test_json_facet_sub_works(config: Config) -> None: name = "JsonFacetSub" wait_for_solr(config.solr_host, 30) @@ -107,12 +113,10 @@ async def test_json_facet_sub_works(config: Config): ) response = await config.async_client.select(select_builder, name) facets = response.get_json_facets() - total_people = ( - facets.get_nested_facets() - .get("below_60") - .get_flat_facets() - .get("total_people") - ) + assert facets is not None + total_people = facets.get_nested_facets()["below_60"].get_flat_facets()[ + "total_people" + ] assert total_people == 750.0 finally: await teardown_collection(config.context, name) diff --git a/wrappers/python/tests/test_latency.py b/wrappers/python/tests/test_latency.py index e57990d..9afc8bb 100644 --- a/wrappers/python/tests/test_latency.py +++ b/wrappers/python/tests/test_latency.py @@ -2,22 +2,27 @@ import asyncio import time from multiprocessing.pool import ThreadPool -from typing import Optional +from typing import Generator, List, Optional import pytest -from helpers import Config, create_config -from solrstice import SolrBasicAuth -from solrstice import AsyncSolrCloudClient, BlockingSolrCloudClient -from solrstice import SolrServerContext, SolrSingleServerHost +from solrstice import ( + AsyncSolrCloudClient, + BlockingSolrCloudClient, + SolrBasicAuth, + SolrServerContext, + SolrSingleServerHost, +) + +from .helpers import Config, create_config @pytest.fixture() -def config() -> Config: +def config() -> Generator[Config, None, None]: yield create_config() -def test_blocking_client_does_not_block_gil_config(config: Config): +def test_blocking_client_does_not_block_gil_config(config: Config) -> None: processes = 8 if not config.speedbump_host: pytest.skip("No speedbump host configured") @@ -39,7 +44,7 @@ def test_blocking_client_does_not_block_gil_config(config: Config): @pytest.mark.asyncio -async def test_async_client_does_not_block_event_loop(config: Config): +async def test_async_client_does_not_block_event_loop(config: Config) -> None: processes = 8 if not config.speedbump_host: pytest.skip("No speedbump host configured") @@ -58,7 +63,9 @@ async def test_async_client_does_not_block_event_loop(config: Config): assert elapsed_seconds < processes -def get_configs_blocking(host: str, username: Optional[str], password: Optional[str]): +def get_configs_blocking( + host: str, username: Optional[str], password: Optional[str] +) -> List[str]: auth = None if not username else SolrBasicAuth(username, password) client = BlockingSolrCloudClient( SolrServerContext(SolrSingleServerHost(host), auth) @@ -67,8 +74,8 @@ def get_configs_blocking(host: str, username: Optional[str], password: Optional[ async def get_configs_async( - host: str, username: Optional[str], password: Optional[str] -): + host: str, username: Optional[str], password: Optional[str] +) -> List[str]: auth = None if not username else SolrBasicAuth(username, password) client = AsyncSolrCloudClient(SolrServerContext(SolrSingleServerHost(host), auth)) return await client.get_configs() diff --git a/wrappers/python/tests/test_logging.py b/wrappers/python/tests/test_logging.py index ee8cbb0..53568ad 100644 --- a/wrappers/python/tests/test_logging.py +++ b/wrappers/python/tests/test_logging.py @@ -1,15 +1,16 @@ import logging +from typing import Generator import pytest from _pytest.logging import LogCaptureFixture -from helpers import Config, create_config, wait_for_solr -from solrstice import AsyncSolrCloudClient -from solrstice import OffLoggingPolicy, SolrServerContext +from solrstice import AsyncSolrCloudClient, OffLoggingPolicy, SolrServerContext + +from .helpers import Config, create_config, wait_for_solr @pytest.fixture() -def config() -> Config: +def config() -> Generator[Config, None, None]: yield create_config() @@ -30,8 +31,8 @@ def config() -> Config: @pytest.mark.asyncio async def test_logging_does_not_log_message_if_disabled( - config: Config, caplog: LogCaptureFixture -): + config: Config, caplog: LogCaptureFixture +) -> None: wait_for_solr(config.solr_host, 30) context = SolrServerContext(config.solr_host, config.solr_auth, OffLoggingPolicy()) diff --git a/wrappers/python/tests/test_multiprocessing.py b/wrappers/python/tests/test_multiprocessing.py index ca2771b..52b14a7 100644 --- a/wrappers/python/tests/test_multiprocessing.py +++ b/wrappers/python/tests/test_multiprocessing.py @@ -1,19 +1,23 @@ import dataclasses import random from multiprocessing.pool import ThreadPool -from typing import Optional +from typing import Generator, Optional import pytest -from helpers import Config, create_config -from solrstice import SolrBasicAuth -from solrstice import BlockingSolrCloudClient -from solrstice import SolrServerContext, SolrSingleServerHost -from solrstice import UpdateQuery +from solrstice import ( + BlockingSolrCloudClient, + SolrBasicAuth, + SolrServerContext, + SolrSingleServerHost, + UpdateQuery, +) + +from .helpers import Config, create_config @pytest.fixture() -def config() -> Config: +def config() -> Generator[Config, None, None]: yield create_config() @@ -24,7 +28,7 @@ class PickableConfig: solr_password: Optional[str] -def create_client(config: PickableConfig): +def create_client(config: PickableConfig) -> BlockingSolrCloudClient: auth = ( None if not config.solr_username @@ -35,7 +39,7 @@ def create_client(config: PickableConfig): ) -def index_independent(config: PickableConfig, collection_name): +def index_independent(config: PickableConfig, collection_name: str) -> None: client = create_client(config) client.index( UpdateQuery(), @@ -76,7 +80,7 @@ def index_independent(config: PickableConfig, collection_name): # pass -def test_blocking_multithreading_works(config: Config): +def test_blocking_multithreading_works(config: Config) -> None: name = "BlockingMultithreadingWorks" pickable_config = PickableConfig( diff --git a/wrappers/python/tests/test_pickle.py b/wrappers/python/tests/test_pickle.py index 7410407..02bfb2b 100644 --- a/wrappers/python/tests/test_pickle.py +++ b/wrappers/python/tests/test_pickle.py @@ -1,10 +1,15 @@ import pickle -from solrstice import GroupingComponent -from solrstice import CommitType, DeleteQuery, SelectQuery, UpdateQuery +from solrstice import ( + CommitType, + DeleteQuery, + GroupingComponent, + SelectQuery, + UpdateQuery, +) -def test_pickle_works_select_query_builder(): +def test_pickle_works_select_query_builder() -> None: builder = SelectQuery( fq=["test", "test"], grouping=GroupingComponent(fields=["test"], main=True, facet=False), @@ -14,14 +19,14 @@ def test_pickle_works_select_query_builder(): assert pickle.dumps(builder_copy) == string -def test_pickle_works_update_query_builder(): +def test_pickle_works_update_query_builder() -> None: builder = UpdateQuery(handler="test", commit_type=CommitType.Soft) string = pickle.dumps(builder) builder_copy: UpdateQuery = pickle.loads(string) assert pickle.dumps(builder_copy) == string -def test_pickle_works_delete_query_builder(): +def test_pickle_works_delete_query_builder() -> None: builder = DeleteQuery() string = pickle.dumps(builder) builder_copy: DeleteQuery = pickle.loads(string) diff --git a/wrappers/python/tests/test_select.py b/wrappers/python/tests/test_select.py index 3a60943..2ba9dd7 100644 --- a/wrappers/python/tests/test_select.py +++ b/wrappers/python/tests/test_select.py @@ -1,5 +1,10 @@ +from typing import Generator + import pytest -from helpers import ( + +from solrstice import SelectQuery + +from .helpers import ( Config, create_config, index_test_data, @@ -8,16 +13,14 @@ wait_for_solr, ) -from solrstice import SelectQuery - @pytest.fixture() -def config() -> Config: +def config() -> Generator[Config, None, None]: yield create_config() @pytest.mark.asyncio -async def test_get_response_gets_response(config: Config): +async def test_get_response_gets_response(config: Config) -> None: name = "SelectGetResponse" wait_for_solr(config.solr_host, 30) @@ -29,6 +32,7 @@ async def test_get_response_gets_response(config: Config): builder = SelectQuery() solr_response = await builder.execute(config.context, name) docs_response = solr_response.get_docs_response() + assert docs_response is not None assert docs_response.get_num_found() > 0 assert docs_response.get_start() == 0 assert len(docs_response.get_docs()) > 4 @@ -37,7 +41,7 @@ async def test_get_response_gets_response(config: Config): @pytest.mark.asyncio -async def test_select_works_when_no_result(config: Config): +async def test_select_works_when_no_result(config: Config) -> None: name = "SelectNoResult" wait_for_solr(config.solr_host, 30) @@ -49,6 +53,7 @@ async def test_select_works_when_no_result(config: Config): builder = SelectQuery(fq=["id:non_existent_id"]) solr_response = await builder.execute(config.context, name) docs_response = solr_response.get_docs_response() + assert docs_response is not None assert docs_response.get_num_found() == 0 assert docs_response.get_start() == 0 assert len(docs_response.get_docs()) == 0 @@ -57,7 +62,7 @@ async def test_select_works_when_no_result(config: Config): @pytest.mark.asyncio -async def test_select_works_with_cursor_mark(config: Config): +async def test_select_works_with_cursor_mark(config: Config) -> None: name = "SelectCursorMark" wait_for_solr(config.solr_host, 30) @@ -76,7 +81,7 @@ async def test_select_works_with_cursor_mark(config: Config): if result.get_next_cursor_mark() is not None: if cursor_mark == "*": break - cursor_mark = result.get_next_cursor_mark() + cursor_mark = result.get_next_cursor_mark() # type: ignore else: raise Exception("Cursor mark test failed. No next cursor mark") current_iteration += 1 From 016534a311cb2d4752e6dd6bc46d6f5a277c854c Mon Sep 17 00:00:00 2001 From: Sh1nku <42642351+Sh1nku@users.noreply.github.com> Date: Fri, 26 Jul 2024 13:43:29 +0200 Subject: [PATCH 4/5] Remove python pdoc documentation --- .github/workflows/generate_docs.yml | 7 ----- .github/workflows/publish_docs.yml | 7 ----- README.md | 2 +- docs/src/index.md | 2 +- wrappers/python/README.md | 1 - wrappers/python/generate_documentation.py | 31 ---------------------- wrappers/python/solrstice/alias.pyi | 32 ++++++++++++++++------- wrappers/python/solrstice/collection.pyi | 32 ++++++++++++++++------- wrappers/python/solrstice/config.pyi | 31 +++++++++++++++------- wrappers/python/solrstice/models.pyi | 19 +++++++++++--- wrappers/python/src/queries/alias.rs | 2 +- wrappers/python/src/queries/collection.rs | 2 +- wrappers/python/src/queries/config.rs | 2 +- 13 files changed, 85 insertions(+), 85 deletions(-) delete mode 100755 wrappers/python/generate_documentation.py diff --git a/.github/workflows/generate_docs.yml b/.github/workflows/generate_docs.yml index 8783071..1b877ac 100644 --- a/.github/workflows/generate_docs.yml +++ b/.github/workflows/generate_docs.yml @@ -29,10 +29,3 @@ jobs: - uses: actions/setup-python@v4 with: python-version: 3.8 - - name: Build Python documentation - working-directory: ./wrappers/python - run: | - pip install -r requirements-dev.txt - ./generate_documentation.py - mkdir ../../docs/docs_built/python - mv docs/* ../../docs/docs_built/python diff --git a/.github/workflows/publish_docs.yml b/.github/workflows/publish_docs.yml index 6037925..75cf0ac 100644 --- a/.github/workflows/publish_docs.yml +++ b/.github/workflows/publish_docs.yml @@ -38,13 +38,6 @@ jobs: - uses: actions/setup-python@v4 with: python-version: 3.8 - - name: Build Python documentation - working-directory: ./wrappers/python - run: | - pip install -r requirements-dev.txt - ./generate_documentation.py - mkdir ../../docs/docs_built/python - mv docs/* ../../docs/docs_built/python - name: Upload artifact uses: actions/upload-pages-artifact@v2 with: diff --git a/README.md b/README.md index 92db2ae..740d437 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Solrstice is a SolrCloud aware client library written in rust. It also provides a wrapper to python. Use the [Rust documentation](https://docs.rs/solrstice) or -the [Python documentation](https://sh1nku.github.io/solrstice/python) for more information. +the [Python documentation](https://pypi.org/project/solrstice/) for more information. ## Features diff --git a/docs/src/index.md b/docs/src/index.md index 5fa07cc..377dfcb 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -17,7 +17,7 @@ If the `blocking` feature is not provided, only async will work. ```bash pip install solrstice ``` -* [Python docs](https://sh1nku.github.io/solrstice/python) +* [Python docs](https://pypi.org/project/solrstice/) ## Getting started diff --git a/wrappers/python/README.md b/wrappers/python/README.md index 57e2daf..d767557 100644 --- a/wrappers/python/README.md +++ b/wrappers/python/README.md @@ -3,7 +3,6 @@ Solrstice is a solr client library written in rust. With this wrapper you can use it in python. Both asyncio and blocking clients are provided. All apis have type hints. -Documentation can be found at [sh1nku.github.io/solrstice/python](https://sh1nku.github.io/solrstice/python) ## Features diff --git a/wrappers/python/generate_documentation.py b/wrappers/python/generate_documentation.py deleted file mode 100755 index 677cb56..0000000 --- a/wrappers/python/generate_documentation.py +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- - -import os -import shutil -import tempfile -from pathlib import Path - -import pdoc - -if __name__ == '__main__': - tmpdir = tempfile.TemporaryDirectory() - package_name = 'solrstice' - package_path = os.path.join(tmpdir.name, package_name) - current_directory = os.path.dirname(os.path.realpath(__file__)) - docs_directory = Path(os.path.join(Path(current_directory), 'docs')) - - os.mkdir(package_path) - for filename in os.listdir(package_name): - f = os.path.join(package_name, filename) - if os.path.isfile(f) and filename.endswith('.pyi'): - shutil.copyfile(f, os.path.join(package_path, filename[:-1])) - shutil.copyfile('README.md', os.path.join(tmpdir.name, 'README.md')) - with open(os.path.join(package_path, '__init__.py'), 'w') as f: - f.write(''' -""" -.. include:: ../README.md -""" - ''') - - pdoc.pdoc(os.path.join(tmpdir.name, package_name), output_directory=docs_directory) diff --git a/wrappers/python/solrstice/alias.pyi b/wrappers/python/solrstice/alias.pyi index 21f14e7..dd79e2c 100644 --- a/wrappers/python/solrstice/alias.pyi +++ b/wrappers/python/solrstice/alias.pyi @@ -1,9 +1,10 @@ -from typing import Dict, List +from typing import TYPE_CHECKING, Dict, List -from solrstice import SolrServerContext +if TYPE_CHECKING: + from solrstice import SolrServerContext async def create_alias( - context: SolrServerContext, name: str, collections: List[str] + context: "SolrServerContext", name: str, collections: List[str] ) -> None: """ Create an alias for a collection on the Solr server @@ -14,7 +15,7 @@ async def create_alias( """ def create_alias_blocking( - context: SolrServerContext, name: str, collections: List[str] + context: "SolrServerContext", name: str, collections: List[str] ) -> None: """ Create an alias for a collection on the Solr server @@ -24,7 +25,7 @@ def create_alias_blocking( :param collections: The collections to alias """ -async def get_aliases(context: SolrServerContext) -> Dict[str, List[str]]: +async def get_aliases(context: "SolrServerContext") -> Dict[str, List[str]]: """ Get all aliases on the Solr server @@ -32,7 +33,7 @@ async def get_aliases(context: SolrServerContext) -> Dict[str, List[str]]: :return: A dictionary of aliases to collections """ -def get_aliases_blocking(context: SolrServerContext) -> Dict[str, List[str]]: +def get_aliases_blocking(context: "SolrServerContext") -> Dict[str, List[str]]: """ Get all aliases on the Solr server @@ -40,7 +41,7 @@ def get_aliases_blocking(context: SolrServerContext) -> Dict[str, List[str]]: :return: A dictionary of aliases to collections """ -async def alias_exists(context: SolrServerContext, name: str) -> bool: +async def alias_exists(context: "SolrServerContext", name: str) -> bool: """ Check if an alias exists on the Solr server @@ -49,7 +50,7 @@ async def alias_exists(context: SolrServerContext, name: str) -> bool: :return: True if the alias exists, False otherwise """ -def alias_exists_blocking(context: SolrServerContext, name: str) -> bool: +def alias_exists_blocking(context: "SolrServerContext", name: str) -> bool: """ Check if an alias exists on the Solr server @@ -58,7 +59,7 @@ def alias_exists_blocking(context: SolrServerContext, name: str) -> bool: :return: True if the alias exists, False otherwise """ -async def delete_alias(context: SolrServerContext, name: str) -> None: +async def delete_alias(context: "SolrServerContext", name: str) -> None: """ Delete an alias from the Solr server @@ -66,10 +67,21 @@ async def delete_alias(context: SolrServerContext, name: str) -> None: :param name: The name of the alias to delete """ -def delete_alias_blocking(context: SolrServerContext, name: str) -> None: +def delete_alias_blocking(context: "SolrServerContext", name: str) -> None: """ Delete an alias from the Solr server :param context: The Solr server context :param name: The name of the alias to delete """ + +__all__ = [ + "create_alias", + "create_alias_blocking", + "get_aliases", + "get_aliases_blocking", + "alias_exists", + "alias_exists_blocking", + "delete_alias", + "delete_alias_blocking", +] diff --git a/wrappers/python/solrstice/collection.pyi b/wrappers/python/solrstice/collection.pyi index c4ebe27..d086dd4 100644 --- a/wrappers/python/solrstice/collection.pyi +++ b/wrappers/python/solrstice/collection.pyi @@ -1,9 +1,10 @@ -from typing import List, Optional +from typing import TYPE_CHECKING, List, Optional -from solrstice import SolrServerContext +if TYPE_CHECKING: + from solrstice import SolrServerContext async def create_collection( - context: SolrServerContext, + context: "SolrServerContext", name: str, config: str, shards: Optional[int] = 1, @@ -20,7 +21,7 @@ async def create_collection( """ def create_collection_blocking( - context: SolrServerContext, + context: "SolrServerContext", name: str, config: str, shards: Optional[int] = 1, @@ -36,7 +37,7 @@ def create_collection_blocking( :param replication_factor: The replication factor to use. """ -async def get_collections(context: SolrServerContext) -> List[str]: +async def get_collections(context: "SolrServerContext") -> List[str]: """ Get the list of collections on the Solr server. @@ -44,7 +45,7 @@ async def get_collections(context: SolrServerContext) -> List[str]: :return: The list of collections on the Solr server. """ -def get_collections_blocking(context: SolrServerContext) -> List[str]: +def get_collections_blocking(context: "SolrServerContext") -> List[str]: """ Get the list of collections on the Solr server. @@ -52,7 +53,7 @@ def get_collections_blocking(context: SolrServerContext) -> List[str]: :return: The list of collections on the Solr server. """ -async def collection_exists(context: SolrServerContext, name: str) -> bool: +async def collection_exists(context: "SolrServerContext", name: str) -> bool: """ Check if a collection exists on the Solr server. @@ -61,7 +62,7 @@ async def collection_exists(context: SolrServerContext, name: str) -> bool: :return: True if the collection exists, False otherwise. """ -def collection_exists_blocking(context: SolrServerContext, name: str) -> bool: +def collection_exists_blocking(context: "SolrServerContext", name: str) -> bool: """ Check if a collection exists on the Solr server. @@ -70,7 +71,7 @@ def collection_exists_blocking(context: SolrServerContext, name: str) -> bool: :return: True if the collection exists, False otherwise. """ -async def delete_collection(context: SolrServerContext, name: str) -> None: +async def delete_collection(context: "SolrServerContext", name: str) -> None: """ Delete a config from the Solr server. @@ -78,10 +79,21 @@ async def delete_collection(context: SolrServerContext, name: str) -> None: :param name: The name of the collection to delete. """ -def delete_collection_blocking(context: SolrServerContext, name: str) -> None: +def delete_collection_blocking(context: "SolrServerContext", name: str) -> None: """ Delete a config from the Solr server. :param context: The Solr server context. :param name: The name of the collection to delete. """ + +__all__ = [ + "create_collection", + "create_collection_blocking", + "get_collections", + "get_collections_blocking", + "collection_exists", + "collection_exists_blocking", + "delete_collection", + "delete_collection_blocking", +] diff --git a/wrappers/python/solrstice/config.pyi b/wrappers/python/solrstice/config.pyi index 1e9d7c1..61b5f20 100644 --- a/wrappers/python/solrstice/config.pyi +++ b/wrappers/python/solrstice/config.pyi @@ -1,15 +1,15 @@ from os import PathLike from typing import TYPE_CHECKING, List, Union -from solrstice import SolrServerContext - if TYPE_CHECKING: + from solrstice import SolrServerContext + Somepath = Union[PathLike[str], str] else: Somepath = Union[PathLike, str] async def upload_config( - context: SolrServerContext, config_name: str, config_path: Somepath + context: "SolrServerContext", config_name: str, config_path: Somepath ) -> None: """Uploads a Solr config to a Solr instance @@ -20,7 +20,7 @@ async def upload_config( pass def upload_config_blocking( - context: SolrServerContext, config_name: str, config_path: Somepath + context: "SolrServerContext", config_name: str, config_path: Somepath ) -> None: """Uploads a Solr config to a Solr instance @@ -30,7 +30,7 @@ def upload_config_blocking( """ pass -async def delete_config(context: SolrServerContext, config_name: str) -> None: +async def delete_config(context: "SolrServerContext", config_name: str) -> None: """Deletes a Solr config from a Solr instance :param context: SolrServerRequest context @@ -38,7 +38,7 @@ async def delete_config(context: SolrServerContext, config_name: str) -> None: """ pass -def delete_config_blocking(context: SolrServerContext, config_name: str) -> None: +def delete_config_blocking(context: "SolrServerContext", config_name: str) -> None: """Deletes a Solr config from a Solr instance :param context: SolrServerRequest context @@ -46,7 +46,7 @@ def delete_config_blocking(context: SolrServerContext, config_name: str) -> None """ pass -async def config_exists(context: SolrServerContext, config_name: str) -> bool: +async def config_exists(context: "SolrServerContext", config_name: str) -> bool: """Checks if a Solr config exists on a Solr instance :param context: SolrServerRequest context @@ -54,7 +54,7 @@ async def config_exists(context: SolrServerContext, config_name: str) -> bool: """ pass -def config_exists_blocking(context: SolrServerContext, config_name: str) -> bool: +def config_exists_blocking(context: "SolrServerContext", config_name: str) -> bool: """Checks if a Solr config exists on a Solr instance :param context: SolrServerRequest context @@ -62,16 +62,27 @@ def config_exists_blocking(context: SolrServerContext, config_name: str) -> bool """ pass -async def get_configs(context: SolrServerContext) -> List[str]: +async def get_configs(context: "SolrServerContext") -> List[str]: """Gets a list of Solr configs on a Solr instance :param context: SolrServerRequest context """ pass -def get_configs_blocking(context: SolrServerContext) -> List[str]: +def get_configs_blocking(context: "SolrServerContext") -> List[str]: """Gets a list of Solr configs on a Solr instance :param context: SolrServerRequest builder """ pass + +__all__ = [ + "upload_config", + "upload_config_blocking", + "delete_config", + "delete_config_blocking", + "config_exists", + "config_exists_blocking", + "get_configs", + "get_configs_blocking", +] diff --git a/wrappers/python/solrstice/models.pyi b/wrappers/python/solrstice/models.pyi index 8566ec4..c023e9e 100644 --- a/wrappers/python/solrstice/models.pyi +++ b/wrappers/python/solrstice/models.pyi @@ -85,7 +85,7 @@ class SolrGroupFieldResult: :return: Group value """ - def get_doc_list(self) -> SolrDocsResponse: + def get_doc_list(self) -> "SolrDocsResponse": """ Gets the document response from solr :return: Document response @@ -102,13 +102,13 @@ class SolrGroupResult: :return: List of group field results """ - def get_query_result(self) -> Optional[SolrDocsResponse]: + def get_query_result(self) -> Optional["SolrDocsResponse"]: """ Gets the query result from a group query :return: Query result """ - def get_simple_result(self) -> Optional[SolrDocsResponse]: + def get_simple_result(self) -> Optional["SolrDocsResponse"]: """ Gets the result from a group query where `GroupFormatting.Simple` was used :return: Simple result @@ -177,7 +177,7 @@ class SolrDocsResponse: class SolrResponse: """The response from a solr query""" - def get_docs_response(self) -> Optional[SolrDocsResponse]: + def get_docs_response(self) -> Optional["SolrDocsResponse"]: """Get the response from a solr query""" def get_groups(self) -> Dict[str, "SolrGroupResult"]: @@ -191,3 +191,14 @@ class SolrResponse: def get_json_facets(self) -> Optional["SolrJsonFacetResponse"]: """Get json facets""" + +__all__ = [ + "SolrFacetSetResult", + "SolrPivotFacetResult", + "SolrFieldFacetResult", + "SolrGroupFieldResult", + "SolrGroupResult", + "SolrJsonFacetResponse", + "SolrDocsResponse", + "SolrResponse", +] diff --git a/wrappers/python/src/queries/alias.rs b/wrappers/python/src/queries/alias.rs index 8cfde49..7460bc5 100644 --- a/wrappers/python/src/queries/alias.rs +++ b/wrappers/python/src/queries/alias.rs @@ -1,7 +1,6 @@ use crate::models::context::SolrServerContextWrapper; use crate::models::error::PyErrWrapper; use pyo3::prelude::*; -use solrstice::SolrServerContext; use solrstice::queries::alias::{ alias_exists as alias_exists_rs, create_alias as create_alias_rs, delete_alias as delete_alias_rs, get_aliases as get_aliases_rs, @@ -12,6 +11,7 @@ use solrstice::queries::alias::{ delete_alias_blocking as delete_alias_blocking_rs, get_aliases_blocking as get_aliases_blocking_rs, }; +use solrstice::SolrServerContext; use std::collections::HashMap; #[pymodule] diff --git a/wrappers/python/src/queries/collection.rs b/wrappers/python/src/queries/collection.rs index d24f5ff..ecc7d6b 100644 --- a/wrappers/python/src/queries/collection.rs +++ b/wrappers/python/src/queries/collection.rs @@ -1,7 +1,6 @@ use crate::models::context::SolrServerContextWrapper; use crate::models::error::PyErrWrapper; use pyo3::prelude::*; -use solrstice::SolrServerContext; use solrstice::queries::collection::{ collection_exists as collection_exists_rs, create_collection as create_collection_rs, delete_collection as delete_collection_rs, get_collections as get_collections_rs, @@ -12,6 +11,7 @@ use solrstice::queries::collection::{ delete_collection_blocking as delete_collection_blocking_rs, get_collections_blocking as get_collections_blocking_rs, }; +use solrstice::SolrServerContext; #[pymodule] pub fn collection(_py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> { diff --git a/wrappers/python/src/queries/config.rs b/wrappers/python/src/queries/config.rs index 0333239..ab72fa1 100644 --- a/wrappers/python/src/queries/config.rs +++ b/wrappers/python/src/queries/config.rs @@ -1,7 +1,6 @@ use crate::models::context::SolrServerContextWrapper; use crate::models::error::PyErrWrapper; use pyo3::prelude::*; -use solrstice::SolrServerContext; use solrstice::queries::config::{ config_exists as config_exists_rs, delete_config as delete_config_rs, get_configs as get_configs_rs, upload_config as upload_config_rs, @@ -12,6 +11,7 @@ use solrstice::queries::config::{ get_configs_blocking as get_configs_blocking_rs, upload_config_blocking as upload_config_blocking_rs, }; +use solrstice::SolrServerContext; use std::path::PathBuf; #[pymodule] From cd3d959932e11cc83d44e5e92cfab51db79ac8ed Mon Sep 17 00:00:00 2001 From: Sh1nku <42642351+Sh1nku@users.noreply.github.com> Date: Fri, 26 Jul 2024 14:10:04 +0200 Subject: [PATCH 5/5] Change how mdbook is generated --- .github/workflows/generate_docs.yml | 8 +++----- .github/workflows/publish_docs.yml | 10 ++++------ 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/.github/workflows/generate_docs.yml b/.github/workflows/generate_docs.yml index 1b877ac..3c278d8 100644 --- a/.github/workflows/generate_docs.yml +++ b/.github/workflows/generate_docs.yml @@ -15,6 +15,9 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: 3.8 - name: Install mdbook run: | wget https://github.com/rust-lang/mdBook/releases/download/v0.4.34/mdbook-v0.4.34-x86_64-unknown-linux-gnu.tar.gz @@ -24,8 +27,3 @@ jobs: working-directory: ./docs run: | mdbook build - mkdir docs_built - mv book/* docs_built - - uses: actions/setup-python@v4 - with: - python-version: 3.8 diff --git a/.github/workflows/publish_docs.yml b/.github/workflows/publish_docs.yml index 75cf0ac..e595299 100644 --- a/.github/workflows/publish_docs.yml +++ b/.github/workflows/publish_docs.yml @@ -24,6 +24,9 @@ jobs: url: ${{ steps.deployment.outputs.page_url }} steps: - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: 3.8 - name: Install mdbook run: | wget https://github.com/rust-lang/mdBook/releases/download/v0.4.34/mdbook-v0.4.34-x86_64-unknown-linux-gnu.tar.gz @@ -33,15 +36,10 @@ jobs: working-directory: ./docs run: | mdbook build - mkdir docs_built - mv book/* docs_built - - uses: actions/setup-python@v4 - with: - python-version: 3.8 - name: Upload artifact uses: actions/upload-pages-artifact@v2 with: - path: 'docs/docs_built/' + path: 'docs/book/' - name: Deploy to GitHub Pages id: deployment uses: actions/deploy-pages@v2