aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Blott2012-11-03 10:57:36 +0000
committerStephen Blott2012-11-03 10:57:36 +0000
commitd9e0ba4f0a06b5f5543a4398434399497573336d (patch)
treec086ab70316b7e8ee64d6b154a0f4ffda519b061
parent2b1e7b1208bbd9c8e4dc0635163c810cc0c46316 (diff)
downloadvimium-d9e0ba4f0a06b5f5543a4398434399497573336d.tar.bz2
Bug fix. Not all query terms matched.
Additionally, add relevant test cases.
-rw-r--r--background_scripts/completion.coffee7
-rw-r--r--tests/unit_tests/completion_test.coffee6
2 files changed, 11 insertions, 2 deletions
diff --git a/background_scripts/completion.coffee b/background_scripts/completion.coffee
index b0c04cce..ffc824ba 100644
--- a/background_scripts/completion.coffee
+++ b/background_scripts/completion.coffee
@@ -251,12 +251,15 @@ class MultiCompleter
RankingUtils =
# Whether the given things (usually URLs or titles) match any one of the query terms.
# This is used to prune out irrelevant suggestions before we try to rank them, and for calculating word relevancy.
+ # Every term must match at least one thing.
matches: (queryTerms, things...) ->
for term in queryTerms
regexp = RegexpCache.get(term)
+ matchedTerm = false
for thing in things
- return true if thing?.match && thing.match regexp
- false
+ matchedTerm = matchedTerm || (thing?.match && thing.match regexp)
+ return false unless matchedTerm
+ true
# Returns a number between [0, 1] indicating how often the query terms appear in the url and title.
wordRelevancy: (queryTerms, url, title) ->
diff --git a/tests/unit_tests/completion_test.coffee b/tests/unit_tests/completion_test.coffee
index f409aa6e..9cde460e 100644
--- a/tests/unit_tests/completion_test.coffee
+++ b/tests/unit_tests/completion_test.coffee
@@ -167,6 +167,12 @@ context "RankingUtils",
should "do case insensitive word relevancy (not matching)", ->
assert.isTrue RankingUtils.wordRelevancy(["DOES_NOT_MATCH"], "MARIO", "MARio") == 0.0
+ should "every term must match at least one thing (matching)", ->
+ assert.isTrue RankingUtils.matches(["cat", "dog"], "catapult", "hound dog")
+
+ should "every term must match at least one thing (not matching)", ->
+ assert.isTrue not RankingUtils.matches(["cat", "dog", "wolf"], "catapult", "hound dog")
+
# A convenience wrapper around completer.filter() so it can be called synchronously in tests.
filterCompleter = (completer, queryTerms) ->
results = []