From 39885cd326737534e2afc976f2a8ce086c76fc66 Mon Sep 17 00:00:00 2001 From: Phil Crosby Date: Sun, 3 Jun 2012 16:02:01 -0700 Subject: Make title in suggestions optional (domain suggestions may not have a title) --- background_scripts/completion.coffee | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'background_scripts') diff --git a/background_scripts/completion.coffee b/background_scripts/completion.coffee index 8b18ce90..c9b4de78 100644 --- a/background_scripts/completion.coffee +++ b/background_scripts/completion.coffee @@ -3,6 +3,7 @@ class Suggestion # - type: one of [bookmark, history, tab]. constructor: (@queryTerms, @type, @url, @title, @computeRelevancyFunction, @extraRelevancyData) -> + @title ||= "" generateHtml: -> return @html if @html @@ -151,11 +152,14 @@ RankingUtils = for term in queryTerms queryLength += term.length urlScore += 1 if url.indexOf(term) >= 0 - titleScore += 1 if title.indexOf(term) >= 0 + titleScore += 1 if title && title.indexOf(term) >= 0 urlScore = urlScore / queryTerms.length urlScore = urlScore * RankingUtils.normalizeDifference(queryLength, url.length) - titleScore = titleScore / queryTerms.length - titleScore = titleScore * RankingUtils.normalizeDifference(queryLength, title.length) + if title + titleScore = titleScore / queryTerms.length + titleScore = titleScore * RankingUtils.normalizeDifference(queryLength, title.length) + else + titleScore = urlScore (urlScore + titleScore) / 2 # Returns a score between [0, 1] which indicates how recent the given timestamp is. Items which are over -- cgit v1.2.3