mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-05 04:28:55 +01:00
Merge #2313
2313: fix(search): remove the back and forth between the IndexMap and the serde_json::Map r=irevoire a=irevoire This is ok because we're using the preserve_order feature in serde_json which is already internally using an IndexMap. See https://github.com/meilisearch/meilisearch/pull/2298#discussion_r845228412_ Co-authored-by: Tamo <tamo@meilisearch.com>
This commit is contained in:
commit
049cf0fcee
@ -21,11 +21,11 @@ macro_rules! make_setting_route {
|
||||
use meilisearch_lib::milli::update::Setting;
|
||||
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 $crate::analytics::Analytics;
|
||||
use $crate::extractors::authentication::{policies::*, GuardedData};
|
||||
use $crate::extractors::sequential_extractor::SeqHandler;
|
||||
use $crate::task::SummarizedTaskView;
|
||||
|
||||
pub async fn delete(
|
||||
meilisearch: GuardedData<ActionPolicy<{ actions::SETTINGS_UPDATE }>, MeiliSearch>,
|
||||
|
@ -4,7 +4,6 @@ use std::str::FromStr;
|
||||
use std::time::Instant;
|
||||
|
||||
use either::Either;
|
||||
use indexmap::IndexMap;
|
||||
use milli::tokenizer::{Analyzer, AnalyzerConfig, Token};
|
||||
use milli::{AscDesc, FieldId, FieldsIdsMap, Filter, MatchingWords, SortError};
|
||||
use regex::Regex;
|
||||
@ -16,7 +15,7 @@ use crate::index::error::FacetError;
|
||||
use super::error::{IndexError, Result};
|
||||
use super::index::Index;
|
||||
|
||||
pub type Document = IndexMap<String, Value>;
|
||||
pub type Document = serde_json::Map<String, Value>;
|
||||
type MatchesInfo = BTreeMap<String, Vec<MatchInfo>>;
|
||||
|
||||
#[derive(Serialize, Debug, Clone, PartialEq)]
|
||||
@ -499,10 +498,6 @@ fn make_document(
|
||||
.map(|&fid| field_ids_map.name(fid).expect("Missing field name"));
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
@ -513,12 +508,6 @@ fn format_fields<A: AsRef<[u8]>>(
|
||||
matching_words: &impl Matcher,
|
||||
formatted_options: &BTreeMap<FieldId, FormatOptions>,
|
||||
) -> 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
|
||||
.keys()
|
||||
// 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())
|
||||
.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| {
|
||||
// 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)| {
|
||||
acc.merge(*option)
|
||||
});
|
||||
// TODO: remove this useless clone
|
||||
*value = formatter.format_value(value.clone(), matching_words, format);
|
||||
*value = formatter.format_value(std::mem::take(value), matching_words, format);
|
||||
});
|
||||
|
||||
// we need to convert back the `serde_json::Map` into an `IndexMap`.
|
||||
let document = document.into_iter().collect();
|
||||
|
||||
Ok(document)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user