diff options
| author | Phil Crosby | 2012-06-03 16:01:11 -0700 | 
|---|---|---|
| committer | Phil Crosby | 2012-06-03 16:56:39 -0700 | 
| commit | 7d6f675b7b890645d7bd2819d697d8a6210f37b0 (patch) | |
| tree | f1ba24d19aa98d39ed409d0fa6e98383b7012d0e /background_scripts | |
| parent | 4a90ae22b2e0de76d0993e4158a6232e7de1c108 (diff) | |
| download | vimium-7d6f675b7b890645d7bd2819d697d8a6210f37b0.tar.bz2 | |
Make computing the recency score of an item into RankingUtils.
Diffstat (limited to 'background_scripts')
| -rw-r--r-- | background_scripts/completion.coffee | 23 | 
1 files changed, 15 insertions, 8 deletions
| diff --git a/background_scripts/completion.coffee b/background_scripts/completion.coffee index f1016ebb..8b18ce90 100644 --- a/background_scripts/completion.coffee +++ b/background_scripts/completion.coffee @@ -101,15 +101,8 @@ class HistoryCompleter      onComplete(suggestions)    computeRelevancy: (queryTerms, suggestion) -> -    @oneMonthAgo ||= 1000 * 60 * 60 * 24 * 30      historyEntry = suggestion.extraRelevancyData -    recency = Date.now() - historyEntry.lastVisitTime -    recencyDifference = Math.max(0, @oneMonthAgo - recency) / @oneMonthAgo - -    # recencyScore is between [0, 1]. It is 1 when recenyDifference is 0. This qudratic equation will -    # incresingly discount older history entries. -    recencyScore = recencyDifference * recencyDifference * recencyDifference - +    recencyScore = RankingUtils.recencyScore(historyEntry.lastVisitTime)      wordRelevancy = RankingUtils.wordRelevancy(queryTerms, suggestion.url, suggestion.title)      # Average out the word score and the recency. Recency has the ability to pull the score up, but not down.      score = (wordRelevancy + Math.max(recencyScore, wordRelevancy)) / 2 @@ -165,6 +158,20 @@ RankingUtils =      titleScore = titleScore * RankingUtils.normalizeDifference(queryLength, title.length)      (urlScore + titleScore) / 2 +  # Returns a score between [0, 1] which indicates how recent the given timestamp is. Items which are over +  # a month old are counted as 0. This range is quadratic, so an item from one day ago has a much stronger +  # score than an item from two days ago. +  recencyScore: (lastAccessedTime) -> +    @oneMonthAgo ||= 1000 * 60 * 60 * 24 * 30 +    recency = Date.now() - lastAccessedTime +    recencyDifference = Math.max(0, @oneMonthAgo - recency) / @oneMonthAgo + +    # recencyScore is between [0, 1]. It is 1 when recenyDifference is 0. This quadratic equation will +    # incresingly discount older history entries. +    recencyScore = recencyDifference * recencyDifference * recencyDifference + + +    # Takes the difference of two numbers and returns a number between [0, 1] (the percentage difference).    normalizeDifference: (a, b) ->      max = Math.max(a, b) | 
