Use the unified config in the indexer

This commit is contained in:
Olivier 'reivilibre' 2022-04-06 21:49:40 +01:00
parent 4fd2dc393e
commit df356da498
6 changed files with 20 additions and 11 deletions

4
.gitignore vendored
View File

@ -19,4 +19,6 @@ qp_indexer.toml
nix_flake/result
nix_flake/test_vm/nixos.qcow2
nix_flake/test_vm/result
quickpeep.ron
quickpeep.ron
index_icons
index_icons-lck

2
Cargo.lock generated
View File

@ -3746,12 +3746,12 @@ dependencies = [
"quickpeep_seed_parser",
"quickpeep_structs",
"quickpeep_utils",
"ron",
"serde",
"serde_bare",
"serde_json",
"smartstring",
"tokio",
"toml",
"url",
"zstd",
]

View File

@ -67,8 +67,10 @@
// Index (indexer, web)
index: (
type: "tantivy",
index_dir: "./index",
backend: (
type: "tantivy",
index_dir: "./index",
),
icon_store: "./index_icons"
),

View File

@ -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"

View File

@ -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);

View File

@ -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<IndexerConfig> {
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<Box<dyn Backend>> {
match &self.backend {
match &self.index.backend {
BackendConfig::Tantivy(tantivy) => {
Ok(Box::new(TantivyBackend::open(&tantivy.index_dir)?))
}