diff options
| author | Nathan Reiner <nathan@nathanreiner.xyz> | 2023-07-09 22:18:14 +0200 |
|---|---|---|
| committer | Nathan Reiner <nathan@nathanreiner.xyz> | 2023-07-09 22:18:14 +0200 |
| commit | 7fc3df372f119e8c8706fca8d5b060fc13cea5b4 (patch) | |
| tree | c3c6944869dca8ec9c892e72f19006d24936305c /src/index.rs | |
| parent | 4f0b65f5eab1875edd3d4f547952e49bbc79a54d (diff) | |
add optioal prioritizer on search
Diffstat (limited to 'src/index.rs')
| -rw-r--r-- | src/index.rs | 13 |
1 files changed, 10 insertions, 3 deletions
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); } } |