feat: add search module and bulk indexing functionality

This commit is contained in:
2024-02-11 17:22:11 +01:00
parent 1891687db2
commit ffeaa97feb
4 changed files with 24 additions and 1 deletions

View File

@@ -1 +1,2 @@
pub mod hello;
pub mod hello;
pub mod search;

3
src/handler/search.rs Normal file
View File

@@ -0,0 +1,3 @@
pub fn index_new_document() {
println!("index_new_document");
}

View File

@@ -79,6 +79,12 @@ impl SearchEngine {
}
}
pub fn bulk_index(&mut self, documents: Vec<(&str, &str)>) {
for (url, content) in documents {
self.index(url, content);
}
}
pub fn get_urls(&self, keyword: &str) -> HashMap<String, i32> {
let keyword = normalize_string(keyword);
self.index.get(&keyword).cloned().unwrap_or(HashMap::new())