From 271c8ba991834560b35c25ac7bd3af0724e88436 Mon Sep 17 00:00:00 2001 From: mpostma Date: Thu, 11 Mar 2021 22:47:29 +0100 Subject: [PATCH] change index name to uid --- meilisearch-http/src/data/mod.rs | 2 +- meilisearch-http/src/index_controller/mod.rs | 70 ++++++++++---------- meilisearch-http/tests/index/create_index.rs | 8 +-- 3 files changed, 40 insertions(+), 40 deletions(-) diff --git a/meilisearch-http/src/data/mod.rs b/meilisearch-http/src/data/mod.rs index b011c18b3..f2b963eec 100644 --- a/meilisearch-http/src/data/mod.rs +++ b/meilisearch-http/src/data/mod.rs @@ -90,7 +90,7 @@ impl Data { pub async fn create_index(&self, name: impl AsRef, primary_key: Option>) -> anyhow::Result { let settings = IndexSettings { - name: Some(name.as_ref().to_string()), + uid: Some(name.as_ref().to_string()), primary_key: primary_key.map(|s| s.as_ref().to_string()), }; diff --git a/meilisearch-http/src/index_controller/mod.rs b/meilisearch-http/src/index_controller/mod.rs index 56693e204..c76cd8a70 100644 --- a/meilisearch-http/src/index_controller/mod.rs +++ b/meilisearch-http/src/index_controller/mod.rs @@ -26,7 +26,7 @@ pub type UpdateStatus = updates::UpdateStatus; #[derive(Debug, Serialize, Deserialize, Clone)] #[serde(rename_all = "camelCase")] pub struct IndexMetadata { - name: String, + uid: String, #[serde(flatten)] meta: index_actor::IndexMeta, } @@ -47,7 +47,7 @@ pub enum UpdateMeta { #[derive(Clone, Debug)] pub struct IndexSettings { - pub name: Option, + pub uid: Option, pub primary_key: Option, } @@ -77,13 +77,13 @@ impl IndexController { pub async fn add_documents( &self, - index: String, + uid: String, method: milli::update::IndexDocumentsMethod, format: milli::update::UpdateFormat, mut payload: Payload, primary_key: Option, ) -> anyhow::Result { - let uuid = self.uuid_resolver.get_or_create(index).await?; + let uuid = self.uuid_resolver.get_or_create(uid).await?; let meta = UpdateMeta::DocumentsAddition { method, format, primary_key }; let (sender, receiver) = mpsc::channel(10); @@ -106,16 +106,16 @@ impl IndexController { Ok(status) } - pub async fn clear_documents(&self, index: String) -> anyhow::Result { - let uuid = self.uuid_resolver.resolve(index).await?; + pub async fn clear_documents(&self, uid: String) -> anyhow::Result { + let uuid = self.uuid_resolver.resolve(uid).await?; let meta = UpdateMeta::ClearDocuments; let (_, receiver) = mpsc::channel(1); let status = self.update_handle.update(meta, receiver, uuid).await?; Ok(status) } - pub async fn delete_documents(&self, index: String, document_ids: Vec) -> anyhow::Result { - let uuid = self.uuid_resolver.resolve(index).await?; + pub async fn delete_documents(&self, uid: String, document_ids: Vec) -> anyhow::Result { + let uuid = self.uuid_resolver.resolve(uid).await?; let meta = UpdateMeta::DeleteDocuments; let (sender, receiver) = mpsc::channel(10); @@ -129,11 +129,11 @@ impl IndexController { Ok(status) } - pub async fn update_settings(&self, index_uid: String, settings: Settings, create: bool) -> anyhow::Result { + pub async fn update_settings(&self, uid: String, settings: Settings, create: bool) -> anyhow::Result { let uuid = if create { - self.uuid_resolver.get_or_create(index_uid).await? + self.uuid_resolver.get_or_create(uid).await? } else { - self.uuid_resolver.resolve(index_uid).await? + self.uuid_resolver.resolve(uid).await? }; let meta = UpdateMeta::Settings(settings); // Nothing so send, drop the sender right away, as not to block the update actor. @@ -144,36 +144,36 @@ impl IndexController { } pub async fn create_index(&self, index_settings: IndexSettings) -> anyhow::Result { - let IndexSettings { name, primary_key } = index_settings; - let name = name.unwrap(); - let uuid = self.uuid_resolver.create(name.clone()).await?; + let IndexSettings { uid: name, primary_key } = index_settings; + let uid = name.unwrap(); + let uuid = self.uuid_resolver.create(uid.clone()).await?; let meta = self.index_handle.create_index(uuid, primary_key).await?; let _ = self.update_handle.create(uuid).await?; - let meta = IndexMetadata { name, meta }; + let meta = IndexMetadata { uid, meta }; Ok(meta) } - pub async fn delete_index(&self, index_uid: String) -> anyhow::Result<()> { + pub async fn delete_index(&self, uid: String) -> anyhow::Result<()> { let uuid = self.uuid_resolver - .delete(index_uid) + .delete(uid) .await?; self.update_handle.delete(uuid.clone()).await?; self.index_handle.delete(uuid).await?; Ok(()) } - pub async fn update_status(&self, index: String, id: u64) -> anyhow::Result> { + pub async fn update_status(&self, uid: String, id: u64) -> anyhow::Result> { let uuid = self.uuid_resolver - .resolve(index) + .resolve(uid) .await?; let result = self.update_handle.update_status(uuid, id).await?; Ok(result) } - pub async fn all_update_status(&self, index: String) -> anyhow::Result> { + pub async fn all_update_status(&self, uid: String) -> anyhow::Result> { let uuid = self.uuid_resolver - .resolve(index).await?; + .resolve(uid).await?; let result = self.update_handle.get_all_updates_status(uuid).await?; Ok(result) } @@ -183,9 +183,9 @@ impl IndexController { let mut ret = Vec::new(); - for (name, uuid) in uuids { + for (uid, uuid) in uuids { if let Some(meta) = self.index_handle.get_index_meta(uuid).await? { - let meta = IndexMetadata { name, meta }; + let meta = IndexMetadata { uid, meta }; ret.push(meta); } } @@ -193,9 +193,9 @@ impl IndexController { Ok(ret) } - pub async fn settings(&self, index: String) -> anyhow::Result { + pub async fn settings(&self, uid: String) -> anyhow::Result { let uuid = self.uuid_resolver - .resolve(index.clone()) + .resolve(uid.clone()) .await?; let settings = self.index_handle.settings(uuid).await?; Ok(settings) @@ -203,13 +203,13 @@ impl IndexController { pub async fn documents( &self, - index: String, + uid: String, offset: usize, limit: usize, attributes_to_retrieve: Option>, ) -> anyhow::Result> { let uuid = self.uuid_resolver - .resolve(index.clone()) + .resolve(uid.clone()) .await?; let documents = self.index_handle.documents(uuid, offset, limit, attributes_to_retrieve).await?; Ok(documents) @@ -217,33 +217,33 @@ impl IndexController { pub async fn document( &self, - index: String, + uid: String, doc_id: String, attributes_to_retrieve: Option>, ) -> anyhow::Result { let uuid = self.uuid_resolver - .resolve(index.clone()) + .resolve(uid.clone()) .await?; let document = self.index_handle.document(uuid, doc_id, attributes_to_retrieve).await?; Ok(document) } - fn update_index(&self, name: String, index_settings: IndexSettings) -> anyhow::Result { + fn update_index(&self, uid: String, index_settings: IndexSettings) -> anyhow::Result { todo!() } - pub async fn search(&self, name: String, query: SearchQuery) -> anyhow::Result { - let uuid = self.uuid_resolver.resolve(name).await?; + pub async fn search(&self, uid: String, query: SearchQuery) -> anyhow::Result { + let uuid = self.uuid_resolver.resolve(uid).await?; let result = self.index_handle.search(uuid, query).await?; Ok(result) } - pub async fn get_index(&self, name: String) -> anyhow::Result> { - let uuid = self.uuid_resolver.resolve(name.clone()).await?; + pub async fn get_index(&self, uid: String) -> anyhow::Result> { + let uuid = self.uuid_resolver.resolve(uid.clone()).await?; let result = self.index_handle .get_index_meta(uuid) .await? - .map(|meta| IndexMetadata { name, meta }); + .map(|meta| IndexMetadata { uid, meta }); Ok(result) } } diff --git a/meilisearch-http/tests/index/create_index.rs b/meilisearch-http/tests/index/create_index.rs index c26941b91..b7c85d748 100644 --- a/meilisearch-http/tests/index/create_index.rs +++ b/meilisearch-http/tests/index/create_index.rs @@ -7,14 +7,15 @@ async fn create_index_no_primary_key() { let index = server.index("test"); let (response, code) = index.create(None).await; + println!("response: {}", response); + assert_eq!(code, 200); assert_eq!(response["uid"], "test"); - assert!(response.get("uuid").is_some()); assert!(response.get("createdAt").is_some()); assert!(response.get("updatedAt").is_some()); assert_eq!(response["createdAt"], response["updatedAt"]); assert_eq!(response["primaryKey"], Value::Null); - assert_eq!(response.as_object().unwrap().len(), 5); + assert_eq!(response.as_object().unwrap().len(), 4); } #[actix_rt::test] @@ -25,12 +26,11 @@ async fn create_index_with_primary_key() { assert_eq!(code, 200); assert_eq!(response["uid"], "test"); - assert!(response.get("uuid").is_some()); assert!(response.get("createdAt").is_some()); assert!(response.get("updatedAt").is_some()); assert_eq!(response["createdAt"], response["updatedAt"]); assert_eq!(response["primaryKey"], "primary"); - assert_eq!(response.as_object().unwrap().len(), 5); + assert_eq!(response.as_object().unwrap().len(), 4); } // TODO: partial test since we are testing error, amd error is not yet fully implemented in