diff options
author | Baitinq <manuelpalenzuelamerino@gmail.com> | 2022-10-27 12:49:21 +0200 |
---|---|---|
committer | Baitinq <manuelpalenzuelamerino@gmail.com> | 2022-10-27 12:49:21 +0200 |
commit | cca92a7ad9670e46556d5b35897394a506d47373 (patch) | |
tree | ea3c19f507743e2a1d20d2db19c7bb556fe75c2a | |
parent | Indexer: Add /search with no query endpoint (diff) | |
download | OSSE-cca92a7ad9670e46556d5b35897394a506d47373.tar.gz OSSE-cca92a7ad9670e46556d5b35897394a506d47373.tar.bz2 OSSE-cca92a7ad9670e46556d5b35897394a506d47373.zip |
Crawler: Abstract database word fetching with search_word_in_db()
-rw-r--r-- | indexer/src/main.rs | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/indexer/src/main.rs b/indexer/src/main.rs index aefcc2b..d1ad867 100644 --- a/indexer/src/main.rs +++ b/indexer/src/main.rs @@ -109,12 +109,13 @@ async fn search(data: web::Data<AppState>, term: web::Path<String>) -> impl Resp let mut valid_results: Option<HashSet<CrawledResource>> = None; for w in query { - let curr_word_results = match database.get(w) { + let curr_word_results = match search_word_in_db(&database, w) { None => return "[]".to_string(), - Some(results) => results, + Some(curr_results) => curr_results, }; match valid_results { + //Initialise valid_results None => { valid_results = Some(curr_word_results.to_owned()); } @@ -131,6 +132,13 @@ async fn search(data: web::Data<AppState>, term: web::Path<String>) -> impl Resp serde_json::to_string(&valid_results.unwrap()).unwrap() } +fn search_word_in_db<'a>( + db: &'a HashMap<String, HashSet<CrawledResource>>, + word: &'a str, +) -> Option<&'a HashSet<CrawledResource>> { + db.get(word) +} + //TODO! fn calculate_word_priority(_word: &str, _html_site: &str) -> u32 { rand::thread_rng().gen::<u32>() |