Move the indexer around

This commit is contained in:
Olivier 'reivilibre' 2022-03-24 19:50:20 +00:00
parent 7aa5521c5d
commit 73154e7e34
11 changed files with 71 additions and 32 deletions

17
Cargo.lock generated
View File

@ -3441,7 +3441,7 @@ dependencies = [
] ]
[[package]] [[package]]
name = "quickpeep_indexer" name = "quickpeep_index"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",
@ -3456,6 +3456,21 @@ dependencies = [
"toml", "toml",
] ]
[[package]]
name = "quickpeep_indexer"
version = "0.1.0"
dependencies = [
"anyhow",
"env_logger",
"log",
"quickpeep_index",
"quickpeep_structs",
"serde",
"serde_bare",
"tokio",
"toml",
]
[[package]] [[package]]
name = "quickpeep_moz_readability" name = "quickpeep_moz_readability"
version = "0.1.0" version = "0.1.0"

View File

@ -1,6 +1,7 @@
[workspace] [workspace]
members = [ members = [
"quickpeep", "quickpeep",
"quickpeep_index",
"quickpeep_indexer", "quickpeep_indexer",
"quickpeep_raker", "quickpeep_raker",
"quickpeep_densedoc", "quickpeep_densedoc",

View File

@ -0,0 +1,20 @@
[package]
name = "quickpeep_index"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
tantivy = "0.17.0"
meilisearch-sdk = "0.15.0"
anyhow = "1.0.56"
tokio = { version = "1.17.0", features = ["full"] }
log = "0.4.16"
env_logger = "0.9.0"
serde = { version = "1.0.136", features = ["derive"] }
serde_bare = "0.5.0"
toml = "0.5.8"
quickpeep_structs = { path = "../quickpeep_structs" }

View File

@ -1,7 +1,7 @@
use crate::backend::{Backend, BackendIndependentDocument}; use crate::backend::{Backend, BackendIndependentDocument};
use std::path::Path; use std::path::Path;
use tantivy::schema::{Schema, STORED, TEXT}; use tantivy::schema::{Schema, STORED, TEXT};
use tantivy::{doc, Index, IndexWriter}; use tantivy::{Index, IndexWriter};
fn experiment_tantivy() -> anyhow::Result<()> { fn experiment_tantivy() -> anyhow::Result<()> {
let mut schema_builder = Schema::builder(); let mut schema_builder = Schema::builder();
@ -15,7 +15,7 @@ fn experiment_tantivy() -> anyhow::Result<()> {
// schema_builder.add_bytes_field() // schema_builder.add_bytes_field()
let schema = schema_builder.build(); let schema = schema_builder.build();
let index = tantivy::Index::create_in_dir(Path::new("/tmp/tindex"), schema)?; let index = tantivy::Index::create_in_dir(Path::new("/tmp/tindex"), schema)?;
let writer = index.writer(100 * 1024 * 1024)?; let _writer = index.writer(100 * 1024 * 1024)?;
Ok(()) Ok(())
} }
@ -26,14 +26,14 @@ pub struct TantivyBackend {
} }
impl Backend for TantivyBackend { impl Backend for TantivyBackend {
fn add_document(&mut self, document: BackendIndependentDocument) -> anyhow::Result<()> { fn add_document(&mut self, _document: BackendIndependentDocument) -> anyhow::Result<()> {
self.index_writer.add_document(doc! { // self.index_writer.add_document(doc! {
"title" => document.title, // "title" => document.title,
"article" => document.article_body, // "article" => document.article_body,
"nonarticle" => document.nonarticle_body, // "nonarticle" => document.nonarticle_body,
"url" => document.url, // "url" => document.url,
"tags" => document.tags // "tags" => document.tags
})?; // })?;
todo!() todo!()
} }

View File

@ -0,0 +1,19 @@
use serde::{Deserialize, Serialize};
use std::path::PathBuf;
#[derive(Serialize, Deserialize, Debug, Clone)]
pub enum BackendConfig {
Tantivy(TantivyBackendConfig),
Meili(MeiliBackendConfig),
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct TantivyBackendConfig {
pub index_dir: PathBuf,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct MeiliBackendConfig {
pub url: String,
pub token: String,
}

View File

@ -0,0 +1,3 @@
pub mod config;
pub mod backend;

View File

@ -6,8 +6,6 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
tantivy = "0.17.0"
meilisearch-sdk = "0.15.0"
anyhow = "1.0.56" anyhow = "1.0.56"
tokio = { version = "1.17.0", features = ["full"] } tokio = { version = "1.17.0", features = ["full"] }
log = "0.4.16" log = "0.4.16"
@ -17,4 +15,5 @@ serde_bare = "0.5.0"
toml = "0.5.8" toml = "0.5.8"
quickpeep_index = { path = "../quickpeep_index" }
quickpeep_structs = { path = "../quickpeep_structs" } quickpeep_structs = { path = "../quickpeep_structs" }

View File

@ -1,4 +1,5 @@
use anyhow::Context; use anyhow::Context;
use quickpeep_index::config::BackendConfig;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
@ -32,20 +33,3 @@ impl IndexerConfig {
Ok(indexer_config) Ok(indexer_config)
} }
} }
#[derive(Serialize, Deserialize, Debug, Clone)]
pub enum BackendConfig {
Tantivy(TantivyBackendConfig),
Meili(MeiliBackendConfig),
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct TantivyBackendConfig {
index_dir: PathBuf,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct MeiliBackendConfig {
url: String,
token: String,
}

View File

@ -1,3 +1 @@
pub mod config; pub mod config;
pub mod backend;