aboutsummaryrefslogtreecommitdiffstats
path: root/background_scripts
diff options
context:
space:
mode:
authorStephen Blott2015-05-14 12:29:32 +0100
committerStephen Blott2015-05-14 12:29:36 +0100
commit4189ad2c17f430c1f64a9489d56e4167c79b0459 (patch)
tree2bceefee6f34084d199b29cf4edeb4aaf8c1e2e4 /background_scripts
parent5134a7a2befb0448c1a7e989f31530fd2e10df52 (diff)
downloadvimium-4189ad2c17f430c1f64a9489d56e4167c79b0459.tar.bz2
Search completion; add additional filtering stage.
Two things: 1. Do not fire off requests to completion engines if the relevancy score they are assigned wouldn't be enough to be included. 2. Fix off-by-one error in prepareSuggestions.
Diffstat (limited to 'background_scripts')
-rw-r--r--background_scripts/completion.coffee14
1 files changed, 11 insertions, 3 deletions
diff --git a/background_scripts/completion.coffee b/background_scripts/completion.coffee
index 1e22587f..5755bfaf 100644
--- a/background_scripts/completion.coffee
+++ b/background_scripts/completion.coffee
@@ -513,7 +513,15 @@ class SearchEngineCompleter
# continuation.
onComplete suggestions,
filter: filter
- continuation: (onComplete) =>
+ continuation: (suggestions, onComplete) =>
+ # Fetch completion suggestions from suggestion engines.
+
+ # We can skip this if any new suggestions we propose cannot score highly enough to make the list
+ # anyway.
+ if 10 <= suggestions.length and relevancy < 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
@@ -572,7 +580,7 @@ class MultiCompleter
if shouldRunContinuations
jobs = new JobRunner continuations.map (continuation) ->
(callback) ->
- continuation (newSuggestions) ->
+ continuation suggestions, (newSuggestions) ->
suggestions.push newSuggestions...
callback()
@@ -602,7 +610,7 @@ class MultiCompleter
for suggestion in suggestions
url = suggestion.shortenUrl()
continue if seenUrls[url]
- break if ++count == @maxResults
+ break if count++ == @maxResults
seenUrls[url] = suggestion
# Generate HTML for the remaining suggestions and return them.