From cb900a255113b8304d8931f7c6294e20f7f9f36d Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sat, 6 Jun 2015 14:19:45 +0100 Subject: Re-work completions: only offer actual search URL matches. When filter suggestions from other completers, most notably the history completer, we only keep suggestions which match the current searchUrl and completer. Here, we also *replace* the URL of the suggestion. With duplicate elimination, multiple history entries (e.g. those generated with various "Search Tools" settings on Google) will be collapsed to one. This matters because, with custom search engines, we don't show the URL, so the user can't see differences in the URL. Without this, the user can be presented with a list of apparently identical completions. --- background_scripts/completion.coffee | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'background_scripts') diff --git a/background_scripts/completion.coffee b/background_scripts/completion.coffee index 6b58f4ea..fc6263ee 100644 --- a/background_scripts/completion.coffee +++ b/background_scripts/completion.coffee @@ -456,24 +456,26 @@ class SearchEngineCompleter # This filter is applied to all of the suggestions from all of the completers, after they have been # aggregated by the MultiCompleter. filter = (suggestions) -> - suggestions.filter (suggestion) -> - # We only keep suggestions which either *were* generated by this search engine, or *could have - # been* generated by this search engine (and match the current query). - suggestion.isSearchSuggestion or suggestion.isCustomSearch or - ( - terms = Utils.extractQuery searchUrl, suggestion.url - terms and RankingUtils.matches queryTerms, terms - ) + # We only keep suggestions which either *were* generated by this search engine, or *could have + # been* generated by this search engine (and match the current query). + for suggestion in suggestions + if suggestion.isSearchSuggestion or suggestion.isCustomSearch + suggestion + else + terms = Utils.extractQuery searchUrl, suggestion.url + continue unless terms and RankingUtils.matches queryTerms, terms + suggestion.url = Utils.createSearchUrl terms, searchUrl + suggestion # If a previous suggestion still matches the query, then we keep it (even if the completion engine may not - # return it for the current query). This allows the user to pick suggestions they've previously seen by - # typing fragments of their text, without regard to whether the completion engine can continue to complete - # the actual text of the query. + # return it for the current query). This allows the user to pick suggestions that they've previously seen + # by typing fragments of their text, without regard to whether the completion engine can continue to + # complete the actual text of the query. previousSuggestions = if queryTerms.length == 0 [] else - for url, suggestion of @previousSuggestions[searchUrl] + for _, suggestion of @previousSuggestions[searchUrl] continue unless RankingUtils.matches queryTerms, suggestion.title # Reset various fields, they may not be correct wrt. the current query. extend suggestion, relevancy: null, html: null, queryTerms: queryTerms -- cgit v1.2.3