mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-22 18:17:39 +08:00
Move the TopLevelMap into a dedicated module
This commit is contained in:
parent
24cb5839ad
commit
04596f3616
@ -1,16 +1,19 @@
|
|||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::collections::{BTreeMap, HashMap};
|
use std::collections::{BTreeMap, HashMap};
|
||||||
|
use std::fmt;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use heed::types::Bytes;
|
use heed::types::Bytes;
|
||||||
use heed::RoTxn;
|
use heed::RoTxn;
|
||||||
use memmap2::Mmap;
|
use memmap2::Mmap;
|
||||||
use rayon::iter::{IntoParallelIterator, ParallelIterator};
|
use rayon::iter::{IntoParallelIterator, ParallelIterator};
|
||||||
|
use serde_json::from_str;
|
||||||
use IndexDocumentsMethod as Idm;
|
use IndexDocumentsMethod as Idm;
|
||||||
|
|
||||||
use super::super::document_change::DocumentChange;
|
use super::super::document_change::DocumentChange;
|
||||||
use super::super::items_pool::ItemsPool;
|
use super::super::items_pool::ItemsPool;
|
||||||
use super::DocumentChanges;
|
use super::top_level_map::{CowStr, TopLevelMap};
|
||||||
|
use super::{top_level_map, DocumentChanges};
|
||||||
use crate::documents::PrimaryKey;
|
use crate::documents::PrimaryKey;
|
||||||
use crate::update::new::{Deletion, Insertion, KvReaderFieldId, KvWriterFieldId, Update};
|
use crate::update::new::{Deletion, Insertion, KvReaderFieldId, KvWriterFieldId, Update};
|
||||||
use crate::update::{AvailableIds, IndexDocumentsMethod};
|
use crate::update::{AvailableIds, IndexDocumentsMethod};
|
||||||
@ -395,36 +398,8 @@ impl MergeChanges for MergeDocumentForUpdates {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
use std::borrow::Borrow;
|
/// Returns the document ID based on the primary and
|
||||||
|
/// search for it recursively in zero-copy-deserialized documents.
|
||||||
use serde::Deserialize;
|
|
||||||
use serde_json::from_str;
|
|
||||||
use serde_json::value::RawValue;
|
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
|
||||||
pub struct TopLevelMap<'p>(#[serde(borrow)] BTreeMap<CowStr<'p>, &'p RawValue>);
|
|
||||||
|
|
||||||
#[derive(Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash, Clone)]
|
|
||||||
pub struct CowStr<'p>(#[serde(borrow)] Cow<'p, str>);
|
|
||||||
|
|
||||||
impl CowStr<'_> {
|
|
||||||
fn to_string(&self) -> String {
|
|
||||||
self.0.to_string()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl AsRef<str> for CowStr<'_> {
|
|
||||||
fn as_ref(&self) -> &str {
|
|
||||||
self.0.as_ref()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'doc> Borrow<str> for CowStr<'doc> {
|
|
||||||
fn borrow(&self) -> &str {
|
|
||||||
self.0.borrow()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_docid<'p>(
|
fn get_docid<'p>(
|
||||||
map: &TopLevelMap<'p>,
|
map: &TopLevelMap<'p>,
|
||||||
primary_key: &[&str],
|
primary_key: &[&str],
|
||||||
|
@ -26,6 +26,7 @@ use crate::{FieldsIdsMap, GlobalFieldsIdsMap, Index, Result, UserError};
|
|||||||
mod document_deletion;
|
mod document_deletion;
|
||||||
mod document_operation;
|
mod document_operation;
|
||||||
mod partial_dump;
|
mod partial_dump;
|
||||||
|
mod top_level_map;
|
||||||
mod update_by_function;
|
mod update_by_function;
|
||||||
|
|
||||||
pub trait DocumentChanges<'p> {
|
pub trait DocumentChanges<'p> {
|
||||||
|
30
milli/src/update/new/indexer/top_level_map.rs
Normal file
30
milli/src/update/new/indexer/top_level_map.rs
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
use std::borrow::{Borrow, Cow};
|
||||||
|
use std::collections::BTreeMap;
|
||||||
|
use std::fmt;
|
||||||
|
|
||||||
|
use serde::Deserialize;
|
||||||
|
use serde_json::value::RawValue;
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
pub struct TopLevelMap<'p>(#[serde(borrow)] pub BTreeMap<CowStr<'p>, &'p RawValue>);
|
||||||
|
|
||||||
|
#[derive(Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash, Clone)]
|
||||||
|
pub struct CowStr<'p>(#[serde(borrow)] pub Cow<'p, str>);
|
||||||
|
|
||||||
|
impl fmt::Display for CowStr<'_> {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
fmt::Display::fmt(&self.0, f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AsRef<str> for CowStr<'_> {
|
||||||
|
fn as_ref(&self) -> &str {
|
||||||
|
self.0.as_ref()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'doc> Borrow<str> for CowStr<'doc> {
|
||||||
|
fn borrow(&self) -> &str {
|
||||||
|
self.0.borrow()
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user