Skip to content

Commit 6a05f1a

Browse files
wiiznokesmmstick
authored andcommitted
feat: always match exact match
1 parent d01a6cd commit 6a05f1a

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/matching.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,20 @@ where
8181

8282
let query = query.as_ref().to_lowercase();
8383

84+
let query_espaced = query.split_ascii_whitespace().collect::<Vec<_>>();
85+
8486
normalized_values
8587
.into_iter()
86-
.map(|de| strsim::jaro_winkler(&query, &de))
88+
.map(|de_field| {
89+
let jaro_score = strsim::jaro_winkler(&query, &de_field);
90+
91+
if query_espaced.iter().any(|query| de_field.contains(*query)) {
92+
// provide a bonus if the query is contained in the de field
93+
(jaro_score + 0.1).clamp(0.61, 1.)
94+
} else {
95+
jaro_score
96+
}
97+
})
8798
.max_by(|e1, e2| e1.total_cmp(e2))
8899
.unwrap_or(0.0)
89100
}

0 commit comments

Comments
 (0)