From 73845f87cf2e37ec61b59439b56d1106d532d4c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Lecrenier?= Date: Wed, 22 Jun 2022 15:31:04 +0200 Subject: [PATCH] Fix loading of dump v2 by patching ranking rules inside update settings --- meilisearch-lib/src/dump/loaders/v2.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/meilisearch-lib/src/dump/loaders/v2.rs b/meilisearch-lib/src/dump/loaders/v2.rs index 5926de931..d7e985b59 100644 --- a/meilisearch-lib/src/dump/loaders/v2.rs +++ b/meilisearch-lib/src/dump/loaders/v2.rs @@ -78,11 +78,17 @@ fn patch_updates(dir: impl AsRef, path: impl AsRef) -> anyhow::Resul let mut output_update_file = NamedTempFile::new_in(&dir)?; let update_file = File::open(&path)?; - let stream = Deserializer::from_reader(update_file).into_iter::(); - - for update in stream { - let update_entry = update?; + let updates = Deserializer::from_reader(update_file).into_iter::(); + for update_entry in updates { + let mut update_entry = update_entry?; + println!("{:?}", update_entry); + // We first deserialize the dump meta into a serde_json::Value and change + // the custom ranking rules settings from the old format to the new format. + if let Some(ranking_rules) = update_entry.pointer_mut("/update/meta/rankingRules") { + patch_custom_ranking_rules(ranking_rules); + } + let update_entry: v2::UpdateEntry = serde_json::from_value(update_entry)?; let update_entry = v3::UpdateEntry::from(update_entry); serde_json::to_writer(&mut output_update_file, &update_entry)?;