Prepare indexer

This commit is contained in:
Olivier 'reivilibre' 2022-03-24 23:19:32 +00:00
parent 7fa302b2c2
commit 4f4c3e36d1
7 changed files with 62 additions and 8 deletions

10
.gitignore vendored
View File

@ -10,7 +10,9 @@ quickpeep_static/dist
quickpeep_static/node_modules quickpeep_static/node_modules
quickpeep/testdb.sqlite quickpeep/testdb.sqlite
qp_web.ron qp_web.ron
dist /dist
book /book
workbench /workbench
rakepacks /rakepacks
/index
qp_indexer.toml

3
Cargo.lock generated
View File

@ -3461,12 +3461,15 @@ name = "quickpeep_indexer"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"clap",
"colour",
"env_logger", "env_logger",
"log", "log",
"quickpeep_index", "quickpeep_index",
"quickpeep_structs", "quickpeep_structs",
"serde", "serde",
"serde_bare", "serde_bare",
"serde_json",
"tokio", "tokio",
"toml", "toml",
] ]

View File

@ -58,6 +58,7 @@ impl TantivyBackend {
}; };
let schema = schema_builder.build(); let schema = schema_builder.build();
std::fs::create_dir(&dir_path)?;
let index = Index::create_in_dir(dir_path, schema)?; let index = Index::create_in_dir(dir_path, schema)?;
(index, fields) (index, fields)

View File

@ -2,8 +2,11 @@ use serde::{Deserialize, Serialize};
use std::path::PathBuf; use std::path::PathBuf;
#[derive(Serialize, Deserialize, Debug, Clone)] #[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(tag = "type")]
pub enum BackendConfig { pub enum BackendConfig {
#[serde(rename = "tantivy")]
Tantivy(TantivyBackendConfig), Tantivy(TantivyBackendConfig),
#[serde(rename = "meili")]
Meili(MeiliBackendConfig), Meili(MeiliBackendConfig),
} }

View File

@ -12,8 +12,10 @@ log = "0.4.16"
env_logger = "0.9.0" 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"
toml = "0.5.8" toml = "0.5.8"
clap = { version = "3.1.6", features = ["derive"] }
colour = "0.6.0"
quickpeep_index = { path = "../quickpeep_index" } quickpeep_index = { path = "../quickpeep_index" }
quickpeep_structs = { path = "../quickpeep_structs" } quickpeep_structs = { path = "../quickpeep_structs" }

View File

@ -1,6 +1,36 @@
pub struct IndexerConfig {} use anyhow::Context;
use clap::Parser;
use colour::{blue, yellow_ln};
use env_logger::Env;
use quickpeep_indexer::config::IndexerConfig;
use std::path::PathBuf;
/// Seeds a raker's queue with URLs
#[derive(Clone, Debug, Parser)]
pub struct Opts {
#[clap(long = "config")]
config: Option<PathBuf>,
rakepacks: Vec<PathBuf>,
}
pub fn main() -> anyhow::Result<()> {
env_logger::Builder::from_env(Env::default().default_filter_or("info,qp_indexer=debug")).init();
let opts: Opts = Opts::parse();
let config_path = opts
.config
.unwrap_or_else(|| PathBuf::from("qp_indexer.toml"));
let config = IndexerConfig::load(&config_path).context("Failed to load config")?;
let _indexer_backend = config.open_indexer_backend()?;
for pack in opts.rakepacks {
blue!("Indexing: ");
yellow_ln!("{:?}", pack);
}
#[tokio::main]
pub async fn main() -> anyhow::Result<()> {
Ok(()) Ok(())
} }

View File

@ -1,4 +1,6 @@
use anyhow::Context; use anyhow::Context;
use quickpeep_index::backend::tantivy::TantivyBackend;
use quickpeep_index::backend::Backend;
use quickpeep_index::config::BackendConfig; use quickpeep_index::config::BackendConfig;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
@ -32,4 +34,15 @@ impl IndexerConfig {
Ok(indexer_config) Ok(indexer_config)
} }
pub fn open_indexer_backend(&self) -> anyhow::Result<Box<dyn Backend>> {
match &self.backend {
BackendConfig::Tantivy(tantivy) => {
Ok(Box::new(TantivyBackend::open(&tantivy.index_dir)?))
}
BackendConfig::Meili(_) => {
todo!()
}
}
}
} }