quick_search/src/main.rs

56 lines
1.8 KiB
Rust
Raw Normal View History

2024-06-10 16:23:38 -04:00
use std::sync::{Mutex, Arc};
2024-06-10 12:45:33 -04:00
use walkdir::WalkDir;
2024-06-10 12:45:33 -04:00
use tqdm;
use rusqlite::Connection;
use dioxus::prelude::*;
2024-06-10 16:23:38 -04:00
use dpc_pariter::IteratorExt as _;
2024-06-10 12:45:33 -04:00
mod frontend;
mod file_handling;
mod document_extraction;
2024-06-10 12:45:33 -04:00
fn main() {
// launch(frontend::App);
let path: &str = "G:\\datasets\\preprocessed_ch_100";
let db_path: &str = "GDrive.db";
2024-06-10 12:45:33 -04:00
2024-06-10 13:56:01 -04:00
let conn = Connection::open(db_path).unwrap();
2024-06-10 16:23:38 -04:00
// let conn = Connection::open_in_memory().unwrap();
2024-06-10 13:56:01 -04:00
// PRAGMA cache_size is in number of pages with 1024 byte page size by default
conn.execute_batch(
"PRAGMA journal_mode = OFF;
PRAGMA synchronous = 0;
2024-06-10 16:23:38 -04:00
PRAGMA cache_size = 10000;
2024-06-10 13:56:01 -04:00
PRAGMA temp_store = MEMORY;",
)
// PRAGMA locking_mode = EXCLUSIVE;
2024-06-10 13:56:01 -04:00
.expect("PRAGMA");
2024-06-10 12:45:33 -04:00
conn.execute("CREATE TABLE IF NOT EXISTS files (
name TEXT,
path TEXT,
size INTEGER,
moddate INTEGER,
hash BLOB);", ()).unwrap();
// https://sqlite.org/fts5.html
conn.execute("CREATE VIRTUAL TABLE IF NOT EXISTS searchabletext USING fts5 (name, path, text, tokenize = 'trigram');", ()).unwrap();
2024-06-10 13:56:01 -04:00
2024-06-10 16:23:38 -04:00
let conn_mutex = Arc::new(Mutex::new(conn));
2024-06-10 13:56:01 -04:00
2024-06-10 16:23:38 -04:00
tqdm::tqdm(WalkDir::new(path).into_iter()).parallel_map(move |entry| {
match entry {
Ok(e) => file_handling::process_entry(&conn_mutex, e),
2024-06-10 16:23:38 -04:00
Err(error) => {
println!("Error with directory walk: {:?}", error);
return;
},
};
}).for_each(drop);
2024-06-10 13:56:01 -04:00
2024-06-10 18:16:28 -04:00
/*
SELECT name, hash, count(*) as cnt FROM files GROUP BY hash ORDER BY cnt DESC;
SELECT name, path, text, snippet(searchabletext, 2 , "<b>", "</b>", "...", 64) as "snip" FROM searchabletext WHERE text MATCH 'Terrasound' LIMIT 100;
2024-06-10 18:16:28 -04:00
*/
2024-06-10 12:45:33 -04:00
}