Continue integrating Jayson

This commit is contained in:
Loïc Lecrenier
2022-06-21 14:40:01 +02:00
parent ba82584328
commit b84ea036dd
7 changed files with 49 additions and 110 deletions

View File

@ -1,7 +1,6 @@
use actix_web::{dev::Payload, web::Json, FromRequest, HttpRequest};
use futures::ready;
use jayson::{DeserializeError, DeserializeFromValue, MergeWithError, ValuePointer};
use meilisearch_lib::milli::AscDescError;
use jayson::{DeserializeError, DeserializeFromValue};
use meilisearch_types::error::{Code, ErrorCode, ResponseError};
use std::{
fmt::Debug,
@ -11,66 +10,6 @@ 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.
///

View File

@ -8,7 +8,6 @@ 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;
@ -262,27 +261,27 @@ make_setting_route!(
"distinctAttribute"
);
// make_setting_route!(
// "/ranking-rules",
// put,
// Vec<String>,
// ranking_rules,
// "rankingRules",
// analytics,
// |setting: &Option<Vec<milli::AscDesc>>, req: &HttpRequest| {
// use serde_json::json;
make_setting_route!(
"/ranking-rules",
put,
Vec<milli::Criterion>,
ranking_rules,
"rankingRules",
analytics,
|setting: &Option<Vec<milli::Criterion>>, 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| matches!(s, milli::Criterion::Sort))),
}
}),
Some(req),
);
}
);
make_setting_route!(
"/faceting",
@ -350,7 +349,7 @@ generate_configure!(
distinct_attribute,
stop_words,
synonyms,
// ranking_rules,
ranking_rules,
typo_tolerance
);
@ -367,7 +366,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| true /*TODO*/)),
"sort_position": settings.ranking_rules.as_ref().set().map(|sort| sort.iter().position(|s| matches!(s, milli::Criterion::Sort))),
},
"searchable_attributes": {
"total": settings.searchable_attributes.as_ref().set().map(|searchable| searchable.len()),