aboutsummaryrefslogtreecommitdiffstats
path: root/background_scripts
diff options
context:
space:
mode:
authorStephen Blott2012-11-03 10:17:10 +0000
committerStephen Blott2012-11-03 10:17:10 +0000
commit61adf1857993e48c791b65484c1d2ed494554446 (patch)
tree020be940f0a08c2f674462b98a2e2967588cd282 /background_scripts
parent4abd6fe7602108ef7b2179645f570e0737444777 (diff)
downloadvimium-61adf1857993e48c791b65484c1d2ed494554446.tar.bz2
Refactor RankingUtils.matches() to use splat.
Diffstat (limited to 'background_scripts')
-rw-r--r--background_scripts/completion.coffee15
1 files changed, 8 insertions, 7 deletions
diff --git a/background_scripts/completion.coffee b/background_scripts/completion.coffee
index 96b74100..b0c04cce 100644
--- a/background_scripts/completion.coffee
+++ b/background_scripts/completion.coffee
@@ -249,13 +249,14 @@ class MultiCompleter
# Utilities which help us compute a relevancy score for a given item.
RankingUtils =
- # Whether the given URL or title match any one of the query terms. This is used to prune out irrelevant
- # suggestions before we try to rank them.
- matches: (queryTerms, url, title) ->
+ # 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.
+ matches: (queryTerms, things...) ->
for term in queryTerms
regexp = RegexpCache.get(term)
- return false unless (title && title.match(regexp)) || (url && url.match(regexp))
- true
+ for thing in things
+ return true if thing?.match && thing.match regexp
+ false
# Returns a number between [0, 1] indicating how often the query terms appear in the url and title.
wordRelevancy: (queryTerms, url, title) ->
@@ -264,8 +265,8 @@ RankingUtils =
titleScore = 0.0
for term in queryTerms
queryLength += term.length
- urlScore += 1 if RankingUtils.matches([term], url, null)
- titleScore += 1 if RankingUtils.matches([term], null, title)
+ urlScore += 1 if RankingUtils.matches [term], url
+ titleScore += 1 if RankingUtils.matches [term], title
urlScore = urlScore / queryTerms.length
urlScore = urlScore * RankingUtils.normalizeDifference(queryLength, url.length)
if title