Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 <me@abdolence.dev>"]
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