From 5191ee986615f45bfaedb389e3b34fd0a1ce9ca9 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sun, 10 May 2015 08:59:14 +0100 Subject: Search completion; reuse previous query. --- background_scripts/completion_engines.coffee | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'background_scripts/completion_engines.coffee') diff --git a/background_scripts/completion_engines.coffee b/background_scripts/completion_engines.coffee index 51799971..729c68b0 100644 --- a/background_scripts/completion_engines.coffee +++ b/background_scripts/completion_engines.coffee @@ -213,6 +213,21 @@ CompletionEngines = return null if returnResultsOnlyFromCache + if @mostRecentQuery? and @mostRecentSuggestions? + # If the user appears to be typing a continuation of the characters in all of the most recent query, + # then we can re-use the results of the previous query. + reusePreviousSuggestions = do (query) => + query = queryTerms.join(" ").toLowerCase() + return false unless 0 == query.indexOf @mostRecentQuery.toLowerCase() + previousSuggestions = @mostRecentSuggestions.map (s) -> s.toLowerCase() + return false unless query.length <= Utils.longestCommonPrefix previousSuggestions + true + + if reusePreviousSuggestions + console.log "reuse previous query", @mostRecentQuery if @debug + @mostRecentQuery = queryTerms.join " " + return callback @completionCache.set completionCacheKey, @mostRecentSuggestions + fetchSuggestions = (engine, callback) => url = engine.getUrl queryTerms query = queryTerms.join(" ").toLowerCase() -- cgit v1.2.3