aboutsummaryrefslogtreecommitdiffstats
path: root/background_scripts/completion.coffee
diff options
context:
space:
mode:
authorJez Ng2012-11-03 10:12:48 -0700
committerJez Ng2012-11-03 10:12:48 -0700
commitc5744b9ac228d2943a1ba77cc3e8fc91aeab85a7 (patch)
tree0c46c2213c0978141049f3fc481742c86f746364 /background_scripts/completion.coffee
parentc492f651970437b9f3a9c90d424db31f19225d73 (diff)
parentd9e0ba4f0a06b5f5543a4398434399497573336d (diff)
downloadvimium-c5744b9ac228d2943a1ba77cc3e8fc91aeab85a7.tar.bz2
Merge pull request #702 from smblott-github/relevancy-fix
Improve consistency and fix bug in relevancy calculation.
Diffstat (limited to 'background_scripts/completion.coffee')
-rw-r--r--background_scripts/completion.coffee16
1 files changed, 10 insertions, 6 deletions
diff --git a/background_scripts/completion.coffee b/background_scripts/completion.coffee
index 79f31073..cf946b06 100644
--- a/background_scripts/completion.coffee
+++ b/background_scripts/completion.coffee
@@ -249,12 +249,16 @@ 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.
+ # Every term must match at least one thing.
+ matches: (queryTerms, things...) ->
for term in queryTerms
regexp = RegexpCache.get(term)
- return false unless title.match(regexp) || url.match(regexp)
+ matchedTerm = false
+ for thing in things
+ 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.
@@ -264,8 +268,8 @@ RankingUtils =
titleScore = 0.0
for term in queryTerms
queryLength += term.length
- urlScore += 1 if url.indexOf(term) >= 0
- titleScore += 1 if title && title.indexOf(term) >= 0
+ 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