Skip to content

Commit

Permalink
feat(search): computeTermSimilarity is now not case sensitive (#850)
Browse files Browse the repository at this point in the history
Co-authored-by: Pierre-Étienne Lord <pe_lord@yahoo.ca>
  • Loading branch information
pelord and Pierre-Étienne Lord committed May 3, 2021
1 parent e53721a commit ef9e548
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions packages/geo/src/lib/search/shared/search.utils.ts
Expand Up @@ -64,14 +64,16 @@ export function findDiff(str1: string, str2: string){
return diff;
}

export function computeTermSimilarity(from, to): number {
const fromToDiff = findDiff(from, to);
const toFromDiff = findDiff(to, from);
export function computeTermSimilarity(from, to, caseSensitive: boolean = false): number {
const termFrom = caseSensitive ? from : from.toLowerCase();
const termTo = caseSensitive ? to : to.toLowerCase();
const fromToDiff = findDiff(termFrom, termTo);
const toFromDiff = findDiff(termTo, termFrom);
const totalDiff = fromToDiff + toFromDiff;

let delta = 0;
if (totalDiff.length) {
delta = totalDiff.length / from.length * 100;
delta = totalDiff.length / termFrom.length * 100;
}

return 100 - Math.floor(delta);
Expand Down

0 comments on commit ef9e548

Please sign in to comment.