feat(meilisearch): add document and settings views
This commit is contained in:
1 parent
39ce50b681
commit
884744df4c
32 files changed
+3673
-57
No files matched your search
@@ -799,6 +799,18 @@ async fn main() {
|
||||
.route("/document-store/update-document", post(routes::document_store::update_document))
|
||||
.route("/document-store/delete-document", post(routes::document_store::delete_document))
|
||||
.route("/document-store/save-meilisearch-batch", post(routes::document_store::save_meilisearch_batch))
|
||||
.route("/document-store/meilisearch/search", post(routes::document_store::meilisearch_search))
|
||||
.route("/document-store/meilisearch/documents/fetch", post(routes::document_store::meilisearch_fetch_documents))
|
||||
.route("/document-store/meilisearch/documents/get", post(routes::document_store::meilisearch_get_document))
|
||||
.route("/document-store/meilisearch/settings/get", post(routes::document_store::meilisearch_get_settings))
|
||||
.route("/document-store/meilisearch/settings/update", post(routes::document_store::meilisearch_update_settings))
|
||||
.route("/document-store/meilisearch/stats", post(routes::document_store::meilisearch_get_stats))
|
||||
.route("/document-store/meilisearch/overview", post(routes::document_store::meilisearch_get_overview))
|
||||
.route("/document-store/meilisearch/index/delete", post(routes::document_store::meilisearch_delete_index))
|
||||
.route(
|
||||
"/document-store/meilisearch/documents/delete-all",
|
||||
post(routes::document_store::meilisearch_delete_all_documents),
|
||||
)
|
||||
.route("/mongo/find-documents", post(routes::mongo::find_documents))
|
||||
.route("/mongo/parse-shell-command", post(routes::mongo::parse_shell_command))
|
||||
.route("/mongo/explain-find", post(routes::mongo::explain_find))
|
||||
|
||||
@@ -139,6 +139,56 @@ pub struct MeilisearchBatchSaveRequest {
|
||||
pub inserts: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct MeilisearchSearchRequest {
|
||||
pub connection_id: String,
|
||||
pub index: String,
|
||||
pub q: Option<String>,
|
||||
pub filter: Option<String>,
|
||||
pub sort: Option<String>,
|
||||
pub limit: u64,
|
||||
pub offset: u64,
|
||||
pub hybrid_embedder: Option<String>,
|
||||
pub hybrid_semantic_ratio: Option<f64>,
|
||||
pub show_ranking_score: Option<bool>,
|
||||
pub ranking_score_threshold: Option<f64>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct MeilisearchDocumentPageRequest {
|
||||
pub connection_id: String,
|
||||
pub index: String,
|
||||
pub filter: Option<String>,
|
||||
pub sort: Option<String>,
|
||||
pub limit: u64,
|
||||
pub offset: u64,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct MeilisearchIndexRequest {
|
||||
pub connection_id: String,
|
||||
pub index: String,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct MeilisearchDocumentGetRequest {
|
||||
pub connection_id: String,
|
||||
pub index: String,
|
||||
pub id: String,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct MeilisearchSettingsUpdateRequest {
|
||||
pub connection_id: String,
|
||||
pub index: String,
|
||||
pub settings: serde_json::Value,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct GridFsBucketRequest {
|
||||
@@ -360,6 +410,128 @@ pub async fn save_meilisearch_batch(
|
||||
Ok(Json(result))
|
||||
}
|
||||
|
||||
pub async fn meilisearch_search(
|
||||
State(state): State<Arc<WebState>>,
|
||||
Json(req): Json<MeilisearchSearchRequest>,
|
||||
) -> Result<Json<dbx_core::db::meilisearch_driver::MeilisearchSearchResult>, AppError> {
|
||||
let result = dbx_core::document_ops::meilisearch_search_documents_core(
|
||||
&state.app,
|
||||
&req.connection_id,
|
||||
&req.index,
|
||||
req.q.as_deref(),
|
||||
req.filter.as_deref(),
|
||||
req.sort.as_deref(),
|
||||
req.limit,
|
||||
req.offset,
|
||||
req.hybrid_embedder.as_deref(),
|
||||
req.hybrid_semantic_ratio,
|
||||
req.show_ranking_score.unwrap_or(false),
|
||||
req.ranking_score_threshold,
|
||||
)
|
||||
.await
|
||||
.map_err(AppError::from)?;
|
||||
Ok(Json(result))
|
||||
}
|
||||
|
||||
pub async fn meilisearch_fetch_documents(
|
||||
State(state): State<Arc<WebState>>,
|
||||
Json(req): Json<MeilisearchDocumentPageRequest>,
|
||||
) -> Result<Json<dbx_core::db::meilisearch_driver::MeilisearchDocumentPage>, AppError> {
|
||||
let result = dbx_core::document_ops::meilisearch_fetch_document_page_core(
|
||||
&state.app,
|
||||
&req.connection_id,
|
||||
&req.index,
|
||||
req.filter.as_deref(),
|
||||
req.sort.as_deref(),
|
||||
req.limit,
|
||||
req.offset,
|
||||
)
|
||||
.await
|
||||
.map_err(AppError::from)?;
|
||||
Ok(Json(result))
|
||||
}
|
||||
|
||||
pub async fn meilisearch_get_document(
|
||||
State(state): State<Arc<WebState>>,
|
||||
Json(req): Json<MeilisearchDocumentGetRequest>,
|
||||
) -> Result<Json<String>, AppError> {
|
||||
let result =
|
||||
dbx_core::document_ops::meilisearch_get_document_core(&state.app, &req.connection_id, &req.index, &req.id)
|
||||
.await
|
||||
.map_err(AppError::from)?;
|
||||
Ok(Json(result))
|
||||
}
|
||||
|
||||
pub async fn meilisearch_get_settings(
|
||||
State(state): State<Arc<WebState>>,
|
||||
Json(req): Json<MeilisearchIndexRequest>,
|
||||
) -> Result<Json<serde_json::Value>, AppError> {
|
||||
let result =
|
||||
dbx_core::document_ops::meilisearch_get_index_settings_core(&state.app, &req.connection_id, &req.index)
|
||||
.await
|
||||
.map_err(AppError::from)?;
|
||||
Ok(Json(result))
|
||||
}
|
||||
|
||||
pub async fn meilisearch_update_settings(
|
||||
State(state): State<Arc<WebState>>,
|
||||
Json(req): Json<MeilisearchSettingsUpdateRequest>,
|
||||
) -> Result<Json<()>, AppError> {
|
||||
ensure_writable(&state.app, &req.connection_id, "Update settings").await?;
|
||||
dbx_core::document_ops::meilisearch_update_index_settings_core(
|
||||
&state.app,
|
||||
&req.connection_id,
|
||||
&req.index,
|
||||
&req.settings,
|
||||
)
|
||||
.await
|
||||
.map_err(AppError::from)?;
|
||||
Ok(Json(()))
|
||||
}
|
||||
|
||||
pub async fn meilisearch_get_stats(
|
||||
State(state): State<Arc<WebState>>,
|
||||
Json(req): Json<MeilisearchIndexRequest>,
|
||||
) -> Result<Json<serde_json::Value>, AppError> {
|
||||
let result = dbx_core::document_ops::meilisearch_get_index_stats_core(&state.app, &req.connection_id, &req.index)
|
||||
.await
|
||||
.map_err(AppError::from)?;
|
||||
Ok(Json(result))
|
||||
}
|
||||
|
||||
pub async fn meilisearch_get_overview(
|
||||
State(state): State<Arc<WebState>>,
|
||||
Json(req): Json<MeilisearchIndexRequest>,
|
||||
) -> Result<Json<dbx_core::db::meilisearch_driver::MeilisearchIndexOverview>, AppError> {
|
||||
let result =
|
||||
dbx_core::document_ops::meilisearch_get_index_overview_core(&state.app, &req.connection_id, &req.index)
|
||||
.await
|
||||
.map_err(AppError::from)?;
|
||||
Ok(Json(result))
|
||||
}
|
||||
|
||||
pub async fn meilisearch_delete_index(
|
||||
State(state): State<Arc<WebState>>,
|
||||
Json(req): Json<MeilisearchIndexRequest>,
|
||||
) -> Result<Json<()>, AppError> {
|
||||
ensure_writable(&state.app, &req.connection_id, "Delete index").await?;
|
||||
dbx_core::document_ops::meilisearch_delete_index_core(&state.app, &req.connection_id, &req.index)
|
||||
.await
|
||||
.map_err(AppError::from)?;
|
||||
Ok(Json(()))
|
||||
}
|
||||
|
||||
pub async fn meilisearch_delete_all_documents(
|
||||
State(state): State<Arc<WebState>>,
|
||||
Json(req): Json<MeilisearchIndexRequest>,
|
||||
) -> Result<Json<()>, AppError> {
|
||||
ensure_writable(&state.app, &req.connection_id, "Delete all documents").await?;
|
||||
dbx_core::document_ops::meilisearch_delete_all_documents_core(&state.app, &req.connection_id, &req.index)
|
||||
.await
|
||||
.map_err(AppError::from)?;
|
||||
Ok(Json(()))
|
||||
}
|
||||
|
||||
pub async fn list_gridfs_files(
|
||||
State(state): State<Arc<WebState>>,
|
||||
Json(req): Json<GridFsFileListRequest>,
|
||||
|
||||
Reference in new issue
Block a user