mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-23 05:14:27 +01:00
Change document operation to use method in primary key
This commit is contained in:
parent
c283c95f6a
commit
152683083b
@ -8,13 +8,12 @@ use IndexDocumentsMethod as Idm;
|
|||||||
|
|
||||||
use super::super::document_change::DocumentChange;
|
use super::super::document_change::DocumentChange;
|
||||||
use super::document_changes::{DocumentChangeContext, DocumentChanges, MostlySend};
|
use super::document_changes::{DocumentChangeContext, DocumentChanges, MostlySend};
|
||||||
use crate::documents::{DocumentIdExtractionError, PrimaryKey};
|
use crate::documents::PrimaryKey;
|
||||||
use crate::update::new::document::DocumentFromVersions;
|
use crate::update::new::document::DocumentFromVersions;
|
||||||
use crate::update::new::document_change::Versions;
|
use crate::update::new::document_change::Versions;
|
||||||
use crate::update::new::indexer::de::FieldAndDocidExtractor;
|
|
||||||
use crate::update::new::{Deletion, Insertion, Update};
|
use crate::update::new::{Deletion, Insertion, Update};
|
||||||
use crate::update::{AvailableIds, IndexDocumentsMethod};
|
use crate::update::{AvailableIds, IndexDocumentsMethod};
|
||||||
use crate::{external_documents_ids, DocumentId, Error, FieldsIdsMap, Index, Result, UserError};
|
use crate::{DocumentId, Error, FieldsIdsMap, Index, Result, UserError};
|
||||||
|
|
||||||
pub struct DocumentOperation<'pl> {
|
pub struct DocumentOperation<'pl> {
|
||||||
operations: Vec<Payload<'pl>>,
|
operations: Vec<Payload<'pl>>,
|
||||||
@ -77,7 +76,6 @@ impl<'pl> DocumentOperation<'pl> {
|
|||||||
primary_key: &PrimaryKey,
|
primary_key: &PrimaryKey,
|
||||||
new_fields_ids_map: &mut FieldsIdsMap,
|
new_fields_ids_map: &mut FieldsIdsMap,
|
||||||
) -> Result<DocumentOperationChanges<'pl>> {
|
) -> Result<DocumentOperationChanges<'pl>> {
|
||||||
use serde::de::Deserializer;
|
|
||||||
// will contain nodes from the intermediate hashmap
|
// will contain nodes from the intermediate hashmap
|
||||||
let document_changes_alloc = Bump::with_capacity(1024 * 1024 * 1024); // 1 MiB
|
let document_changes_alloc = Bump::with_capacity(1024 * 1024 * 1024); // 1 MiB
|
||||||
|
|
||||||
@ -97,30 +95,11 @@ impl<'pl> DocumentOperation<'pl> {
|
|||||||
while let Some(document) =
|
while let Some(document) =
|
||||||
iter.next().transpose().map_err(UserError::SerdeJson)?
|
iter.next().transpose().map_err(UserError::SerdeJson)?
|
||||||
{
|
{
|
||||||
let res = document
|
let external_document_id = primary_key.extract_fields_and_docid(
|
||||||
.deserialize_map(FieldAndDocidExtractor::new(
|
document,
|
||||||
new_fields_ids_map,
|
new_fields_ids_map,
|
||||||
primary_key,
|
indexer,
|
||||||
indexer,
|
)?;
|
||||||
))
|
|
||||||
.map_err(UserError::SerdeJson)?;
|
|
||||||
|
|
||||||
let external_document_id = match res {
|
|
||||||
Ok(document_id) => Ok(document_id),
|
|
||||||
Err(DocumentIdExtractionError::InvalidDocumentId(e)) => Err(e),
|
|
||||||
Err(DocumentIdExtractionError::MissingDocumentId) => {
|
|
||||||
Err(UserError::MissingDocumentId {
|
|
||||||
primary_key: primary_key.name().to_string(),
|
|
||||||
document: serde_json::from_str(document.get()).unwrap(),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
Err(DocumentIdExtractionError::TooManyDocumentIds(_)) => {
|
|
||||||
Err(UserError::TooManyDocumentIds {
|
|
||||||
primary_key: primary_key.name().to_string(),
|
|
||||||
document: serde_json::from_str(document.get()).unwrap(),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}?;
|
|
||||||
|
|
||||||
let external_document_id = external_document_id.to_de();
|
let external_document_id = external_document_id.to_de();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user