aboutsummaryrefslogtreecommitdiffstats
path: root/background_scripts
diff options
context:
space:
mode:
Diffstat (limited to 'background_scripts')
-rw-r--r--background_scripts/completion.coffee26
-rw-r--r--background_scripts/completion_engines.coffee4
-rw-r--r--background_scripts/completion_search.coffee5
-rw-r--r--background_scripts/main.coffee2
4 files changed, 21 insertions, 16 deletions
diff --git a/background_scripts/completion.coffee b/background_scripts/completion.coffee
index e38a4e16..85829c75 100644
--- a/background_scripts/completion.coffee
+++ b/background_scripts/completion.coffee
@@ -361,14 +361,18 @@ class SearchEngineCompleter
cancel: ->
CompletionSearch.cancel()
- # This looks up the custom search engine and, if one is found, then notes it and removes its keyword from
- # the query terms. It also sets request.completers to indicate that only this completer should run.
+ # This looks up the custom search engine and, if one is found, notes it and removes its keyword from the
+ # query terms. It also sets request.completers to indicate that only this completer should run (but only if
+ # it finds a completion engine).
triageRequest: (request) ->
@searchEngines.use (engines) =>
{ queryTerms, query } = request
keyword = queryTerms[0]
+ # Note. For a keyword "w", we match "w search terms" and "w ", but not "w" on its own.
if keyword and engines[keyword] and (1 < queryTerms.length or /\s$/.test query)
- request.completers = [ this ]
+ # This is a query for a custom search engine. If we have a completion engine, then we *only* want
+ # suggestions from SearchEngineCompleter.
+ request.completers = [ this ] if CompletionSearch.haveCompletionEngine engines[keyword].searchUrl
extend request,
queryTerms: queryTerms[1..]
keyword: keyword
@@ -394,7 +398,9 @@ class SearchEngineCompleter
callback engines
- # Let the front-end vomnibar know the search-engine keywords.
+ # Let the front-end vomnibar know the search-engine keywords. It needs to know them so that, when the
+ # query goes from "w" to "w ", the vomnibar synchronously launches the next filter() request (all of which avoids
+ # an ugly delay).
port.postMessage
handler: "keywords"
keywords: key for own key of engines
@@ -453,7 +459,6 @@ class SearchEngineCompleter
insertText: if useExclusiveVomnibar then query else null
# We suppress the leading keyword, for example "w something" becomes "something" in the vomnibar.
suppressLeadingKeyword: true
- selectCommonMatches: false
customSearchEnginePrimarySuggestion: true
# Toggles for the legacy behaviour.
autoSelect: not useExclusiveVomnibar
@@ -470,7 +475,6 @@ class SearchEngineCompleter
relevancy: relevancy *= 0.9
insertText: suggestion
highlightTerms: false
- selectCommonMatches: true
customSearchEngineCompletionSuggestion: true
# If we have cached suggestions, then we can bundle them immediately (otherwise we'll have to fetch them
@@ -495,9 +499,11 @@ class SearchEngineCompleter
onComplete suggestions.map mkSuggestion
# A completer which calls filter() on many completers, aggregates the results, ranks them, and returns the top
-# 10. Queries from the vomnibar frontend script come through a multi completer.
+# 10. All queries from the vomnibar come through a multi completer.
class MultiCompleter
maxResults: 10
+ filterInProgress: false
+ mostRecentQuery: null
constructor: (@completers) ->
refresh: (port) -> completer.refresh? port for completer in @completers
@@ -531,8 +537,8 @@ class MultiCompleter
filters.push filter if filter?
callback()
- # Once all completers have finished, process the results and post them, and run any continuations or
- # pending queries.
+ # Once all completers have finished, process the results and post them, and run any continuations or a
+ # pending query.
jobs.onReady =>
suggestions = suggestions.filter filter for filter in filters
shouldRunContinuations = 0 < continuations.length and not @mostRecentQuery?
@@ -563,7 +569,7 @@ class MultiCompleter
results: suggestions
mayCacheResults: true
- # Admit subsequent queries, and launch any pending query.
+ # Admit subsequent queries and launch any pending query.
@filterInProgress = false
if @mostRecentQuery
@filter @mostRecentQuery...
diff --git a/background_scripts/completion_engines.coffee b/background_scripts/completion_engines.coffee
index 14e65692..048e9020 100644
--- a/background_scripts/completion_engines.coffee
+++ b/background_scripts/completion_engines.coffee
@@ -1,6 +1,6 @@
# A completion engine provides search suggestions for a search engine. A search engine is identified by a
-# "searchUrl", e.g. Settings.get("searchUrl"), or a custom search engine.
+# "searchUrl", e.g. Settings.get("searchUrl"), or a custom search engine URL.
#
# Each completion engine defines three functions:
#
@@ -14,7 +14,7 @@
# returns a list of suggestions (a list of strings). This method is always executed within the context
# of a try/catch block, so errors do not propagate.
#
-# Each new completion engine must be add to the list "CompletionEngines" at the bottom of this file.
+# Each new completion engine must be added to the list "CompletionEngines" at the bottom of this file.
#
# The lookup logic which uses these completion engines is in "./completion_search.coffee".
#
diff --git a/background_scripts/completion_search.coffee b/background_scripts/completion_search.coffee
index 2d2ee439..b6514cd2 100644
--- a/background_scripts/completion_search.coffee
+++ b/background_scripts/completion_search.coffee
@@ -2,7 +2,7 @@
CompletionSearch =
debug: false
inTransit: {}
- completionCache: new SimpleCache 2 * 60 * 60 * 1000, 5000 # Two hour, 5000 entries.
+ completionCache: new SimpleCache 2 * 60 * 60 * 1000, 5000 # Two hours, 5000 entries.
engineCache:new SimpleCache 1000 * 60 * 60 * 1000 # 1000 hours.
# The amount of time to wait for new requests before launching the current request (for example, if the user
@@ -35,7 +35,7 @@ CompletionSearch =
not @lookupEngine(searchUrl).dummy
# This is the main entry point.
- # - searchUrl is the search engine's URL, e.g. Settings.get("searchUrl"), or a custome search engine's URL.
+ # - searchUrl is the search engine's URL, e.g. Settings.get("searchUrl"), or a custom search engine's URL.
# This is only used as a key for determining the relevant completion engine.
# - queryTerms are the query terms.
# - callback will be applied to a list of suggestion strings (which may be an empty list, if anything goes
@@ -82,7 +82,6 @@ CompletionSearch =
if reusePreviousSuggestions
console.log "reuse previous query:", @mostRecentQuery if @debug
- @mostRecentQuery = queryTerms.join " "
return callback @completionCache.set completionCacheKey, @mostRecentSuggestions
# That's all of the caches we can try. Bail if the caller is looking for synchronous results.
diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee
index 913f1de5..6ee0e8e7 100644
--- a/background_scripts/main.coffee
+++ b/background_scripts/main.coffee
@@ -64,7 +64,7 @@ completionHandlers =
completer.filter request, (response) ->
# We use try here because this may fail if the sender has already navigated away from the original page.
# This can happen, for example, when posting completion suggestions from the SearchEngineCompleter
- # (which can be slow).
+ # (which is done asynchronously).
try
port.postMessage extend request, extend response, handler: "completions"