From 4309dcd3030687f3ed02b86bbdf7c485baaee4a5 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Mon, 18 May 2015 06:49:18 +0100 Subject: Search completion; promote the top completion. This puts the first (top) completion suggestion at the top of the list: either one or two s away, depending upon whether a domain-completer suggestion is present or not. --- background_scripts/completion.coffee | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/background_scripts/completion.coffee b/background_scripts/completion.coffee index 1f0a0019..22740128 100644 --- a/background_scripts/completion.coffee +++ b/background_scripts/completion.coffee @@ -10,7 +10,7 @@ # - refresh(): (optional) refreshes the completer's data source (e.g. refetches the list of bookmarks). # - cancel(): (optional) cancels any pending, cancelable action. class Suggestion - showRelevancy: true # Set this to true to render relevancy when debugging the ranking scores. + showRelevancy: false # Set this to true to render relevancy when debugging the ranking scores. constructor: (@options) -> # Required options. @@ -281,7 +281,7 @@ class DomainCompleter queryTerms: queryTerms type: "domain" url: domains[0]?[0] ? "" # This is the URL or an empty string, but not null. - relevancy: 1 + relevancy: 2 ].filter (s) -> 0 < s.url.length # Returns a list of domains of the form: [ [domain, relevancy], ... ] @@ -477,22 +477,28 @@ class SearchEngineCompleter type: description url: Utils.createSearchUrl queryTerms, searchUrl title: queryTerms.join " " - relevancy: 1 + relevancy: 2 autoSelect: custom forceAutoSelect: custom highlightTerms: not haveCompletionEngine - mkSuggestion = (suggestion) => - new Suggestion - queryTerms: queryTerms - type: description - url: Utils.createSearchUrl suggestion, searchUrl - title: suggestion - insertText: suggestion - highlightTerms: false - isCustomSearch: custom - relevancyFunction: @computeRelevancy - relevancyData: factor + mkSuggestion = do => + count = 0 + (suggestion) => + console.log count + new Suggestion + queryTerms: queryTerms + type: description + url: Utils.createSearchUrl suggestion, searchUrl + title: suggestion + insertText: suggestion + highlightTerms: false + isCustomSearch: custom + # The first (top) suggestion gets a score of 1. This puts it two s away if a domain completion + # is present (which has a score of 2), and one away otherwise. + relevancy: if 0 < count++ then null else 1 + relevancyFunction: @computeRelevancy + relevancyData: factor cachedSuggestions = if haveCompletionEngine then CompletionSearch.complete searchUrl, queryTerms else null -- cgit v1.2.3