mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-27 04:25:06 +08:00
Rename index_name to index_uids
This commit is contained in:
parent
39e2b73718
commit
e97e13ce9f
@ -251,7 +251,7 @@ impl Database {
|
|||||||
self.env.copy_to_path(path, CompactionOption::Enabled)
|
self.env.copy_to_path(path, CompactionOption::Enabled)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn indexes_names(&self) -> MResult<Vec<String>> {
|
pub fn indexes_uids(&self) -> MResult<Vec<String>> {
|
||||||
let indexes = self.indexes.read().unwrap();
|
let indexes = self.indexes.read().unwrap();
|
||||||
Ok(indexes.keys().cloned().collect())
|
Ok(indexes.keys().cloned().collect())
|
||||||
}
|
}
|
||||||
|
@ -29,11 +29,54 @@ pub async fn list_indexes(ctx: Context<Data>) -> SResult<Response> {
|
|||||||
let list = ctx
|
let list = ctx
|
||||||
.state()
|
.state()
|
||||||
.db
|
.db
|
||||||
.indexes_names()
|
.indexes_uids()
|
||||||
.map_err(ResponseError::internal)?;
|
.map_err(ResponseError::internal)?;
|
||||||
Ok(tide::response::json(list))
|
Ok(tide::response::json(list))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
#[serde(rename_all = "camelCase", deny_unknown_fields)]
|
||||||
|
struct GetIndexResponse {
|
||||||
|
name: String,
|
||||||
|
uid: String,
|
||||||
|
schema: Option<SchemaBody>,
|
||||||
|
created_at: DateTime<Utc>,
|
||||||
|
updated_at: DateTime<Utc>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn get_index(ctx: Context<Data>) -> SResult<Response> {
|
||||||
|
ctx.is_allowed(IndexesRead)?;
|
||||||
|
|
||||||
|
let index = ctx.index()?;
|
||||||
|
|
||||||
|
let env = &ctx.state().db.env;
|
||||||
|
let mut reader = env.read_txn().map_err(ResponseError::internal)?;
|
||||||
|
|
||||||
|
let uid = ctx.url_param("index")?.to_string();
|
||||||
|
let name = index.main.name(&mut reader)
|
||||||
|
.map_err(ResponseError::internal)?
|
||||||
|
.ok_or(ResponseError::internal("Name not found"))?;
|
||||||
|
let schema = index.main.schema(&mut reader)
|
||||||
|
.map_err(ResponseError::internal)?
|
||||||
|
.map(|schema| SchemaBody::from(schema));
|
||||||
|
let created_at = index.main.created_at(&mut reader)
|
||||||
|
.map_err(ResponseError::internal)?
|
||||||
|
.ok_or(ResponseError::internal("Created date not found"))?;
|
||||||
|
let updated_at = index.main.updated_at(&mut reader)
|
||||||
|
.map_err(ResponseError::internal)?
|
||||||
|
.ok_or(ResponseError::internal("Updated date not found"))?;
|
||||||
|
|
||||||
|
let response_body = GetIndexResponse {
|
||||||
|
name,
|
||||||
|
uid,
|
||||||
|
schema,
|
||||||
|
created_at,
|
||||||
|
updated_at,
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(tide::response::json(response_body))
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn get_index_schema(ctx: Context<Data>) -> SResult<Response> {
|
pub async fn get_index_schema(ctx: Context<Data>) -> SResult<Response> {
|
||||||
ctx.is_allowed(IndexesRead)?;
|
ctx.is_allowed(IndexesRead)?;
|
||||||
|
|
||||||
|
@ -158,7 +158,7 @@ pub async fn search_multi_index(mut ctx: Context<Data>) -> SResult<Response> {
|
|||||||
index_list = ctx
|
index_list = ctx
|
||||||
.state()
|
.state()
|
||||||
.db
|
.db
|
||||||
.indexes_names()
|
.indexes_uids()
|
||||||
.map_err(ResponseError::internal)?
|
.map_err(ResponseError::internal)?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.collect();
|
.collect();
|
||||||
|
@ -72,7 +72,7 @@ pub async fn get_stats(ctx: Context<Data>) -> SResult<Response> {
|
|||||||
|
|
||||||
let mut index_list = HashMap::new();
|
let mut index_list = HashMap::new();
|
||||||
|
|
||||||
if let Ok(indexes_set) = ctx.state().db.indexes_names() {
|
if let Ok(indexes_set) = ctx.state().db.indexes_uids() {
|
||||||
for index_uid in indexes_set {
|
for index_uid in indexes_set {
|
||||||
let db = &ctx.state().db;
|
let db = &ctx.state().db;
|
||||||
let env = &db.env;
|
let env = &db.env;
|
||||||
|
Loading…
Reference in New Issue
Block a user