blob: fc82739ce50a861545b8b462dba08c52a6ef0c23 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
pub mod vector;
pub mod dictionary;
pub mod text;
pub mod splitter;
pub mod filecache;
pub mod searchresult;
pub mod filecounter;
pub mod extractors;
pub mod index;
pub mod gui;
use index::Index;
use std::io::*;
use std::env;
fn main() {
let args: Vec<_> = env::args().collect();
if args.len() > 1 {
let cmd = args.get(1).unwrap();
if cmd == "-g" {
if args.len() != 4 {
eprintln!("{} -g <input> <indexfile>", args.get(0).unwrap());
return;
}
let input = args.get(2).unwrap();
let file = args.get(3).unwrap();
let _ = Index::generate(input, file, |counter, nof| {
eprint!("\r\x1b[2K{} of {} files indexed ({}%)", counter, nof, (counter * 100) / nof);
std::io::stdout().flush().ok();
});
} else if cmd == "-s" {
if args.len() < 4 {
eprintln!("{} -s <indexfile> ...", args.get(0).unwrap());
return;
}
let file = args.get(2).unwrap().clone();
let v = args.get(3..(args.len())).unwrap();
let search = v.join(" ");
let searchvec = splitter::split_to_words(search);
let idx = Index::from_file(file.as_str());
let results = idx.search(searchvec);
for result in results {
println!("{}", result.path);
}
}
} else {
let _ = gui::run();
}
}
|