diff --git a/Cargo.toml b/Cargo.toml index 10c0e6c..94148c9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ name = "firestore" version = "0.43.0" authors = ["Abdulla Abdurakhmanov "] edition = "2021" -rust-version = "1.63" +rust-version = "1.64" license = "Apache-2.0" description = "Library provides a simple API for Google Firestore and own Serde serializer based on efficient gRPC API" homepage = "https://github.com/abdolence/firestore-rs" @@ -31,7 +31,7 @@ tls-webpki-roots = ["gcloud-sdk/tls-webpki-roots"] [dependencies] tracing = "0.1" -gcloud-sdk = { version = "0.25", default-features = false, features = ["google-firestore-v1"] } +gcloud-sdk = { version = "0.25.6", default-features = false, features = ["google-firestore-v1"] } hyper = { version = "1" } struct-path = "0.2" rvstruct = "0.3.2" diff --git a/examples/nearest-vector-query.rs b/examples/nearest-vector-query.rs index 3fbfbcb..7e89f94 100644 --- a/examples/nearest-vector-query.rs +++ b/examples/nearest-vector-query.rs @@ -11,6 +11,7 @@ struct MyTestStructure { some_id: String, some_string: String, some_vec: FirestoreVector, + distance: Option, } #[tokio::main] @@ -43,6 +44,7 @@ async fn main() -> Result<(), Box> { some_id: format!("test-{}", i), some_string: "Test".to_string(), some_vec: vec![i as f64, (i * 10) as f64, (i * 20) as f64].into(), + distance: None, }; // Let's insert some data @@ -74,11 +76,14 @@ async fn main() -> Result<(), Box> { .fluent() .select() .from(TEST_COLLECTION_NAME) - .find_nearest( - path!(MyTestStructure::some_vec), - vec![0.0_f64, 0.0_f64, 0.0_f64].into(), - FirestoreFindNearestDistanceMeasure::Euclidean, - 5, + .find_nearest_with_options( + FirestoreFindNearestOptions::new( + path!(MyTestStructure::some_vec), + vec![0.0_f64, 0.0_f64, 0.0_f64].into(), + FirestoreFindNearestDistanceMeasure::Euclidean, + 5, + ) + .with_distance_result_field(path!(MyTestStructure::distance)), ) .obj() .query() diff --git a/src/db/query.rs b/src/db/query.rs index 7755dbe..bfe1b4b 100644 --- a/src/db/query.rs +++ b/src/db/query.rs @@ -436,8 +436,7 @@ impl FirestoreQuerySupport for FirestoreDb { .as_ref() .unwrap_or_else(|| self.get_documents_path()) .clone(), - consistency_selector: maybe_consistency_selector - .clone(), + consistency_selector: maybe_consistency_selector, query_type: Some( partition_query_request::QueryType::StructuredQuery( query_params, diff --git a/src/db/query_models.rs b/src/db/query_models.rs index 8fcf659..35ecfcc 100644 --- a/src/db/query_models.rs +++ b/src/db/query_models.rs @@ -442,6 +442,8 @@ pub struct FirestoreFindNearestOptions { pub query_vector: FirestoreVector, pub distance_measure: FirestoreFindNearestDistanceMeasure, pub neighbors_limit: u32, + pub distance_result_field: Option, + pub distance_threshold: Option, } impl TryFrom @@ -470,6 +472,8 @@ impl TryFrom ), ))) )?), + distance_result_field: options.distance_result_field.unwrap_or("".into()), + distance_threshold: options.distance_threshold, }) } } diff --git a/src/fluent_api/select_builder.rs b/src/fluent_api/select_builder.rs index 70d0019..c94c734 100644 --- a/src/fluent_api/select_builder.rs +++ b/src/fluent_api/select_builder.rs @@ -211,7 +211,7 @@ where where F: AsRef, { - self.find_nearest_with_options::(FirestoreFindNearestOptions::new( + self.find_nearest_with_options(FirestoreFindNearestOptions::new( field_name.as_ref().to_string(), vector, measure, @@ -220,13 +220,10 @@ where } #[inline] - pub fn find_nearest_with_options( + pub fn find_nearest_with_options( self, options: FirestoreFindNearestOptions, - ) -> FirestoreSelectDocBuilder<'a, D> - where - F: AsRef, - { + ) -> FirestoreSelectDocBuilder<'a, D> { Self { params: self.params.with_find_nearest(options), ..self