Skip to content

Commit

Permalink
Merge pull request #1431 from dimagi/fix-levenshtein-distance-algorithm
Browse files Browse the repository at this point in the history
Fix Levenshtein distance algorithm
  • Loading branch information
avazirna authored Sep 4, 2024
2 parents a615d84 + 5bc1663 commit db0ffdd
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/org/commcare/cases/util/StringUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ private static int LevenshteinDistance(String s0, String s1) {
for (int j = 1; j < len1; j++) {

// initial cost of skipping prefix in String s1
newcost[0] = j - 1;
newcost[0] = j;

// transformation cost for each letter in s0
for (int i = 1; i < len0; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,8 @@ public void testFuzzySearch() {
// false even though we have an exact substring match,
// Cuz fuzzy search starts checking from 0th location.
Assert.assertFalse(StringUtils.fuzzyMatch("Test", "CrazyTest").first);

// false since aply and cape has a difference of 3 edits add 'c', remove 'l', replace 'y' with 'e'
Assert.assertFalse(StringUtils.fuzzyMatch("aply", "cape").first);
}
}

0 comments on commit db0ffdd

Please sign in to comment.