@@ -31,7 +31,7 @@ const UNMATCHED_LETTER_PENALTY = -1; | |||||
* @returns [boolean, number] a boolean which tells if pattern was | * @returns [boolean, number] a boolean which tells if pattern was | ||||
* found or not and a search score | * found or not and a search score | ||||
*/ | */ | ||||
function fuzzy_match(pattern, str) { | |||||
export function fuzzy_match(pattern, str) { | |||||
const recursion_count = 0; | const recursion_count = 0; | ||||
const recursion_limit = 10; | const recursion_limit = 10; | ||||
const matches = []; | const matches = []; | ||||
@@ -42,7 +42,7 @@ function fuzzy_match(pattern, str) { | |||||
str, | str, | ||||
0 /* pattern_cur_index */, | 0 /* pattern_cur_index */, | ||||
0 /* str_curr_index */, | 0 /* str_curr_index */, | ||||
null /* src_matces */, | |||||
null /* src_matches */, | |||||
matches, | matches, | ||||
max_matches, | max_matches, | ||||
0 /* next_match */, | 0 /* next_match */, | ||||
@@ -56,7 +56,7 @@ function fuzzy_match_recursive( | |||||
str, | str, | ||||
pattern_cur_index, | pattern_cur_index, | ||||
str_curr_index, | str_curr_index, | ||||
src_matces, | |||||
src_matches, | |||||
matches, | matches, | ||||
max_matches, | max_matches, | ||||
next_match, | next_match, | ||||
@@ -91,8 +91,8 @@ function fuzzy_match_recursive( | |||||
return [false, out_score]; | return [false, out_score]; | ||||
} | } | ||||
if (first_match && src_matces) { | |||||
matches = [...src_matces]; | |||||
if (first_match && src_matches) { | |||||
matches = [...src_matches]; | |||||
first_match = false; | first_match = false; | ||||
} | } | ||||
@@ -116,7 +116,7 @@ function fuzzy_match_recursive( | |||||
best_recursive_matches = [...recursive_matches]; | best_recursive_matches = [...recursive_matches]; | ||||
best_recursive_score = recursive_score; | best_recursive_score = recursive_score; | ||||
} | } | ||||
recursiveMatch = true; | |||||
recursive_match = true; | |||||
} | } | ||||
matches[next_match++] = str_curr_index; | matches[next_match++] = str_curr_index; | ||||
@@ -189,8 +189,3 @@ function fuzzy_match_recursive( | |||||
} | } | ||||
return [false, out_score]; | return [false, out_score]; | ||||
} | } | ||||
module.exports = { | |||||
fuzzy_match | |||||
}; |
@@ -540,36 +540,36 @@ frappe.search.utils = { | |||||
}, | }, | ||||
bolden_match_part: function(str, subseq) { | bolden_match_part: function(str, subseq) { | ||||
if(fuzzy_match(subseq, str)[0] === false) { | |||||
if (fuzzy_match(subseq, str)[0] === false) { | |||||
return str; | return str; | ||||
} | } | ||||
if(str.indexOf(subseq) == 0) { | |||||
var tail = str.split(subseq)[1]; | |||||
return '<mark>' + subseq + '</mark>' + tail; | |||||
if (str.indexOf(subseq) == 0) { | |||||
var tail = str.split(subseq)[1]; | |||||
return '<mark>' + subseq + '</mark>' + tail; | |||||
} | } | ||||
var rendered = ""; | var rendered = ""; | ||||
var str_orig = str; | var str_orig = str; | ||||
var str = str.toLowerCase(); | |||||
var str_len = str.length; | var str_len = str.length; | ||||
var subseq = subseq.toLowerCase(); | |||||
outer: for(var i = 0, j = 0; i < subseq.length; i++) { | |||||
var sub_ch = subseq.charCodeAt(i); | |||||
while(j < str_len) { | |||||
if(str.charCodeAt(j) === sub_ch) { | |||||
var str_char = str_orig.charAt(j); | |||||
if(str_char === str_char.toLowerCase()) { | |||||
rendered += '<mark>' + subseq.charAt(i) + '</mark>'; | |||||
} else { | |||||
rendered += '<mark>' + subseq.charAt(i).toUpperCase() + '</mark>'; | |||||
} | |||||
j++; | |||||
continue outer; | |||||
} | |||||
rendered += str_orig.charAt(j); | |||||
j++; | |||||
} | |||||
return str_orig; | |||||
str = str.toLowerCase(); | |||||
subseq = subseq.toLowerCase(); | |||||
outer: for (var i = 0, j = 0; i < subseq.length; i++) { | |||||
var sub_ch = subseq.charCodeAt(i); | |||||
while (j < str_len) { | |||||
if (str.charCodeAt(j) === sub_ch) { | |||||
var str_char = str_orig.charAt(j); | |||||
if (str_char === str_char.toLowerCase()) { | |||||
rendered += '<mark>' + subseq.charAt(i) + '</mark>'; | |||||
} else { | |||||
rendered += '<mark>' + subseq.charAt(i).toUpperCase() + '</mark>'; | |||||
} | |||||
j++; | |||||
continue outer; | |||||
} | |||||
rendered += str_orig.charAt(j); | |||||
j++; | |||||
} | |||||
return str_orig; | |||||
} | } | ||||
rendered += str_orig.slice(j); | rendered += str_orig.slice(j); | ||||
return rendered; | return rendered; | ||||