aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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