mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-07-04 20:37:15 +02:00
Expose the DocumentId
struct to be sure to inject the generated ids
This commit is contained in:
parent
d1a4da9812
commit
0bbcc7b180
7 changed files with 41 additions and 25 deletions
|
@ -153,8 +153,9 @@ impl<'a, 'i> Transform<'a, 'i> {
|
|||
let mapping = create_fields_mapping(&mut self.fields_ids_map, fields_index)?;
|
||||
|
||||
let primary_key = cursor.primary_key().to_string();
|
||||
self.fields_ids_map.insert(&primary_key).ok_or(UserError::AttributeLimitReached)?;
|
||||
let primary_key_id_nested = primary_key.contains('.');
|
||||
let primary_key_id =
|
||||
self.fields_ids_map.insert(&primary_key).ok_or(UserError::AttributeLimitReached)?;
|
||||
|
||||
let mut flattened_document = None;
|
||||
let mut obkv_buffer = Vec::new();
|
||||
|
@ -162,7 +163,7 @@ impl<'a, 'i> Transform<'a, 'i> {
|
|||
let mut documents_count = 0;
|
||||
let mut field_buffer: Vec<(u16, Cow<[u8]>)> = Vec::new();
|
||||
while let Some(enriched_document) = cursor.next_enriched_document()? {
|
||||
let EnrichedDocument { document, external_id } = enriched_document;
|
||||
let EnrichedDocument { document, document_id } = enriched_document;
|
||||
|
||||
let mut field_buffer_cache = drop_and_reuse(field_buffer);
|
||||
if self.indexer_settings.log_every_n.map_or(false, |len| documents_count % len == 0) {
|
||||
|
@ -171,6 +172,14 @@ impl<'a, 'i> Transform<'a, 'i> {
|
|||
});
|
||||
}
|
||||
|
||||
// When the document id has been auto-generated by the `enrich_documents_batch`
|
||||
// we must insert this document id into the remaped document.
|
||||
let external_id = document_id.value();
|
||||
if document_id.is_generated() {
|
||||
let docid = serde_json::to_vec(external_id).map_err(InternalError::SerdeJson)?;
|
||||
field_buffer_cache.push((primary_key_id, Cow::from(docid)));
|
||||
}
|
||||
|
||||
for (k, v) in document.iter() {
|
||||
let mapped_id =
|
||||
*mapping.get(&k).ok_or(InternalError::FieldIdMappingMissingEntry { key: k })?;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue