From c52c0ea57f86c1c5a132819fe85e763db84ce712 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Mon, 29 Dec 2014 16:33:23 +0000 Subject: Descriptions for custom search engines. --- background_scripts/completion.coffee | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'background_scripts/completion.coffee') diff --git a/background_scripts/completion.coffee b/background_scripts/completion.coffee index d62f82fe..4e570313 100644 --- a/background_scripts/completion.coffee +++ b/background_scripts/completion.coffee @@ -324,11 +324,17 @@ class SearchEngineCompleter searchEngines: {} filter: (queryTerms, onComplete) -> - searchEngineMatch = this.getSearchEngineMatches(queryTerms[0]) + {url: url, description: description} = this.getSearchEngineMatches(queryTerms[0]) suggestions = [] - if searchEngineMatch - searchEngineMatch = searchEngineMatch.replace(/%s/g, Utils.createSearchQuery queryTerms[1..]) - suggestion = new Suggestion(queryTerms, "search", searchEngineMatch, queryTerms[0] + ": " + queryTerms[1..].join(" "), @computeRelevancy) + if url + url = url.replace(/%s/g, Utils.createSearchQuery queryTerms[1..]) + if description + type = description + query = queryTerms[1..].join " " + else + type = "search" + query = queryTerms[0] + ": " + queryTerms[1..].join(" ") + suggestion = new Suggestion(queryTerms, type, url, query, @computeRelevancy) suggestions.push(suggestion) onComplete(suggestions) @@ -338,7 +344,7 @@ class SearchEngineCompleter this.searchEngines = root.Settings.getSearchEngines() getSearchEngineMatches: (queryTerm) -> - this.searchEngines[queryTerm] + this.searchEngines[queryTerm] || {} # 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. -- cgit v1.2.3 From 094753c5a536ebacdaa3f811d198595ef2c67d24 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Tue, 30 Dec 2014 16:57:27 +0000 Subject: Delay recognising query as search-engine query. --- background_scripts/completion.coffee | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'background_scripts/completion.coffee') diff --git a/background_scripts/completion.coffee b/background_scripts/completion.coffee index 4e570313..5cab54ed 100644 --- a/background_scripts/completion.coffee +++ b/background_scripts/completion.coffee @@ -324,7 +324,7 @@ class SearchEngineCompleter searchEngines: {} filter: (queryTerms, onComplete) -> - {url: url, description: description} = this.getSearchEngineMatches(queryTerms[0]) + {url: url, description: description} = @getSearchEngineMatches queryTerms suggestions = [] if url url = url.replace(/%s/g, Utils.createSearchQuery queryTerms[1..]) @@ -343,8 +343,8 @@ class SearchEngineCompleter refresh: -> this.searchEngines = root.Settings.getSearchEngines() - getSearchEngineMatches: (queryTerm) -> - this.searchEngines[queryTerm] || {} + getSearchEngineMatches: (queryTerms) -> + if 1 < queryTerms.length and engine = @searchEngines[queryTerms[0]] then engine else {} # 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. -- cgit v1.2.3 From 877bf98618ba4f8c2dfdb6a82459a98816062112 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Wed, 31 Dec 2014 08:58:06 +0000 Subject: Simplify search engine logic. --- background_scripts/completion.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'background_scripts/completion.coffee') diff --git a/background_scripts/completion.coffee b/background_scripts/completion.coffee index 5cab54ed..d6402019 100644 --- a/background_scripts/completion.coffee +++ b/background_scripts/completion.coffee @@ -344,7 +344,7 @@ class SearchEngineCompleter this.searchEngines = root.Settings.getSearchEngines() getSearchEngineMatches: (queryTerms) -> - if 1 < queryTerms.length and engine = @searchEngines[queryTerms[0]] then engine else {} + (1 < queryTerms.length and @searchEngines[queryTerms[0]]) or {} # 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. -- cgit v1.2.3