Use the unified config in the indexer
This commit is contained in:
parent
4fd2dc393e
commit
df356da498
|
@ -20,3 +20,5 @@ nix_flake/result
|
||||||
nix_flake/test_vm/nixos.qcow2
|
nix_flake/test_vm/nixos.qcow2
|
||||||
nix_flake/test_vm/result
|
nix_flake/test_vm/result
|
||||||
quickpeep.ron
|
quickpeep.ron
|
||||||
|
index_icons
|
||||||
|
index_icons-lck
|
|
@ -3746,12 +3746,12 @@ dependencies = [
|
||||||
"quickpeep_seed_parser",
|
"quickpeep_seed_parser",
|
||||||
"quickpeep_structs",
|
"quickpeep_structs",
|
||||||
"quickpeep_utils",
|
"quickpeep_utils",
|
||||||
|
"ron",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_bare",
|
"serde_bare",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"smartstring",
|
"smartstring",
|
||||||
"tokio",
|
"tokio",
|
||||||
"toml",
|
|
||||||
"url",
|
"url",
|
||||||
"zstd",
|
"zstd",
|
||||||
]
|
]
|
||||||
|
|
|
@ -67,8 +67,10 @@
|
||||||
|
|
||||||
// Index (indexer, web)
|
// Index (indexer, web)
|
||||||
index: (
|
index: (
|
||||||
|
backend: (
|
||||||
type: "tantivy",
|
type: "tantivy",
|
||||||
index_dir: "./index",
|
index_dir: "./index",
|
||||||
|
),
|
||||||
icon_store: "./index_icons"
|
icon_store: "./index_icons"
|
||||||
),
|
),
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ env_logger = "0.9.0"
|
||||||
serde = { version = "1.0.136", features = ["derive"] }
|
serde = { version = "1.0.136", features = ["derive"] }
|
||||||
serde_bare = "0.5.0"
|
serde_bare = "0.5.0"
|
||||||
serde_json = "1.0.79"
|
serde_json = "1.0.79"
|
||||||
toml = "0.5.8"
|
ron = "0.7.0"
|
||||||
clap = { version = "3.1.6", features = ["derive"] }
|
clap = { version = "3.1.6", features = ["derive"] }
|
||||||
colour = "0.6.0"
|
colour = "0.6.0"
|
||||||
url = "2.2.2"
|
url = "2.2.2"
|
||||||
|
|
|
@ -41,10 +41,10 @@ pub async fn main() -> anyhow::Result<()> {
|
||||||
|
|
||||||
let config_path = opts
|
let config_path = opts
|
||||||
.config
|
.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 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_files = find_seed_files(config.seed_dir.clone(), SEED_EXTENSION).await?;
|
||||||
let (seed_tx, seed_rx) = tokio::sync::mpsc::channel(64);
|
let (seed_tx, seed_rx) = tokio::sync::mpsc::channel(64);
|
||||||
|
|
|
@ -12,6 +12,11 @@ pub struct IndexerConfig {
|
||||||
/// Path to seeds
|
/// Path to seeds
|
||||||
pub seed_dir: PathBuf,
|
pub seed_dir: PathBuf,
|
||||||
|
|
||||||
|
pub index: IndexerOnlyConfig,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
|
pub struct IndexerOnlyConfig {
|
||||||
/// Path to the icon store
|
/// Path to the icon store
|
||||||
pub icon_store: PathBuf,
|
pub icon_store: PathBuf,
|
||||||
|
|
||||||
|
@ -25,11 +30,11 @@ impl IndexerConfig {
|
||||||
pub fn load(path: &Path) -> anyhow::Result<IndexerConfig> {
|
pub fn load(path: &Path) -> anyhow::Result<IndexerConfig> {
|
||||||
let config_dir = path.parent().context("Can't get parent of config file.")?;
|
let config_dir = path.parent().context("Can't get parent of config file.")?;
|
||||||
let bytes = std::fs::read(path)?;
|
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.seed_dir = config_dir.join(indexer_config.seed_dir);
|
||||||
indexer_config.icon_store = config_dir.join(indexer_config.icon_store);
|
indexer_config.index.icon_store = config_dir.join(indexer_config.index.icon_store);
|
||||||
match &mut indexer_config.backend {
|
match &mut indexer_config.index.backend {
|
||||||
BackendConfig::Tantivy(tantivy) => {
|
BackendConfig::Tantivy(tantivy) => {
|
||||||
tantivy.index_dir = config_dir.join(&tantivy.index_dir);
|
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>> {
|
pub fn open_indexer_backend(&self) -> anyhow::Result<Box<dyn Backend>> {
|
||||||
match &self.backend {
|
match &self.index.backend {
|
||||||
BackendConfig::Tantivy(tantivy) => {
|
BackendConfig::Tantivy(tantivy) => {
|
||||||
Ok(Box::new(TantivyBackend::open(&tantivy.index_dir)?))
|
Ok(Box::new(TantivyBackend::open(&tantivy.index_dir)?))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue