Skip to content

Commit

Permalink
Fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
andylokandy committed Apr 15, 2019
1 parent 5c036bc commit 34c795e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 2 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,18 @@
authors = ["andylokandy <[email protected]>"]
edition = "2018"
name = "simsearch"
version = "0.1.1"
version = "0.1.2"
license = "MIT/Apache-2.0"

description = "A simple and lightweight fuzzy search engine that works in memory, searching for similar strings (a pun here)."
documentation = "https://docs.rs/simsearch"
repository = "https://github.com/andylokandy/simsearch-rs"
homepage = "https://github.com/andylokandy/simsearch-rs"
reame = "README.md"
readme = "README.md"

keywords = ["fuzzy", "search", "lightweight", "pattern", "strsim"]
categories = ["algorithms", "text-processing"]

[badges]
travis-ci = { repository = "andylokandy/simsearch-rs" }

[dependencies]
strsim = "0.9.1"

Expand Down
17 changes: 11 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ where

self.ids.push((id, id_num));

let tokens = self.tokenize(tokens);
let mut tokens = self.tokenize(tokens);
tokens.sort();
tokens.dedup();

for token in tokens.clone() {
self.reverse_map
Expand Down Expand Up @@ -178,7 +180,9 @@ where
///
/// assert_eq!(results, &[1]);
pub fn search_tokenized(&self, pattern_tokens: &[&str]) -> Vec<Id> {
let pattern_tokens = self.tokenize(pattern_tokens);
let mut pattern_tokens = self.tokenize(pattern_tokens);
pattern_tokens.sort();
pattern_tokens.dedup();

let mut token_scores: HashMap<&str, f64> = HashMap::new();

Expand All @@ -197,10 +201,11 @@ where
+ normalized_levenshtein(&prefix_token, &pattern_token) as f64
/ prefix_len as f64)
/ 2.;
token_scores
.entry(token)
.and_modify(|current| *current = current.max(score))
.or_insert(0.);
let score_current = token_scores
.get(&token.as_str())
.map(|score| *score)
.unwrap_or(0.);
token_scores.insert(token, score_current.max(score));
}
}
}
Expand Down

0 comments on commit 34c795e

Please sign in to comment.