mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-30 00:34:26 +01:00
fix(search): remove the back and forth between the IndexMap and the serde_json::Map
This is ok because we're using the preserve_order feature in serde_json which is already internally using an IndexMap.
This commit is contained in:
parent
f67167fa9f
commit
2ee210483f
@ -21,11 +21,11 @@ macro_rules! make_setting_route {
|
|||||||
use meilisearch_lib::milli::update::Setting;
|
use meilisearch_lib::milli::update::Setting;
|
||||||
use meilisearch_lib::{index::Settings, index_controller::Update, MeiliSearch};
|
use meilisearch_lib::{index::Settings, index_controller::Update, MeiliSearch};
|
||||||
|
|
||||||
use crate::analytics::Analytics;
|
|
||||||
use crate::extractors::authentication::{policies::*, GuardedData};
|
|
||||||
use crate::extractors::sequential_extractor::SeqHandler;
|
|
||||||
use crate::task::SummarizedTaskView;
|
|
||||||
use meilisearch_error::ResponseError;
|
use meilisearch_error::ResponseError;
|
||||||
|
use $crate::analytics::Analytics;
|
||||||
|
use $crate::extractors::authentication::{policies::*, GuardedData};
|
||||||
|
use $crate::extractors::sequential_extractor::SeqHandler;
|
||||||
|
use $crate::task::SummarizedTaskView;
|
||||||
|
|
||||||
pub async fn delete(
|
pub async fn delete(
|
||||||
meilisearch: GuardedData<ActionPolicy<{ actions::SETTINGS_UPDATE }>, MeiliSearch>,
|
meilisearch: GuardedData<ActionPolicy<{ actions::SETTINGS_UPDATE }>, MeiliSearch>,
|
||||||
|
@ -4,7 +4,6 @@ use std::str::FromStr;
|
|||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
use either::Either;
|
use either::Either;
|
||||||
use indexmap::IndexMap;
|
|
||||||
use milli::tokenizer::{Analyzer, AnalyzerConfig, Token};
|
use milli::tokenizer::{Analyzer, AnalyzerConfig, Token};
|
||||||
use milli::{AscDesc, FieldId, FieldsIdsMap, Filter, MatchingWords, SortError};
|
use milli::{AscDesc, FieldId, FieldsIdsMap, Filter, MatchingWords, SortError};
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
@ -16,7 +15,7 @@ use crate::index::error::FacetError;
|
|||||||
use super::error::{IndexError, Result};
|
use super::error::{IndexError, Result};
|
||||||
use super::index::Index;
|
use super::index::Index;
|
||||||
|
|
||||||
pub type Document = IndexMap<String, Value>;
|
pub type Document = serde_json::Map<String, Value>;
|
||||||
type MatchesInfo = BTreeMap<String, Vec<MatchInfo>>;
|
type MatchesInfo = BTreeMap<String, Vec<MatchInfo>>;
|
||||||
|
|
||||||
#[derive(Serialize, Debug, Clone, PartialEq)]
|
#[derive(Serialize, Debug, Clone, PartialEq)]
|
||||||
@ -499,10 +498,6 @@ fn make_document(
|
|||||||
.map(|&fid| field_ids_map.name(fid).expect("Missing field name"));
|
.map(|&fid| field_ids_map.name(fid).expect("Missing field name"));
|
||||||
|
|
||||||
let document = permissive_json_pointer::select_values(&document, attributes_to_retrieve);
|
let document = permissive_json_pointer::select_values(&document, attributes_to_retrieve);
|
||||||
|
|
||||||
// then we need to convert the `serde_json::Map` into an `IndexMap`.
|
|
||||||
let document = document.into_iter().collect();
|
|
||||||
|
|
||||||
Ok(document)
|
Ok(document)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -513,12 +508,6 @@ fn format_fields<A: AsRef<[u8]>>(
|
|||||||
matching_words: &impl Matcher,
|
matching_words: &impl Matcher,
|
||||||
formatted_options: &BTreeMap<FieldId, FormatOptions>,
|
formatted_options: &BTreeMap<FieldId, FormatOptions>,
|
||||||
) -> Result<Document> {
|
) -> Result<Document> {
|
||||||
// Convert the `IndexMap` into a `serde_json::Map`.
|
|
||||||
let document = document
|
|
||||||
.iter()
|
|
||||||
.map(|(k, v)| (k.clone(), v.clone()))
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
let selectors: Vec<_> = formatted_options
|
let selectors: Vec<_> = formatted_options
|
||||||
.keys()
|
.keys()
|
||||||
// This unwrap must be safe since we got the ids from the fields_ids_map just
|
// This unwrap must be safe since we got the ids from the fields_ids_map just
|
||||||
@ -526,7 +515,7 @@ fn format_fields<A: AsRef<[u8]>>(
|
|||||||
.map(|&fid| field_ids_map.name(fid).unwrap())
|
.map(|&fid| field_ids_map.name(fid).unwrap())
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let mut document = permissive_json_pointer::select_values(&document, selectors.iter().copied());
|
let mut document = permissive_json_pointer::select_values(document, selectors.iter().copied());
|
||||||
|
|
||||||
permissive_json_pointer::map_leaf_values(&mut document, selectors, |key, value| {
|
permissive_json_pointer::map_leaf_values(&mut document, selectors, |key, value| {
|
||||||
// To get the formatting option of each key we need to see all the rules that applies
|
// To get the formatting option of each key we need to see all the rules that applies
|
||||||
@ -542,13 +531,9 @@ fn format_fields<A: AsRef<[u8]>>(
|
|||||||
.fold(FormatOptions::default(), |acc, (_, option)| {
|
.fold(FormatOptions::default(), |acc, (_, option)| {
|
||||||
acc.merge(*option)
|
acc.merge(*option)
|
||||||
});
|
});
|
||||||
// TODO: remove this useless clone
|
*value = formatter.format_value(std::mem::take(value), matching_words, format);
|
||||||
*value = formatter.format_value(value.clone(), matching_words, format);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// we need to convert back the `serde_json::Map` into an `IndexMap`.
|
|
||||||
let document = document.into_iter().collect();
|
|
||||||
|
|
||||||
Ok(document)
|
Ok(document)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user