aboutsummaryrefslogtreecommitdiffstats
path: root/background_scripts
diff options
context:
space:
mode:
Diffstat (limited to 'background_scripts')
-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