mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-07-27 00:31:02 +00:00
Start jayson integration
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
use actix_web::{dev::Payload, web::Json, FromRequest, HttpRequest};
|
||||
use futures::ready;
|
||||
use jayson::{DeserializeError, DeserializeFromValue};
|
||||
use jayson::{DeserializeError, DeserializeFromValue, MergeWithError, ValuePointer};
|
||||
use meilisearch_lib::milli::AscDescError;
|
||||
use meilisearch_types::error::{Code, ErrorCode, ResponseError};
|
||||
use std::{
|
||||
fmt::Debug,
|
||||
@ -10,6 +11,66 @@ use std::{
|
||||
task::{Context, Poll},
|
||||
};
|
||||
|
||||
// pub struct MeilisearchDeserializeError {
|
||||
// pub Vec<(ValuePointer, Box<dyn Error>)>,
|
||||
// }
|
||||
// impl MergeWithError<AscDescError> for MeilisearchDeserializeError {
|
||||
// fn merge(self_: Option<Self>, other: AscDescError, merge_location: jayson::ValuePointerRef) -> Result<Self, Self> {
|
||||
// todo!()
|
||||
// }
|
||||
// }
|
||||
// /*
|
||||
// {
|
||||
// !
|
||||
// x: {
|
||||
// y: {
|
||||
// z: {
|
||||
// a: 2
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// */
|
||||
// impl MergeWithError<MeilisearchDeserializeError> for MeilisearchDeserializeError {
|
||||
|
||||
// }
|
||||
// impl DeserializeError for MeilisearchDeserializeError{
|
||||
// fn location(&self) -> Option<jayson::ValuePointer> {
|
||||
// todo!()
|
||||
// }
|
||||
|
||||
// fn incorrect_value_kind(
|
||||
// self_: Option<Self>,
|
||||
// actual: jayson::ValueKind,
|
||||
// accepted: &[jayson::ValueKind],
|
||||
// location: jayson::ValuePointerRef,
|
||||
// ) -> Result<Self, Self> {
|
||||
// todo!()
|
||||
// }
|
||||
|
||||
// fn missing_field(
|
||||
// self_: Option<Self>,
|
||||
// field: &str,
|
||||
// location: jayson::ValuePointerRef,
|
||||
// ) -> Result<Self, Self> {
|
||||
// todo!()
|
||||
// }
|
||||
|
||||
// fn unknown_key(
|
||||
// self_: Option<Self>,
|
||||
// key: &str,
|
||||
// accepted: &[&str],
|
||||
// location: jayson::ValuePointerRef,
|
||||
// ) -> Result<Self, Self> {
|
||||
// todo!()
|
||||
// }
|
||||
|
||||
// fn unexpected(self_: Option<Self>, msg: &str, location: jayson::ValuePointerRef) -> Result<Self, Self> {
|
||||
// todo!()
|
||||
// }
|
||||
// }
|
||||
|
||||
/// Extractor for typed data from Json request payloads
|
||||
/// deserialised by Jayson.
|
||||
///
|
||||
|
@ -4,11 +4,13 @@ use actix_web::{web, HttpRequest, HttpResponse};
|
||||
use meilisearch_lib::index::{Settings, Unchecked};
|
||||
use meilisearch_lib::index_controller::Update;
|
||||
use meilisearch_lib::MeiliSearch;
|
||||
use meilisearch_types::error::ResponseError;
|
||||
use meilisearch_types::error::{MeiliDeserError, ResponseError};
|
||||
use serde_json::json;
|
||||
|
||||
use crate::analytics::Analytics;
|
||||
use crate::error::MeilisearchHttpError;
|
||||
use crate::extractors::authentication::{policies::*, GuardedData};
|
||||
use crate::extractors::jayson::ValidatedJson;
|
||||
use crate::task::SummarizedTaskView;
|
||||
|
||||
#[macro_export]
|
||||
@ -260,27 +262,27 @@ make_setting_route!(
|
||||
"distinctAttribute"
|
||||
);
|
||||
|
||||
make_setting_route!(
|
||||
"/ranking-rules",
|
||||
put,
|
||||
Vec<String>,
|
||||
ranking_rules,
|
||||
"rankingRules",
|
||||
analytics,
|
||||
|setting: &Option<Vec<String>>, req: &HttpRequest| {
|
||||
use serde_json::json;
|
||||
// make_setting_route!(
|
||||
// "/ranking-rules",
|
||||
// put,
|
||||
// Vec<String>,
|
||||
// ranking_rules,
|
||||
// "rankingRules",
|
||||
// analytics,
|
||||
// |setting: &Option<Vec<milli::AscDesc>>, req: &HttpRequest| {
|
||||
// use serde_json::json;
|
||||
|
||||
analytics.publish(
|
||||
"RankingRules Updated".to_string(),
|
||||
json!({
|
||||
"ranking_rules": {
|
||||
"sort_position": setting.as_ref().map(|sort| sort.iter().position(|s| s == "sort")),
|
||||
}
|
||||
}),
|
||||
Some(req),
|
||||
);
|
||||
}
|
||||
);
|
||||
// analytics.publish(
|
||||
// "RankingRules Updated".to_string(),
|
||||
// json!({
|
||||
// "ranking_rules": {
|
||||
// "sort_position": setting.as_ref().map(|sort| sort.iter().position(|s| s == "sort")),
|
||||
// }
|
||||
// }),
|
||||
// Some(req),
|
||||
// );
|
||||
// }
|
||||
// );
|
||||
|
||||
make_setting_route!(
|
||||
"/faceting",
|
||||
@ -348,14 +350,14 @@ generate_configure!(
|
||||
distinct_attribute,
|
||||
stop_words,
|
||||
synonyms,
|
||||
ranking_rules,
|
||||
// ranking_rules,
|
||||
typo_tolerance
|
||||
);
|
||||
|
||||
pub async fn update_all(
|
||||
meilisearch: GuardedData<ActionPolicy<{ actions::SETTINGS_UPDATE }>, MeiliSearch>,
|
||||
index_uid: web::Path<String>,
|
||||
body: web::Json<Settings<Unchecked>>,
|
||||
body: ValidatedJson<Settings<Unchecked>, MeiliDeserError>,
|
||||
req: HttpRequest,
|
||||
analytics: web::Data<dyn Analytics>,
|
||||
) -> Result<HttpResponse, ResponseError> {
|
||||
@ -365,7 +367,7 @@ pub async fn update_all(
|
||||
"Settings Updated".to_string(),
|
||||
json!({
|
||||
"ranking_rules": {
|
||||
"sort_position": settings.ranking_rules.as_ref().set().map(|sort| sort.iter().position(|s| s == "sort")),
|
||||
"sort_position": settings.ranking_rules.as_ref().set().map(|sort| sort.iter().position(|s| true /*TODO*/)),
|
||||
},
|
||||
"searchable_attributes": {
|
||||
"total": settings.searchable_attributes.as_ref().set().map(|searchable| searchable.len()),
|
||||
|
Reference in New Issue
Block a user