mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-22 01:57:41 +08:00
Remove primary key from top id map
This commit is contained in:
parent
663deac236
commit
2a91849660
@ -1,15 +1,14 @@
|
||||
use std::borrow::Cow;
|
||||
use std::iter;
|
||||
use std::ops::ControlFlow;
|
||||
use std::result::Result as StdResult;
|
||||
|
||||
use bumpalo::Bump;
|
||||
use serde_json::value::RawValue;
|
||||
use serde_json::{from_str, Value};
|
||||
use serde_json::Value;
|
||||
|
||||
use crate::fields_ids_map::MutFieldIdMapper;
|
||||
use crate::update::new::indexer::de::{match_component, DeOrBumpStr};
|
||||
use crate::update::new::{CowStr, KvReaderFieldId, TopLevelMap};
|
||||
use crate::update::new::KvReaderFieldId;
|
||||
use crate::{FieldId, InternalError, Object, Result, UserError};
|
||||
|
||||
/// The symbol used to define levels in a nested primary key.
|
||||
@ -230,45 +229,6 @@ impl<'a> PrimaryKey<'a> {
|
||||
Ok(external_document_id)
|
||||
}
|
||||
|
||||
/// Returns the document ID based on the primary and
|
||||
/// search for it recursively in zero-copy-deserialized documents.
|
||||
pub fn document_id_from_top_level_map<'p>(
|
||||
&self,
|
||||
document: &TopLevelMap<'p>,
|
||||
) -> Result<StdResult<CowStr<'p>, DocumentIdExtractionError>> {
|
||||
fn get_docid<'p>(
|
||||
document: &TopLevelMap<'p>,
|
||||
primary_key: &[&str],
|
||||
) -> Result<StdResult<CowStr<'p>, DocumentIdExtractionError>> {
|
||||
match primary_key {
|
||||
[] => unreachable!("arrrgh"), // would None be ok?
|
||||
[primary_key] => match document.0.get(*primary_key) {
|
||||
Some(value) => match from_str::<u64>(value.get()) {
|
||||
Ok(value) => Ok(Ok(CowStr(Cow::Owned(value.to_string())))),
|
||||
Err(_) => match from_str(value.get()) {
|
||||
Ok(document_id) => Ok(Ok(document_id)),
|
||||
Err(e) => Ok(Err(DocumentIdExtractionError::InvalidDocumentId(
|
||||
UserError::SerdeJson(e),
|
||||
))),
|
||||
},
|
||||
},
|
||||
None => Ok(Err(DocumentIdExtractionError::MissingDocumentId)),
|
||||
},
|
||||
[head, tail @ ..] => match document.0.get(*head) {
|
||||
Some(value) => {
|
||||
let document = from_str(value.get()).map_err(InternalError::SerdeJson)?;
|
||||
get_docid(&document, tail)
|
||||
}
|
||||
None => Ok(Err(DocumentIdExtractionError::MissingDocumentId)),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/// TODO do not allocate a vec everytime here
|
||||
let primary_key: Vec<_> = self.name().split(PRIMARY_KEY_SPLIT_SYMBOL).collect();
|
||||
get_docid(document, &primary_key)
|
||||
}
|
||||
|
||||
/// Returns an `Iterator` that gives all the possible fields names the primary key
|
||||
/// can have depending of the first level name and depth of the objects.
|
||||
pub fn possible_level_names(&self) -> impl Iterator<Item = (&'a str, &'a str)> + '_ {
|
||||
|
Loading…
Reference in New Issue
Block a user