mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-07-04 20:37:15 +02:00
write the v5 dump import
This commit is contained in:
parent
22b2fa0576
commit
9d6987a412
4 changed files with 246 additions and 34 deletions
|
@ -46,13 +46,15 @@ use uuid::Uuid;
|
|||
use crate::{IndexMetadata, Result, Version};
|
||||
|
||||
use self::{
|
||||
meta::IndexUuid,
|
||||
keys::Key,
|
||||
meta::{DumpMeta, IndexUuid},
|
||||
settings::{Checked, Settings, Unchecked},
|
||||
tasks::Task,
|
||||
};
|
||||
|
||||
use super::{DumpReader, IndexReader};
|
||||
|
||||
mod keys;
|
||||
mod meta;
|
||||
mod settings;
|
||||
mod tasks;
|
||||
|
@ -75,27 +77,6 @@ pub struct V5Reader {
|
|||
index_uuid: Vec<IndexUuid>,
|
||||
}
|
||||
|
||||
struct V5IndexReader {
|
||||
metadata: IndexMetadata,
|
||||
|
||||
documents: BufReader<File>,
|
||||
settings: BufReader<File>,
|
||||
}
|
||||
|
||||
impl V5IndexReader {
|
||||
pub fn new(name: String, path: &Path) -> Result<Self> {
|
||||
let metadata = File::open(path.join("metadata.json"))?;
|
||||
|
||||
let ret = V5IndexReader {
|
||||
metadata: serde_json::from_reader(metadata)?,
|
||||
documents: BufReader::new(File::open(path.join("documents.jsonl"))?),
|
||||
settings: BufReader::new(File::open(path.join("settings.json"))?),
|
||||
};
|
||||
|
||||
Ok(ret)
|
||||
}
|
||||
}
|
||||
|
||||
impl V5Reader {
|
||||
pub fn open(dump: TempDir) -> Result<Self> {
|
||||
let meta_file = fs::read(dump.path().join("metadata.json"))?;
|
||||
|
@ -124,8 +105,7 @@ impl DumpReader for V5Reader {
|
|||
type Task = Task;
|
||||
type UpdateFile = File;
|
||||
|
||||
// TODO: remove this
|
||||
type Key = meilisearch_auth::Key;
|
||||
type Key = Key;
|
||||
|
||||
fn version(&self) -> Version {
|
||||
Version::V5
|
||||
|
@ -190,7 +170,6 @@ impl DumpReader for V5Reader {
|
|||
}))
|
||||
}
|
||||
|
||||
// TODO: do it
|
||||
fn keys(&mut self) -> Box<dyn Iterator<Item = Result<Self::Key>> + '_> {
|
||||
Box::new(
|
||||
(&mut self.keys)
|
||||
|
@ -200,6 +179,36 @@ impl DumpReader for V5Reader {
|
|||
}
|
||||
}
|
||||
|
||||
struct V5IndexReader {
|
||||
metadata: IndexMetadata,
|
||||
settings: Settings<Checked>,
|
||||
|
||||
documents: BufReader<File>,
|
||||
}
|
||||
|
||||
impl V5IndexReader {
|
||||
pub fn new(name: String, path: &Path) -> Result<Self> {
|
||||
let meta = File::open(path.join("meta.json"))?;
|
||||
let meta: DumpMeta = serde_json::from_reader(meta)?;
|
||||
|
||||
let metadata = IndexMetadata {
|
||||
uid: name,
|
||||
primary_key: meta.primary_key,
|
||||
// FIXME: Iterate over the whole task queue to find the creation and last update date.
|
||||
created_at: OffsetDateTime::now_utc(),
|
||||
updated_at: OffsetDateTime::now_utc(),
|
||||
};
|
||||
|
||||
let ret = V5IndexReader {
|
||||
metadata,
|
||||
settings: meta.settings.check(),
|
||||
documents: BufReader::new(File::open(path.join("documents.jsonl"))?),
|
||||
};
|
||||
|
||||
Ok(ret)
|
||||
}
|
||||
}
|
||||
|
||||
impl IndexReader for V5IndexReader {
|
||||
type Document = serde_json::Map<String, serde_json::Value>;
|
||||
type Settings = Settings<Checked>;
|
||||
|
@ -215,7 +224,6 @@ impl IndexReader for V5IndexReader {
|
|||
}
|
||||
|
||||
fn settings(&mut self) -> Result<Self::Settings> {
|
||||
let settings: Settings<Unchecked> = serde_json::from_reader(&mut self.settings)?;
|
||||
Ok(settings.check())
|
||||
Ok(self.settings.clone())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue