mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-07-04 12:27:13 +02:00
add the content type to all the route
This commit is contained in:
parent
9e1bba40f7
commit
8e2d6cf87d
5 changed files with 46 additions and 15 deletions
|
@ -148,6 +148,7 @@ pub async fn add_documents(
|
|||
"with_primary_key": params.primary_key,
|
||||
"index_creation": meilisearch.get_index(path.index_uid.clone()).await.is_ok(),
|
||||
}),
|
||||
Some(&req),
|
||||
);
|
||||
|
||||
document_addition(
|
||||
|
@ -182,6 +183,7 @@ pub async fn update_documents(
|
|||
"with_primary_key": params.primary_key,
|
||||
"index_creation": meilisearch.get_index(path.index_uid.clone()).await.is_ok(),
|
||||
}),
|
||||
Some(&req),
|
||||
);
|
||||
|
||||
document_addition(
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use actix_web::{web, HttpResponse};
|
||||
use actix_web::{web, HttpRequest, HttpResponse};
|
||||
use chrono::{DateTime, Utc};
|
||||
use log::debug;
|
||||
use meilisearch_lib::index_controller::IndexSettings;
|
||||
|
@ -56,6 +56,7 @@ pub struct IndexCreateRequest {
|
|||
pub async fn create_index(
|
||||
meilisearch: GuardedData<Private, MeiliSearch>,
|
||||
body: web::Json<IndexCreateRequest>,
|
||||
req: HttpRequest,
|
||||
analytics: web::Data<&'static dyn Analytics>,
|
||||
) -> Result<HttpResponse, ResponseError> {
|
||||
let body = body.into_inner();
|
||||
|
@ -63,6 +64,7 @@ pub async fn create_index(
|
|||
analytics.publish(
|
||||
"Index Created".to_string(),
|
||||
json!({ "with_primary_key": body.primary_key}),
|
||||
Some(&req),
|
||||
);
|
||||
let meta = meilisearch.create_index(body.uid, body.primary_key).await?;
|
||||
Ok(HttpResponse::Created().json(meta))
|
||||
|
@ -98,6 +100,7 @@ pub async fn update_index(
|
|||
meilisearch: GuardedData<Private, MeiliSearch>,
|
||||
path: web::Path<IndexParam>,
|
||||
body: web::Json<UpdateIndexRequest>,
|
||||
req: HttpRequest,
|
||||
analytics: web::Data<&'static dyn Analytics>,
|
||||
) -> Result<HttpResponse, ResponseError> {
|
||||
debug!("called with params: {:?}", body);
|
||||
|
@ -105,6 +108,7 @@ pub async fn update_index(
|
|||
analytics.publish(
|
||||
"Index Updated".to_string(),
|
||||
json!({ "with_primary_key": body.primary_key}),
|
||||
Some(&req),
|
||||
);
|
||||
let settings = IndexSettings {
|
||||
uid: body.uid,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use actix_web::{web, HttpResponse};
|
||||
use actix_web::{web, HttpRequest, HttpResponse};
|
||||
use log::debug;
|
||||
use meilisearch_lib::index::{default_crop_length, SearchQuery, DEFAULT_SEARCH_LIMIT};
|
||||
use meilisearch_lib::MeiliSearch;
|
||||
|
@ -110,6 +110,7 @@ pub async fn search_with_url_query(
|
|||
meilisearch: GuardedData<Public, MeiliSearch>,
|
||||
path: web::Path<IndexParam>,
|
||||
params: web::Query<SearchQueryGet>,
|
||||
req: HttpRequest,
|
||||
analytics: web::Data<&'static dyn Analytics>,
|
||||
) -> Result<HttpResponse, ResponseError> {
|
||||
debug!("called with params: {:?}", params);
|
||||
|
@ -127,7 +128,11 @@ pub async fn search_with_url_query(
|
|||
assert!(!search_result.exhaustive_nb_hits);
|
||||
|
||||
analytics_value["response_time"] = json!(search_result.processing_time_ms as u64);
|
||||
analytics.publish("Documents Searched".to_string(), analytics_value);
|
||||
analytics.publish(
|
||||
"Documents Searched".to_string(),
|
||||
analytics_value,
|
||||
Some(&req),
|
||||
);
|
||||
|
||||
debug!("returns: {:?}", search_result);
|
||||
Ok(HttpResponse::Ok().json(search_result))
|
||||
|
@ -137,6 +142,7 @@ pub async fn search_with_post(
|
|||
meilisearch: GuardedData<Public, MeiliSearch>,
|
||||
path: web::Path<IndexParam>,
|
||||
params: web::Json<SearchQuery>,
|
||||
req: HttpRequest,
|
||||
analytics: web::Data<&'static dyn Analytics>,
|
||||
) -> Result<HttpResponse, ResponseError> {
|
||||
let query = params.into_inner();
|
||||
|
@ -154,7 +160,11 @@ pub async fn search_with_post(
|
|||
assert!(!search_result.exhaustive_nb_hits);
|
||||
|
||||
analytics_value["response_time"] = json!(search_result.processing_time_ms as u64);
|
||||
analytics.publish("Documents Searched".to_string(), analytics_value);
|
||||
analytics.publish(
|
||||
"Documents Searched".to_string(),
|
||||
analytics_value,
|
||||
Some(&req),
|
||||
);
|
||||
|
||||
debug!("returns: {:?}", search_result);
|
||||
Ok(HttpResponse::Ok().json(search_result))
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use log::debug;
|
||||
|
||||
use actix_web::{web, HttpResponse};
|
||||
use actix_web::{web, HttpRequest, HttpResponse};
|
||||
use meilisearch_lib::index::{Settings, Unchecked};
|
||||
use meilisearch_lib::index_controller::Update;
|
||||
use meilisearch_lib::MeiliSearch;
|
||||
|
@ -15,7 +15,7 @@ macro_rules! make_setting_route {
|
|||
($route:literal, $type:ty, $attr:ident, $camelcase_attr:literal, $analytics_var:ident, $analytics:expr) => {
|
||||
pub mod $attr {
|
||||
use log::debug;
|
||||
use actix_web::{web, HttpResponse, Resource};
|
||||
use actix_web::{web, HttpResponse, HttpRequest, Resource};
|
||||
|
||||
use meilisearch_lib::milli::update::Setting;
|
||||
use meilisearch_lib::{MeiliSearch, index::Settings, index_controller::Update};
|
||||
|
@ -42,11 +42,12 @@ macro_rules! make_setting_route {
|
|||
meilisearch: GuardedData<Private, MeiliSearch>,
|
||||
index_uid: actix_web::web::Path<String>,
|
||||
body: actix_web::web::Json<Option<$type>>,
|
||||
req: HttpRequest,
|
||||
$analytics_var: web::Data<&'static dyn Analytics>,
|
||||
) -> std::result::Result<HttpResponse, ResponseError> {
|
||||
let body = body.into_inner();
|
||||
|
||||
$analytics(&body);
|
||||
$analytics(&body, &req);
|
||||
|
||||
let settings = Settings {
|
||||
$attr: match body {
|
||||
|
@ -82,7 +83,7 @@ macro_rules! make_setting_route {
|
|||
}
|
||||
};
|
||||
($route:literal, $type:ty, $attr:ident, $camelcase_attr:literal) => {
|
||||
make_setting_route!($route, $type, $attr, $camelcase_attr, _analytics, |_| {});
|
||||
make_setting_route!($route, $type, $attr, $camelcase_attr, _analytics, |_, _| {});
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -92,7 +93,7 @@ make_setting_route!(
|
|||
filterable_attributes,
|
||||
"filterableAttributes",
|
||||
analytics,
|
||||
|setting: &Option<std::collections::BTreeSet<String>>| {
|
||||
|setting: &Option<std::collections::BTreeSet<String>>, req: &HttpRequest| {
|
||||
use serde_json::json;
|
||||
|
||||
analytics.publish(
|
||||
|
@ -101,6 +102,7 @@ make_setting_route!(
|
|||
"total": setting.as_ref().map(|filter| filter.len()),
|
||||
"has_geo": setting.as_ref().map(|filter| filter.contains("_geo")).unwrap_or(false),
|
||||
}),
|
||||
Some(&req),
|
||||
);
|
||||
}
|
||||
);
|
||||
|
@ -111,7 +113,7 @@ make_setting_route!(
|
|||
sortable_attributes,
|
||||
"sortableAttributes",
|
||||
analytics,
|
||||
|setting: &Option<std::collections::BTreeSet<String>>| {
|
||||
|setting: &Option<std::collections::BTreeSet<String>>, req: &HttpRequest| {
|
||||
use serde_json::json;
|
||||
|
||||
analytics.publish(
|
||||
|
@ -120,6 +122,7 @@ make_setting_route!(
|
|||
"total": setting.as_ref().map(|sort| sort.len()),
|
||||
"has_geo": setting.as_ref().map(|sort| sort.contains("_geo")).unwrap_or(false),
|
||||
}),
|
||||
Some(&req),
|
||||
);
|
||||
}
|
||||
);
|
||||
|
@ -165,7 +168,7 @@ make_setting_route!(
|
|||
ranking_rules,
|
||||
"rankingRules",
|
||||
analytics,
|
||||
|setting: &Option<Vec<String>>| {
|
||||
|setting: &Option<Vec<String>>, req: &HttpRequest| {
|
||||
use serde_json::json;
|
||||
|
||||
analytics.publish(
|
||||
|
@ -173,6 +176,7 @@ make_setting_route!(
|
|||
json!({
|
||||
"sort_position": setting.as_ref().map(|sort| sort.iter().filter(|s| s.contains(":")).count()),
|
||||
}),
|
||||
Some(&req),
|
||||
);
|
||||
}
|
||||
);
|
||||
|
@ -205,6 +209,7 @@ pub async fn update_all(
|
|||
meilisearch: GuardedData<Private, MeiliSearch>,
|
||||
index_uid: web::Path<String>,
|
||||
body: web::Json<Settings<Unchecked>>,
|
||||
req: HttpRequest,
|
||||
analytics: web::Data<&'static dyn Analytics>,
|
||||
) -> Result<HttpResponse, ResponseError> {
|
||||
let settings = body.into_inner();
|
||||
|
@ -224,6 +229,7 @@ pub async fn update_all(
|
|||
"has_geo": settings.filterable_attributes.as_ref().set().map(|filter| filter.iter().any(|s| s == "_geo")).unwrap_or(false),
|
||||
},
|
||||
}),
|
||||
Some(&req),
|
||||
);
|
||||
|
||||
let update = Update::Settings(settings);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue