aboutsummaryrefslogtreecommitdiffstats
path: root/background_scripts/completion.coffee
diff options
context:
space:
mode:
authorStephen Blott2015-05-16 10:17:37 +0100
committerStephen Blott2015-05-16 10:17:40 +0100
commit148f1b44bcbe7df030ac9f95498826ee66f0a9cd (patch)
tree3533a049ecf70bccb05a3c877adfb0a946817635 /background_scripts/completion.coffee
parenteb0e2964fca5ef2eccc06607944df6b208b2b99f (diff)
downloadvimium-148f1b44bcbe7df030ac9f95498826ee66f0a9cd.tar.bz2
Search completion; reinstate relevancy-score filter.
See the comment in the diff. This test was in a previous version, but was dropped because with eb0e2964fca5ef2eccc06607944df6b208b2b99f, it was (thought to be) no longer possible to filter by relevancy score since we don't know what the relevancy score will be. The filter is reinstated here because we use the simple idea that, whatever relevancy scores are assigned to completion suggestions, they will be less than the score for a perfect suggestion.
Diffstat (limited to 'background_scripts/completion.coffee')
-rw-r--r--background_scripts/completion.coffee13
1 files changed, 13 insertions, 0 deletions
diff --git a/background_scripts/completion.coffee b/background_scripts/completion.coffee
index c210878b..0675d13f 100644
--- a/background_scripts/completion.coffee
+++ b/background_scripts/completion.coffee
@@ -515,6 +515,19 @@ class SearchEngineCompleter
onComplete suggestions,
filter: filter
continuation: (suggestions, onComplete) =>
+
+ # We can skip querying the completion engine if any new suggestions we propose will not score highly
+ # enough to make the list anyway. We construct a suggestion which perfectly matches the query, and
+ # ask the relevancy function what score it would get. If that score is less than the score of the
+ # lowest-ranked suggestion from another completer (and there are already 10 suggestions), then
+ # there's no need to query the completion engine.
+ perfectRelevancyScore = @computeRelevancy new Suggestion
+ queryTerms: queryTerms, title: queryTerms.join(" "), relevancyData: factor
+
+ if 10 <= suggestions.length and perfectRelevancyScore < suggestions[suggestions.length-1].relevancy
+ console.log "skip (cannot make the grade):", suggestions.length, query if SearchEngineCompleter.debug
+ return onComplete []
+
CompletionSearch.complete searchUrl, queryTerms, (suggestions = []) =>
console.log "fetched suggestions:", suggestions.length, query if SearchEngineCompleter.debug
onComplete suggestions.map mkSuggestion