mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-12-25 14:10:06 +01:00
list settings
This commit is contained in:
parent
47138c7632
commit
17b84691f2
@ -78,35 +78,8 @@ impl Data {
|
|||||||
Ok(Data { inner })
|
Ok(Data { inner })
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn settings<S: AsRef<str>>(&self, index_uid: S) -> anyhow::Result<Settings> {
|
pub async fn settings<S: AsRef<str>>(&self, index_uid: S) -> anyhow::Result<Settings> {
|
||||||
let index = self.index_controller
|
self.index_controller.settings(index_uid.as_ref().to_string()).await
|
||||||
.index(index_uid.as_ref().to_string())?
|
|
||||||
.ok_or_else(|| anyhow::anyhow!("Index {} does not exist.", index_uid.as_ref()))?;
|
|
||||||
|
|
||||||
let txn = index.read_txn()?;
|
|
||||||
|
|
||||||
let displayed_attributes = index
|
|
||||||
.displayed_fields(&txn)?
|
|
||||||
.map(|fields| fields.into_iter().map(String::from).collect())
|
|
||||||
.unwrap_or_else(|| vec!["*".to_string()]);
|
|
||||||
|
|
||||||
let searchable_attributes = index
|
|
||||||
.searchable_fields(&txn)?
|
|
||||||
.map(|fields| fields.into_iter().map(String::from).collect())
|
|
||||||
.unwrap_or_else(|| vec!["*".to_string()]);
|
|
||||||
|
|
||||||
let faceted_attributes = index
|
|
||||||
.faceted_fields(&txn)?
|
|
||||||
.into_iter()
|
|
||||||
.map(|(k, v)| (k, v.to_string()))
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
Ok(Settings {
|
|
||||||
displayed_attributes: Some(Some(displayed_attributes)),
|
|
||||||
searchable_attributes: Some(Some(searchable_attributes)),
|
|
||||||
faceted_attributes: Some(Some(faceted_attributes)),
|
|
||||||
criteria: None,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn list_indexes(&self) -> anyhow::Result<Vec<IndexMetadata>> {
|
pub fn list_indexes(&self) -> anyhow::Result<Vec<IndexMetadata>> {
|
||||||
|
@ -17,3 +17,32 @@ impl Deref for Index {
|
|||||||
self.0.as_ref()
|
self.0.as_ref()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Index {
|
||||||
|
pub fn settings(&self) -> anyhow::Result<Settings> {
|
||||||
|
let txn = self.read_txn()?;
|
||||||
|
|
||||||
|
let displayed_attributes = self
|
||||||
|
.displayed_fields(&txn)?
|
||||||
|
.map(|fields| fields.into_iter().map(String::from).collect())
|
||||||
|
.unwrap_or_else(|| vec!["*".to_string()]);
|
||||||
|
|
||||||
|
let searchable_attributes = self
|
||||||
|
.searchable_fields(&txn)?
|
||||||
|
.map(|fields| fields.into_iter().map(String::from).collect())
|
||||||
|
.unwrap_or_else(|| vec!["*".to_string()]);
|
||||||
|
|
||||||
|
let faceted_attributes = self
|
||||||
|
.faceted_fields(&txn)?
|
||||||
|
.into_iter()
|
||||||
|
.map(|(k, v)| (k, v.to_string()))
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
Ok(Settings {
|
||||||
|
displayed_attributes: Some(Some(displayed_attributes)),
|
||||||
|
searchable_attributes: Some(Some(searchable_attributes)),
|
||||||
|
faceted_attributes: Some(Some(faceted_attributes)),
|
||||||
|
criteria: None,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -16,7 +16,7 @@ use super::update_handler::UpdateHandler;
|
|||||||
use crate::index_controller::{IndexMetadata, UpdateMeta, updates::{Processed, Failed, Processing}};
|
use crate::index_controller::{IndexMetadata, UpdateMeta, updates::{Processed, Failed, Processing}};
|
||||||
use crate::index::UpdateResult as UResult;
|
use crate::index::UpdateResult as UResult;
|
||||||
use crate::option::IndexerOpts;
|
use crate::option::IndexerOpts;
|
||||||
use crate::index::{Index, SearchQuery, SearchResult};
|
use crate::index::{Index, SearchQuery, SearchResult, Settings};
|
||||||
|
|
||||||
pub type Result<T> = std::result::Result<T, IndexError>;
|
pub type Result<T> = std::result::Result<T, IndexError>;
|
||||||
type AsyncMap<K, V> = Arc<RwLock<HashMap<K, V>>>;
|
type AsyncMap<K, V> = Arc<RwLock<HashMap<K, V>>>;
|
||||||
@ -26,6 +26,7 @@ enum IndexMsg {
|
|||||||
CreateIndex { uuid: Uuid, primary_key: Option<String>, ret: oneshot::Sender<Result<IndexMetadata>> },
|
CreateIndex { uuid: Uuid, primary_key: Option<String>, ret: oneshot::Sender<Result<IndexMetadata>> },
|
||||||
Update { meta: Processing<UpdateMeta>, data: std::fs::File, ret: oneshot::Sender<UpdateResult>},
|
Update { meta: Processing<UpdateMeta>, data: std::fs::File, ret: oneshot::Sender<UpdateResult>},
|
||||||
Search { uuid: Uuid, query: SearchQuery, ret: oneshot::Sender<anyhow::Result<SearchResult>> },
|
Search { uuid: Uuid, query: SearchQuery, ret: oneshot::Sender<anyhow::Result<SearchResult>> },
|
||||||
|
Settings { uuid: Uuid, ret: oneshot::Sender<Result<Settings>> },
|
||||||
}
|
}
|
||||||
|
|
||||||
struct IndexActor<S> {
|
struct IndexActor<S> {
|
||||||
@ -75,6 +76,7 @@ impl<S: IndexStore + Sync + Send> IndexActor<S> {
|
|||||||
IndexMsg::CreateIndex { uuid, primary_key, ret } => self.handle_create_index(uuid, primary_key, ret).await,
|
IndexMsg::CreateIndex { uuid, primary_key, ret } => self.handle_create_index(uuid, primary_key, ret).await,
|
||||||
IndexMsg::Update { ret, meta, data } => self.handle_update(meta, data, ret).await,
|
IndexMsg::Update { ret, meta, data } => self.handle_update(meta, data, ret).await,
|
||||||
IndexMsg::Search { ret, query, uuid } => self.handle_search(uuid, query, ret).await,
|
IndexMsg::Search { ret, query, uuid } => self.handle_search(uuid, query, ret).await,
|
||||||
|
IndexMsg::Settings { ret, uuid } => self.handle_settings(uuid, ret).await,
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -100,9 +102,19 @@ impl<S: IndexStore + Sync + Send> IndexActor<S> {
|
|||||||
let uuid = meta.index_uuid().clone();
|
let uuid = meta.index_uuid().clone();
|
||||||
let index = self.store.get_or_create(uuid).await.unwrap();
|
let index = self.store.get_or_create(uuid).await.unwrap();
|
||||||
let update_handler = self.update_handler.clone();
|
let update_handler = self.update_handler.clone();
|
||||||
let result = tokio::task::spawn_blocking(move || update_handler.handle_update(meta, data, index)).await;
|
tokio::task::spawn_blocking(move || {
|
||||||
let result = result.unwrap();
|
let result = update_handler.handle_update(meta, data, index);
|
||||||
let _ = ret.send(result);
|
let _ = ret.send(result);
|
||||||
|
}).await;
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn handle_settings(&self, uuid: Uuid, ret: oneshot::Sender<Result<Settings>>) {
|
||||||
|
let index = self.store.get(uuid).await.unwrap().unwrap();
|
||||||
|
tokio::task::spawn_blocking(move || {
|
||||||
|
let result = index.settings()
|
||||||
|
.map_err(|e| IndexError::Error(e));
|
||||||
|
let _ = ret.send(result);
|
||||||
|
}).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,6 +153,13 @@ impl IndexActorHandle {
|
|||||||
let _ = self.sender.send(msg).await;
|
let _ = self.sender.send(msg).await;
|
||||||
Ok(receiver.await.expect("IndexActor has been killed")?)
|
Ok(receiver.await.expect("IndexActor has been killed")?)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn settings(&self, uuid: Uuid) -> Result<Settings> {
|
||||||
|
let (ret, receiver) = oneshot::channel();
|
||||||
|
let msg = IndexMsg::Settings { uuid, ret };
|
||||||
|
let _ = self.sender.send(msg).await;
|
||||||
|
Ok(receiver.await.expect("IndexActor has been killed")?)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct MapIndexStore {
|
struct MapIndexStore {
|
||||||
|
@ -7,14 +7,15 @@ mod update_handler;
|
|||||||
|
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
use tokio::sync::{mpsc, oneshot};
|
|
||||||
use futures::stream::StreamExt;
|
|
||||||
use actix_web::web::Payload;
|
|
||||||
use crate::index::{SearchResult, SearchQuery};
|
|
||||||
use actix_web::web::Bytes;
|
use actix_web::web::Bytes;
|
||||||
|
use actix_web::web::Payload;
|
||||||
|
use anyhow::Context;
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
|
use crate::index::{SearchResult, SearchQuery};
|
||||||
|
use futures::stream::StreamExt;
|
||||||
use milli::update::{IndexDocumentsMethod, UpdateFormat};
|
use milli::update::{IndexDocumentsMethod, UpdateFormat};
|
||||||
use serde::{Serialize, Deserialize};
|
use serde::{Serialize, Deserialize};
|
||||||
|
use tokio::sync::{mpsc, oneshot};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
pub use updates::{Processed, Processing, Failed};
|
pub use updates::{Processed, Processing, Failed};
|
||||||
@ -135,14 +136,6 @@ impl IndexController {
|
|||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn swap_indices(&self, index1_uid: String, index2_uid: String) -> anyhow::Result<()> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn index(&self, name: String) -> anyhow::Result<Option<std::sync::Arc<milli::Index>>> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn update_status(&self, index: String, id: u64) -> anyhow::Result<Option<UpdateStatus>> {
|
fn update_status(&self, index: String, id: u64) -> anyhow::Result<Option<UpdateStatus>> {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
@ -155,6 +148,15 @@ impl IndexController {
|
|||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn settings(&self, index: String) -> anyhow::Result<Settings> {
|
||||||
|
let uuid = self.uuid_resolver
|
||||||
|
.resolve(index.clone())
|
||||||
|
.await?
|
||||||
|
.with_context(|| format!("Index {:?} doesn't exist", index))?;
|
||||||
|
let settings = self.index_handle.settings(uuid).await?;
|
||||||
|
Ok(settings)
|
||||||
|
}
|
||||||
|
|
||||||
fn update_index(&self, name: String, index_settings: IndexSettings) -> anyhow::Result<IndexMetadata> {
|
fn update_index(&self, name: String, index_settings: IndexSettings) -> anyhow::Result<IndexMetadata> {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
@ -64,7 +64,7 @@ macro_rules! make_setting_route {
|
|||||||
data: actix_web::web::Data<data::Data>,
|
data: actix_web::web::Data<data::Data>,
|
||||||
index_uid: actix_web::web::Path<String>,
|
index_uid: actix_web::web::Path<String>,
|
||||||
) -> std::result::Result<HttpResponse, ResponseError> {
|
) -> std::result::Result<HttpResponse, ResponseError> {
|
||||||
match data.settings(index_uid.as_ref()) {
|
match data.settings(index_uid.as_ref()).await {
|
||||||
Ok(settings) => {
|
Ok(settings) => {
|
||||||
let setting = settings.$attr;
|
let setting = settings.$attr;
|
||||||
let json = serde_json::to_string(&setting).unwrap();
|
let json = serde_json::to_string(&setting).unwrap();
|
||||||
@ -153,7 +153,7 @@ async fn get_all(
|
|||||||
data: web::Data<Data>,
|
data: web::Data<Data>,
|
||||||
index_uid: web::Path<String>,
|
index_uid: web::Path<String>,
|
||||||
) -> Result<HttpResponse, ResponseError> {
|
) -> Result<HttpResponse, ResponseError> {
|
||||||
match data.settings(index_uid.as_ref()) {
|
match data.settings(index_uid.as_ref()).await {
|
||||||
Ok(settings) => {
|
Ok(settings) => {
|
||||||
let json = serde_json::to_string(&settings).unwrap();
|
let json = serde_json::to_string(&settings).unwrap();
|
||||||
Ok(HttpResponse::Ok().body(json))
|
Ok(HttpResponse::Ok().body(json))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user