diff --git a/src/data/mod.rs b/src/data/mod.rs index cdb2127a8..0f7722657 100644 --- a/src/data/mod.rs +++ b/src/data/mod.rs @@ -86,12 +86,8 @@ impl Data { self.index_controller.list_indexes().await } - pub fn index(&self, name: impl AsRef) -> anyhow::Result> { - todo!() - //Ok(self - //.list_indexes()? - //.into_iter() - //.find(|i| i.uid == name.as_ref())) + pub async fn index(&self, name: impl AsRef) -> anyhow::Result> { + self.index_controller.get_index(name.as_ref().to_string()).await } pub async fn create_index(&self, name: impl AsRef, primary_key: Option>) -> anyhow::Result { diff --git a/src/index_controller/mod.rs b/src/index_controller/mod.rs index 09a979cbd..bcf663ec8 100644 --- a/src/index_controller/mod.rs +++ b/src/index_controller/mod.rs @@ -239,6 +239,18 @@ impl IndexController { 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?; + if let Some(uuid) = uuid { + let result = self.index_handle + .get_index_meta(uuid) + .await? + .map(|meta| IndexMetadata { name, meta }); + return Ok(result) + } + Ok(None) + } } pub async fn get_arc_ownership_blocking(mut item: Arc) -> T { diff --git a/src/routes/index.rs b/src/routes/index.rs index 752493a3b..818c87303 100644 --- a/src/routes/index.rs +++ b/src/routes/index.rs @@ -37,7 +37,7 @@ async fn get_index( data: web::Data, path: web::Path, ) -> Result { - match data.index(&path.index_uid)? { + match data.index(&path.index_uid).await? { Some(meta) => { let json = serde_json::to_string(&meta).unwrap(); Ok(HttpResponse::Ok().body(json))