From df356da498b177343b23167252af059193506fe8 Mon Sep 17 00:00:00 2001 From: Olivier 'reivilibre Date: Wed, 6 Apr 2022 21:49:40 +0100 Subject: [PATCH] Use the unified config in the indexer --- .gitignore | 4 +++- Cargo.lock | 2 +- quickpeep.sample.ron | 6 ++++-- quickpeep_indexer/Cargo.toml | 2 +- quickpeep_indexer/src/bin/qp-indexer.rs | 4 ++-- quickpeep_indexer/src/config.rs | 13 +++++++++---- 6 files changed, 20 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index 0ade8bf..e335f2a 100644 --- a/.gitignore +++ b/.gitignore @@ -19,4 +19,6 @@ qp_indexer.toml nix_flake/result nix_flake/test_vm/nixos.qcow2 nix_flake/test_vm/result -quickpeep.ron \ No newline at end of file +quickpeep.ron +index_icons +index_icons-lck \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 6c425e8..28137ac 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3746,12 +3746,12 @@ dependencies = [ "quickpeep_seed_parser", "quickpeep_structs", "quickpeep_utils", + "ron", "serde", "serde_bare", "serde_json", "smartstring", "tokio", - "toml", "url", "zstd", ] diff --git a/quickpeep.sample.ron b/quickpeep.sample.ron index ccb641b..31a9bae 100644 --- a/quickpeep.sample.ron +++ b/quickpeep.sample.ron @@ -67,8 +67,10 @@ // Index (indexer, web) index: ( - type: "tantivy", - index_dir: "./index", + backend: ( + type: "tantivy", + index_dir: "./index", + ), icon_store: "./index_icons" ), diff --git a/quickpeep_indexer/Cargo.toml b/quickpeep_indexer/Cargo.toml index 333d2d7..c0f12b5 100644 --- a/quickpeep_indexer/Cargo.toml +++ b/quickpeep_indexer/Cargo.toml @@ -15,7 +15,7 @@ env_logger = "0.9.0" serde = { version = "1.0.136", features = ["derive"] } serde_bare = "0.5.0" serde_json = "1.0.79" -toml = "0.5.8" +ron = "0.7.0" clap = { version = "3.1.6", features = ["derive"] } colour = "0.6.0" url = "2.2.2" diff --git a/quickpeep_indexer/src/bin/qp-indexer.rs b/quickpeep_indexer/src/bin/qp-indexer.rs index 7993228..953fba9 100644 --- a/quickpeep_indexer/src/bin/qp-indexer.rs +++ b/quickpeep_indexer/src/bin/qp-indexer.rs @@ -41,10 +41,10 @@ pub async fn main() -> anyhow::Result<()> { let config_path = opts .config - .unwrap_or_else(|| PathBuf::from("qp_indexer.toml")); + .unwrap_or_else(|| PathBuf::from("quickpeep.ron")); let config = IndexerConfig::load(&config_path).context("Failed to load config")?; - let icon_store = IconStore::open(config.icon_store.as_path())?; + let icon_store = IconStore::open(config.index.icon_store.as_path())?; let seed_files = find_seed_files(config.seed_dir.clone(), SEED_EXTENSION).await?; let (seed_tx, seed_rx) = tokio::sync::mpsc::channel(64); diff --git a/quickpeep_indexer/src/config.rs b/quickpeep_indexer/src/config.rs index 4c231ef..a8fd71a 100644 --- a/quickpeep_indexer/src/config.rs +++ b/quickpeep_indexer/src/config.rs @@ -12,6 +12,11 @@ pub struct IndexerConfig { /// Path to seeds pub seed_dir: PathBuf, + pub index: IndexerOnlyConfig, +} + +#[derive(Serialize, Deserialize, Debug, Clone)] +pub struct IndexerOnlyConfig { /// Path to the icon store pub icon_store: PathBuf, @@ -25,11 +30,11 @@ impl IndexerConfig { pub fn load(path: &Path) -> anyhow::Result { let config_dir = path.parent().context("Can't get parent of config file.")?; let bytes = std::fs::read(path)?; - let mut indexer_config: IndexerConfig = toml::from_slice(&bytes)?; + let mut indexer_config: IndexerConfig = ron::de::from_bytes(&bytes)?; indexer_config.seed_dir = config_dir.join(indexer_config.seed_dir); - indexer_config.icon_store = config_dir.join(indexer_config.icon_store); - match &mut indexer_config.backend { + indexer_config.index.icon_store = config_dir.join(indexer_config.index.icon_store); + match &mut indexer_config.index.backend { BackendConfig::Tantivy(tantivy) => { tantivy.index_dir = config_dir.join(&tantivy.index_dir); } @@ -40,7 +45,7 @@ impl IndexerConfig { } pub fn open_indexer_backend(&self) -> anyhow::Result> { - match &self.backend { + match &self.index.backend { BackendConfig::Tantivy(tantivy) => { Ok(Box::new(TantivyBackend::open(&tantivy.index_dir)?)) }