From 7f99155824edd7424bd28feae401459da6a2ba8f Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Mon, 4 May 2015 12:38:00 +0100 Subject: Search completion; instrument for debugging. --- background_scripts/completion.coffee | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) (limited to 'background_scripts/completion.coffee') diff --git a/background_scripts/completion.coffee b/background_scripts/completion.coffee index f09a079c..1c07a71a 100644 --- a/background_scripts/completion.coffee +++ b/background_scripts/completion.coffee @@ -383,25 +383,21 @@ class SearchEngineCompleter # immediately. return onComplete [] - # We pause in case the user is still typing. - Utils.setTimeout 250, handler = @mostRecentHandler = => - return onComplete [] if handler != @mostRecentHandler # Bail if another completion has begun. - - SearchEngines.complete searchUrl, queryTerms, (searchSuggestions = []) => - for suggestion in searchSuggestions - insertText = if custom then "#{keyword} #{suggestion}" else suggestion - suggestions.push @mkSuggestion insertText, queryTerms, type, mkUrl(suggestion), suggestion, @computeRelevancy, score - score *= 0.9 - - # Experimental. Force the best match to the top of the list. - suggestions[0].extraRelevancyData = 0.9999999 if 0 < suggestions.length - - # We keep at least three suggestions (if possible) and at most six. We keep more than three only if - # there are enough slots. The idea is that these suggestions shouldn't wholly displace suggestions - # from other completers. That would potentially be a problem because there is no relationship - # between the relevancy scores produced here and those produced by other completers. - count = Math.min 6, Math.max 3, MultiCompleter.maxResults - existingSuggestions.length - onComplete suggestions[...count] + SearchEngines.complete searchUrl, queryTerms, (searchSuggestions = []) => + for suggestion in searchSuggestions + insertText = if custom then "#{keyword} #{suggestion}" else suggestion + suggestions.push @mkSuggestion insertText, queryTerms, type, mkUrl(suggestion), suggestion, @computeRelevancy, score + score *= 0.9 + + # Experimental. Force the best match to the top of the list. + suggestions[0].extraRelevancyData = 0.9999999 if 0 < suggestions.length + + # We keep at least three suggestions (if possible) and at most six. We keep more than three only if + # there are enough slots. The idea is that these suggestions shouldn't wholly displace suggestions + # from other completers. That would potentially be a problem because there is no relationship + # between the relevancy scores produced here and those produced by other completers. + count = Math.min 6, Math.max 3, MultiCompleter.maxResults - existingSuggestions.length + onComplete suggestions[...count] mkSuggestion: (insertText, args...) -> suggestion = new Suggestion args... @@ -474,6 +470,7 @@ class MultiCompleter continuation = cont if cont? if @completers.length <= ++completersFinished shouldRunContinuation = continuation? and not @mostRecentQuery + console.log "skip continuation" if continuation? and not shouldRunContinuation # We don't post results immediately if there are none, and we're going to run a continuation # (ie. a SearchEngineCompleter). This prevents hiding the vomnibar briefly before showing it # again, which looks ugly. -- cgit v1.2.3