diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/gui/mod.rs | 6 | ||||
| -rw-r--r-- | src/index.rs | 13 | ||||
| -rw-r--r-- | src/vector.rs | 13 |
3 files changed, 27 insertions, 5 deletions
diff --git a/src/gui/mod.rs b/src/gui/mod.rs index 6f88923..0dcf430 100644 --- a/src/gui/mod.rs +++ b/src/gui/mod.rs @@ -25,7 +25,7 @@ static GENERATE_STATUS : Lazy<Mutex<GenState>> = Lazy::new(|| { Mutex::new(GenSt pub fn run() -> iced::Result { App::run(Settings { window: window::Settings { - size: (500, 800), + size: (1000, 800), ..window::Settings::default() }, ..Settings::default() @@ -256,7 +256,9 @@ impl Application for App { let res : Element<Message> = if results.is_empty() { column![text("There are no results")].spacing(10).into() } else { - let lines : Vec<Element<_>> = results.iter().map(|r| text(r.path.clone()).into()).collect(); + let lines : Vec<Element<_>> = results.iter() + .map(|r| row![text(r.priority).width(Length::Fixed(50.0)), text(r.path.clone())].into()) + .collect(); column(lines).spacing(10).into() }; diff --git a/src/index.rs b/src/index.rs index 98a174b..5d420db 100644 --- a/src/index.rs +++ b/src/index.rs @@ -248,10 +248,16 @@ impl Index { pub fn search(&self, search_args : Vec<String>) -> Vec<SearchResult> { let mut v : FileVector = FileVector::new(); + let mut opt : FileVector = FileVector::new(); for arg in search_args { - if let Some(value) = self.dictionary.get(&arg) { - v.insert(*value, 1); + let a = arg.trim_start_matches("+"); + if let Some(value) = self.dictionary.get(&a.to_string()) { + if arg.chars().nth(0).unwrap() == '+' { + opt.insert(*value, 1); + } else { + v.insert(*value, 1); + } } } @@ -259,8 +265,9 @@ impl Index { for filecache in self.filecache.iter() { let mut r = SearchResult { priority : 0, path : filecache.path.clone() }; - r.priority = vector::scalar_product(&v, &filecache.vector); + r.priority = vector::match_vector(&v, &filecache.vector); if r.priority > 0 { + r.priority += vector::scalar_product(&opt, &filecache.vector); results.push(r); } } diff --git a/src/vector.rs b/src/vector.rs index dfd2d71..c058490 100644 --- a/src/vector.rs +++ b/src/vector.rs @@ -68,3 +68,16 @@ pub fn scalar_product(a : &FileVector, b : &FileVector) -> u64 { } c } + +pub fn match_vector(query : &FileVector, v : &FileVector) -> u64 { + let mut c = 0; + for (i, x) in query.iter() { + let s = x * (v.get(i).unwrap_or(&0)); + if s == 0 { + return 0 + } else { + c += s; + } + } + c +} |