2024-06-10 16:23:38 -04:00
|
|
|
use std::sync::{Mutex, Arc};
|
2024-06-10 12:45:33 -04:00
|
|
|
|
2025-09-11 13:42:18 -04:00
|
|
|
use walkdir::WalkDir;
|
2024-06-10 12:45:33 -04:00
|
|
|
use tqdm;
|
2025-09-11 13:42:18 -04:00
|
|
|
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
|
|
|
|
2025-09-11 13:42:18 -04:00
|
|
|
mod frontend;
|
|
|
|
|
mod file_handling;
|
|
|
|
|
mod document_extraction;
|
2024-06-10 12:45:33 -04:00
|
|
|
|
|
|
|
|
fn main() {
|
2025-09-11 13:42:18 -04:00
|
|
|
// 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;",
|
|
|
|
|
)
|
2025-09-11 13:42:18 -04:00
|
|
|
// 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,
|
2025-09-11 13:42:18 -04:00
|
|
|
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 {
|
2025-09-11 13:42:18 -04:00
|
|
|
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
|
|
|
/*
|
2025-09-11 13:42:18 -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
|
|
|
}
|