diff options
author | Baitinq <manuelpalenzuelamerino@gmail.com> | 2022-11-04 15:44:59 +0100 |
---|---|---|
committer | Baitinq <manuelpalenzuelamerino@gmail.com> | 2022-11-04 15:44:59 +0100 |
commit | 09b038e8da139fe306abdf6592a8fa83c0892eaa (patch) | |
tree | 582c1c6d6535965713e2343090fcda443f062b12 /indexer/src/indexer_implementation.rs | |
parent | Indexer: Add missing /search/ route (diff) | |
download | OSSE-09b038e8da139fe306abdf6592a8fa83c0892eaa.tar.gz OSSE-09b038e8da139fe306abdf6592a8fa83c0892eaa.tar.bz2 OSSE-09b038e8da139fe306abdf6592a8fa83c0892eaa.zip |
Indexer: Make & implement the trait insert() taking a [word] for insert
This has the advantage of taking less calls to the insert() and being able to add all the logic previous to inertion to the actual Indexer implementation.
Diffstat (limited to 'indexer/src/indexer_implementation.rs')
-rw-r--r-- | indexer/src/indexer_implementation.rs | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/indexer/src/indexer_implementation.rs b/indexer/src/indexer_implementation.rs index d5cfead..e3f0495 100644 --- a/indexer/src/indexer_implementation.rs +++ b/indexer/src/indexer_implementation.rs @@ -28,27 +28,28 @@ impl IndexerImplementation { impl crate::Indexer for IndexerImplementation { fn insert( &mut self, - word: &str, + words: &[String], url: &str, title: Option<String>, description: Option<String>, content: &str, - fixed_words: &[String], ) -> Result<(), String> { - let resource_to_add = IndexedResource { - url: url.to_string(), - priority: Self::calculate_word_priority(word, content, fixed_words), - word: Arc::new(word.to_string()), - title: title.map(String::from), - description: description.map(String::from), - }; + for word in words { + let resource_to_add = IndexedResource { + url: url.to_string(), + priority: Self::calculate_word_priority(word, content, words), + word: Arc::new(word.to_string()), + title: title.as_ref().map(String::from), + description: description.as_ref().map(String::from), + }; - match self.database.get_mut(word) { - Some(resources) => _ = resources.insert(resource_to_add), - None => { - _ = self - .database - .insert(word.to_string(), HashSet::from([resource_to_add])) + match self.database.get_mut(word) { + Some(resources) => _ = resources.insert(resource_to_add), + None => { + _ = self + .database + .insert(word.to_string(), HashSet::from([resource_to_add])) + } } } |