From cad90e8cbc9d8b9e0110c855072cef479d06d538 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Thu, 8 Jun 2023 15:44:03 +0200 Subject: [PATCH] Add a vector field to the search routes --- meilisearch/src/routes/indexes/search.rs | 3 +++ meilisearch/src/search.rs | 10 ++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/meilisearch/src/routes/indexes/search.rs b/meilisearch/src/routes/indexes/search.rs index 3ab093b5d..fae24dba2 100644 --- a/meilisearch/src/routes/indexes/search.rs +++ b/meilisearch/src/routes/indexes/search.rs @@ -34,6 +34,8 @@ pub fn configure(cfg: &mut web::ServiceConfig) { pub struct SearchQueryGet { #[deserr(default, error = DeserrQueryParamError)] q: Option, + #[deserr(default, error = DeserrQueryParamError)] + vector: Option>, #[deserr(default = Param(DEFAULT_SEARCH_OFFSET()), error = DeserrQueryParamError)] offset: Param, #[deserr(default = Param(DEFAULT_SEARCH_LIMIT()), error = DeserrQueryParamError)] @@ -84,6 +86,7 @@ impl From for SearchQuery { Self { q: other.q, + vector: other.vector, offset: other.offset.0, limit: other.limit.0, page: other.page.as_deref().copied(), diff --git a/meilisearch/src/search.rs b/meilisearch/src/search.rs index 62f49c148..81bcb6aaa 100644 --- a/meilisearch/src/search.rs +++ b/meilisearch/src/search.rs @@ -33,11 +33,13 @@ pub const DEFAULT_CROP_MARKER: fn() -> String = || "…".to_string(); pub const DEFAULT_HIGHLIGHT_PRE_TAG: fn() -> String = || "".to_string(); pub const DEFAULT_HIGHLIGHT_POST_TAG: fn() -> String = || "".to_string(); -#[derive(Debug, Clone, Default, PartialEq, Eq, Deserr)] +#[derive(Debug, Clone, Default, PartialEq, Deserr)] #[deserr(error = DeserrJsonError, rename_all = camelCase, deny_unknown_fields)] pub struct SearchQuery { #[deserr(default, error = DeserrJsonError)] pub q: Option, + #[deserr(default, error = DeserrJsonError)] + pub vector: Option>, #[deserr(default = DEFAULT_SEARCH_OFFSET(), error = DeserrJsonError)] pub offset: usize, #[deserr(default = DEFAULT_SEARCH_LIMIT(), error = DeserrJsonError)] @@ -86,13 +88,15 @@ impl SearchQuery { // This struct contains the fields of `SearchQuery` inline. // This is because neither deserr nor serde support `flatten` when using `deny_unknown_fields. // The `From` implementation ensures both structs remain up to date. -#[derive(Debug, Clone, PartialEq, Eq, Deserr)] +#[derive(Debug, Clone, PartialEq, Deserr)] #[deserr(error = DeserrJsonError, rename_all = camelCase, deny_unknown_fields)] pub struct SearchQueryWithIndex { #[deserr(error = DeserrJsonError, missing_field_error = DeserrJsonError::missing_index_uid)] pub index_uid: IndexUid, #[deserr(default, error = DeserrJsonError)] pub q: Option, + #[deserr(default, error = DeserrJsonError)] + pub vector: Option>, #[deserr(default = DEFAULT_SEARCH_OFFSET(), error = DeserrJsonError)] pub offset: usize, #[deserr(default = DEFAULT_SEARCH_LIMIT(), error = DeserrJsonError)] @@ -136,6 +140,7 @@ impl SearchQueryWithIndex { let SearchQueryWithIndex { index_uid, q, + vector, offset, limit, page, @@ -159,6 +164,7 @@ impl SearchQueryWithIndex { index_uid, SearchQuery { q, + vector, offset, limit, page,