mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-26 03:55:07 +08:00
Continue integrating Jayson
This commit is contained in:
parent
ba82584328
commit
b84ea036dd
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -2099,6 +2099,7 @@ dependencies = [
|
||||
"meilisearch-auth",
|
||||
"meilisearch-lib",
|
||||
"meilisearch-types",
|
||||
"milli 0.29.3",
|
||||
"mime",
|
||||
"num_cpus",
|
||||
"obkv",
|
||||
|
@ -48,6 +48,7 @@ log = "0.4.14"
|
||||
meilisearch-auth = { path = "../meilisearch-auth" }
|
||||
meilisearch-types = { path = "../meilisearch-types" }
|
||||
meilisearch-lib = { path = "../meilisearch-lib" }
|
||||
milli = { path = "../../milli/milli" }
|
||||
mime = "0.3.16"
|
||||
num_cpus = "1.13.1"
|
||||
obkv = "0.2.0"
|
||||
|
@ -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.
|
||||
///
|
||||
|
@ -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()),
|
||||
|
@ -8,7 +8,7 @@ use std::sync::Arc;
|
||||
use fst::IntoStreamer;
|
||||
use milli::heed::{EnvOpenOptions, RoTxn};
|
||||
use milli::update::{IndexerConfig, Setting};
|
||||
use milli::{obkv_to_json, AscDesc, FieldDistribution, Member, DEFAULT_VALUES_PER_FACET};
|
||||
use milli::{obkv_to_json, FieldDistribution, DEFAULT_VALUES_PER_FACET};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::{Map, Value};
|
||||
use time::OffsetDateTime;
|
||||
@ -143,11 +143,7 @@ impl Index {
|
||||
|
||||
let sortable_attributes = self.sortable_fields(txn)?.into_iter().collect();
|
||||
|
||||
let criteria = self
|
||||
.criteria(txn)?
|
||||
.into_iter()
|
||||
.map(|c| AscDesc::Asc(Member::Field("todo".to_string())))
|
||||
.collect();
|
||||
let criteria = self.criteria(txn)?;
|
||||
|
||||
let stop_words = self
|
||||
.stop_words(txn)?
|
||||
|
@ -5,8 +5,7 @@ use milli::update::{
|
||||
DocumentAdditionResult, DocumentDeletionResult, IndexDocumentsConfig, IndexDocumentsMethod,
|
||||
Setting,
|
||||
};
|
||||
use milli::{AscDesc, Criterion};
|
||||
use rayon::vec;
|
||||
use milli::Criterion;
|
||||
use serde::{Deserialize, Serialize, Serializer};
|
||||
use std::collections::{BTreeMap, BTreeSet};
|
||||
use std::marker::PhantomData;
|
||||
@ -43,8 +42,8 @@ where
|
||||
E: jayson::DeserializeError,
|
||||
{
|
||||
fn deserialize_from_value<V>(
|
||||
value: jayson::Value<V>,
|
||||
location: jayson::ValuePointerRef,
|
||||
_value: jayson::Value<V>,
|
||||
_location: jayson::ValuePointerRef,
|
||||
) -> std::result::Result<Self, E>
|
||||
where
|
||||
V: jayson::IntoValue,
|
||||
@ -147,7 +146,7 @@ pub struct Settings<T> {
|
||||
#[serde(default, skip_serializing_if = "Setting::is_not_set")]
|
||||
#[cfg_attr(test, proptest(strategy = "test::setting_strategy()"))]
|
||||
#[jayson(needs_predicate)]
|
||||
pub ranking_rules: Setting<Vec<AscDesc>>,
|
||||
pub ranking_rules: Setting<Vec<Criterion>>,
|
||||
#[serde(default, skip_serializing_if = "Setting::is_not_set")]
|
||||
#[cfg_attr(test, proptest(strategy = "test::setting_strategy()"))]
|
||||
pub stop_words: Setting<BTreeSet<String>>,
|
||||
|
@ -36,10 +36,10 @@ impl ErrorCode for MeiliDeserError {
|
||||
Code::MalformedPayload
|
||||
}
|
||||
}
|
||||
impl jayson::MergeWithError<milli::AscDescError> for MeiliDeserError {
|
||||
impl jayson::MergeWithError<milli::CriterionError> for MeiliDeserError {
|
||||
fn merge(
|
||||
self_: Option<Self>,
|
||||
other: milli::AscDescError,
|
||||
_self_: Option<Self>,
|
||||
other: milli::CriterionError,
|
||||
merge_location: jayson::ValuePointerRef,
|
||||
) -> Result<Self, Self> {
|
||||
let pointer = merge_location.to_owned();
|
||||
@ -49,9 +49,9 @@ impl jayson::MergeWithError<milli::AscDescError> for MeiliDeserError {
|
||||
|
||||
impl jayson::MergeWithError<MeiliDeserError> for MeiliDeserError {
|
||||
fn merge(
|
||||
self_: Option<Self>,
|
||||
_self_: Option<Self>,
|
||||
other: MeiliDeserError,
|
||||
merge_location: ValuePointerRef,
|
||||
_merge_location: ValuePointerRef,
|
||||
) -> Result<Self, Self> {
|
||||
Err(other)
|
||||
}
|
||||
@ -65,10 +65,10 @@ impl jayson::DeserializeError for MeiliDeserError {
|
||||
///
|
||||
/// Return `Ok` to continue deserializing or `Err` to fail early.
|
||||
fn incorrect_value_kind(
|
||||
self_: Option<Self>,
|
||||
_self_: Option<Self>,
|
||||
actual: ValueKind,
|
||||
accepted: &[ValueKind],
|
||||
location: ValuePointerRef,
|
||||
_accepted: &[ValueKind],
|
||||
_location: ValuePointerRef,
|
||||
) -> Result<Self, Self> {
|
||||
Err(MeiliDeserError(format!("incorrect value kind {actual}")))
|
||||
}
|
||||
@ -76,9 +76,9 @@ impl jayson::DeserializeError for MeiliDeserError {
|
||||
///
|
||||
/// Return `Ok` to continue deserializing or `Err` to fail early.
|
||||
fn missing_field(
|
||||
self_: Option<Self>,
|
||||
_self_: Option<Self>,
|
||||
field: &str,
|
||||
location: ValuePointerRef,
|
||||
_location: ValuePointerRef,
|
||||
) -> Result<Self, Self> {
|
||||
Err(MeiliDeserError(format!("missing field {field}")))
|
||||
}
|
||||
@ -86,17 +86,21 @@ impl jayson::DeserializeError for MeiliDeserError {
|
||||
///
|
||||
/// Return `Ok` to continue deserializing or `Err` to fail early.
|
||||
fn unknown_key(
|
||||
self_: Option<Self>,
|
||||
_self_: Option<Self>,
|
||||
key: &str,
|
||||
accepted: &[&str],
|
||||
location: ValuePointerRef,
|
||||
_accepted: &[&str],
|
||||
_location: ValuePointerRef,
|
||||
) -> Result<Self, Self> {
|
||||
Err(MeiliDeserError(format!("unknown key {key}")))
|
||||
}
|
||||
/// Create a new error with the custom message.
|
||||
///
|
||||
/// Return `Ok` to continue deserializing or `Err` to fail early.
|
||||
fn unexpected(self_: Option<Self>, msg: &str, location: ValuePointerRef) -> Result<Self, Self> {
|
||||
fn unexpected(
|
||||
_self_: Option<Self>,
|
||||
msg: &str,
|
||||
_location: ValuePointerRef,
|
||||
) -> Result<Self, Self> {
|
||||
Err(MeiliDeserError(format!("unexpected {msg}")))
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user