Skip to content

Commit

Permalink
Gcloud SDK v0.25.6 support and new options support for Find Nearest s…
Browse files Browse the repository at this point in the history
…earch (#189)

* Gcloud SDK v0.25.6 support and new options support for Find Nearest search

* Clippy fixes
  • Loading branch information
abdolence authored Sep 5, 2024
1 parent 5b22b09 commit d549313
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 15 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "firestore"
version = "0.43.0"
authors = ["Abdulla Abdurakhmanov <[email protected]>"]
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"
Expand Down Expand Up @@ -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"
Expand Down
15 changes: 10 additions & 5 deletions examples/nearest-vector-query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ struct MyTestStructure {
some_id: String,
some_string: String,
some_vec: FirestoreVector,
distance: Option<f64>,
}

#[tokio::main]
Expand Down Expand Up @@ -43,6 +44,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
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
Expand Down Expand Up @@ -74,11 +76,14 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
.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()
Expand Down
3 changes: 1 addition & 2 deletions src/db/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions src/db/query_models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,8 @@ pub struct FirestoreFindNearestOptions {
pub query_vector: FirestoreVector,
pub distance_measure: FirestoreFindNearestDistanceMeasure,
pub neighbors_limit: u32,
pub distance_result_field: Option<String>,
pub distance_threshold: Option<f64>,
}

impl TryFrom<FirestoreFindNearestOptions>
Expand Down Expand Up @@ -470,6 +472,8 @@ impl TryFrom<FirestoreFindNearestOptions>
),
)))
)?),
distance_result_field: options.distance_result_field.unwrap_or("".into()),
distance_threshold: options.distance_threshold,
})
}
}
Expand Down
9 changes: 3 additions & 6 deletions src/fluent_api/select_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ where
where
F: AsRef<str>,
{
self.find_nearest_with_options::<F>(FirestoreFindNearestOptions::new(
self.find_nearest_with_options(FirestoreFindNearestOptions::new(
field_name.as_ref().to_string(),
vector,
measure,
Expand All @@ -220,13 +220,10 @@ where
}

#[inline]
pub fn find_nearest_with_options<F>(
pub fn find_nearest_with_options(
self,
options: FirestoreFindNearestOptions,
) -> FirestoreSelectDocBuilder<'a, D>
where
F: AsRef<str>,
{
) -> FirestoreSelectDocBuilder<'a, D> {
Self {
params: self.params.with_find_nearest(options),
..self
Expand Down

0 comments on commit d549313

Please sign in to comment.