Skip to content

Commit

Permalink
Spellchecker now prioritizes the closest edit dist
Browse files Browse the repository at this point in the history
  • Loading branch information
elijah-potter committed Jan 28, 2024
1 parent 69fefb2 commit 359a482
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions harper-core/src/spell/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,23 @@ pub fn suggest_correct_spelling<'a>(
if a == b {
found.push(found_dist.remove(a).0);
} else {
found.push(found_dist[b].0);
found.push(found_dist.remove(a).0);
found.push(found_dist[a].0);
found.push(found_dist.remove(b).0);
if a < b {
found_dist.remove(b - 1);
found_dist.remove(a - 1);
} else {
found_dist.remove(b);
found_dist.remove(a);
}
}
}

found.extend(found_dist.into_iter().map(|v| v.0));

// Finally, swap the lowest edit distance word with the shortest.
if found.len() >= 2 {
found.swap(0, 2);
}

found
}

Expand Down

0 comments on commit 359a482

Please sign in to comment.