From a476277cab8e03764aceb43c29fb08b0bf5e9059 Mon Sep 17 00:00:00 2001 From: Sina Siadat Date: Sat, 26 Sep 2015 23:32:49 +0330 Subject: [PATCH] Fix scores, so all words must match. --- background.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/background.js b/background.js index 85cbb93..390a371 100644 --- a/background.js +++ b/background.js @@ -51,18 +51,22 @@ function ffSearchFor(text, callback) { var score = 0; var hostname = ffGetHostname(tab.url); - words_fuzzy.forEach(function(word) { - if(tab.title.match(word)) { score += 20; } - if(tab.url.match(word)) { score += 20; } - if(hostname.match(word)) { score += 20; } + var found_words = words_exact.map(function() { return false; }) + + words_fuzzy.forEach(function(word, i) { + if(tab.title.match(word)) { score += 20; found_words[i] = true; } + if(tab.url.match(word)) { score += 20; found_words[i] = true; } + if(hostname.match(word)) { score += 20; found_words[i] = true; } }); - words_exact.forEach(function(word) { - if(tab.title.match(word)) { score += 100; } - if(tab.url.match(word)) { score += 100; } - if(hostname.match(word)) { score += 100; } + words_exact.forEach(function(word, i) { + if(found_words[i]) { return; } + if(tab.title.match(word)) { score += 100; found_words[i] = true; } + if(tab.url.match(word)) { score += 100; found_words[i] = true; } + if(hostname.match(word)) { score += 100; found_words[i] = true; } }); + if(found_words.filter(function(x) { return x; }).length !== words_exact.length) { score = 0; } if(score > 0 && tab.pinned) { score += 1000; } if(FF_DEBUGGING && score > 0) { console.debug("tab", tab.title); }