From 4abd6fe7602108ef7b2179645f570e0737444777 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sat, 3 Nov 2012 08:19:57 +0000 Subject: Improve consistency and fix relevancy calculation. Problem: - The word relevancy calculation is case sensitive, all other matching is case insensitive. Improve consistency: - Highlighting of elements in the vomnibox is case insensitive; this does not match the case sensitive relevancy calculation. Fix: - Bookmark titles, in particular, tend to contain capital letters. Unless the query term also contains the relevant capital letters, then the term was scored at zero, pushing what seem to be good matches to the bottom of the list. In fact, they were only included in the list at all because they happen to pass the `RankingUtils.matches()` test. --- background_scripts/completion.coffee | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'background_scripts') diff --git a/background_scripts/completion.coffee b/background_scripts/completion.coffee index f7313756..96b74100 100644 --- a/background_scripts/completion.coffee +++ b/background_scripts/completion.coffee @@ -254,7 +254,7 @@ RankingUtils = matches: (queryTerms, url, title) -> for term in queryTerms regexp = RegexpCache.get(term) - return false unless title.match(regexp) || url.match(regexp) + return false unless (title && title.match(regexp)) || (url && url.match(regexp)) true # Returns a number between [0, 1] indicating how often the query terms appear in the url and title. @@ -264,8 +264,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, null) + titleScore += 1 if RankingUtils.matches([term], null, title) urlScore = urlScore / queryTerms.length urlScore = urlScore * RankingUtils.normalizeDifference(queryLength, url.length) if title -- cgit v1.2.3 From 61adf1857993e48c791b65484c1d2ed494554446 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sat, 3 Nov 2012 10:17:10 +0000 Subject: Refactor RankingUtils.matches() to use splat. --- background_scripts/completion.coffee | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'background_scripts') 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 -- cgit v1.2.3 From d9e0ba4f0a06b5f5543a4398434399497573336d Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sat, 3 Nov 2012 10:57:36 +0000 Subject: Bug fix. Not all query terms matched. Additionally, add relevant test cases. --- background_scripts/completion.coffee | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'background_scripts') diff --git a/background_scripts/completion.coffee b/background_scripts/completion.coffee index b0c04cce..ffc824ba 100644 --- a/background_scripts/completion.coffee +++ b/background_scripts/completion.coffee @@ -251,12 +251,15 @@ class MultiCompleter RankingUtils = # 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) + matchedTerm = false for thing in things - return true if thing?.match && thing.match regexp - false + 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. wordRelevancy: (queryTerms, url, title) -> -- cgit v1.2.3