Skip to content

Commit

Permalink
feature: fix typo issues
Browse files Browse the repository at this point in the history
  • Loading branch information
densumesh authored and skeptrunedev committed Sep 6, 2024
1 parent cb84cef commit 39bff18
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
12 changes: 6 additions & 6 deletions frontends/search/src/hooks/useSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ const initalState: SearchOptions = {
pageSize: 10,
getTotalPages: false,
correctTypos: false,
oneTypoWordRangeMin: 5,
oneTypoWordRangeMax: 8,
twoTypoWordRangeMin: 8,
oneTypoWordRangeMin: 4,
oneTypoWordRangeMax: 6,
twoTypoWordRangeMin: 6,
twoTypoWordRangeMax: null,
prioritize_domain_specifc_words: true,
disableOnWords: [],
Expand Down Expand Up @@ -139,7 +139,7 @@ const fromStateToParams = (state: SearchOptions): Params => {
getTotalPages: state.getTotalPages.toString(),
correctTypos: state.correctTypos.toString(),
oneTypoWordRangeMin: state.oneTypoWordRangeMin.toString(),
oneTypoWordRangeMax: state.oneTypoWordRangeMax?.toString() ?? "8",
oneTypoWordRangeMax: state.oneTypoWordRangeMax?.toString() ?? "6",
twoTypoWordRangeMin: state.twoTypoWordRangeMin.toString(),
twoTypoWordRangeMax: state.twoTypoWordRangeMax?.toString() ?? "",
prioritize_domain_specifc_words:
Expand Down Expand Up @@ -184,9 +184,9 @@ const fromParamsToState = (
pageSize: parseInt(params.pageSize ?? "10"),
getTotalPages: (params.getTotalPages ?? "false") === "true",
correctTypos: (params.correctTypos ?? "false") === "true",
oneTypoWordRangeMin: parseInt(params.oneTypoWordRangeMin ?? "5"),
oneTypoWordRangeMin: parseInt(params.oneTypoWordRangeMin ?? "4"),
oneTypoWordRangeMax: parseIntOrNull(params.oneTypoWordRangeMax),
twoTypoWordRangeMin: parseInt(params.oneTypoWordRangeMin ?? "8"),
twoTypoWordRangeMin: parseInt(params.oneTypoWordRangeMin ?? "6"),
twoTypoWordRangeMax: parseIntOrNull(params.twoTypoWordRangeMax),
prioritize_domain_specifc_words:
(params.prioritize_domain_specifc_words ?? "true") === "true",
Expand Down
14 changes: 8 additions & 6 deletions server/src/operators/typo_operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -599,14 +599,14 @@ fn correct_query_helper(
.collect();

let single_typo_range = options.one_typo_word_range.clone().unwrap_or(TypoRange {
min: 5,
max: Some(8),
min: 4,
max: Some(6),
});

let two_typo_range = options
.two_typo_word_range
.clone()
.unwrap_or(TypoRange { min: 8, max: None });
.unwrap_or(TypoRange { min: 6, max: None });

for &word in &query_words {
if corrections.contains_key(word) {
Expand Down Expand Up @@ -661,7 +661,7 @@ fn correct_query_helper(
best_correction = None;
break;
}
if !is_best_correction(word, correction) {
if !is_best_correction(word.to_lowercase(), correction.to_string()) {
continue;
}

Expand Down Expand Up @@ -703,7 +703,7 @@ fn correct_query_helper(
}
}

fn is_best_correction(word: &str, correction: &str) -> bool {
fn is_best_correction(word: String, correction: String) -> bool {
// Length-based filter
let len_diff = (word.len() as i32 - correction.len() as i32).abs();
if len_diff > 2 {
Expand All @@ -712,7 +712,9 @@ fn is_best_correction(word: &str, correction: &str) -> bool {

// Prefix matching (adjust the length as needed)
let prefix_len = std::cmp::min(1, std::cmp::min(word.len(), correction.len()));
if word[..prefix_len] != correction[..prefix_len] {
if word.chars().take(prefix_len).collect::<Vec<_>>()
!= correction.chars().take(prefix_len).collect::<Vec<_>>()
{
return false;
}

Expand Down

0 comments on commit 39bff18

Please sign in to comment.