@@ -60,9 +60,9 @@ class Suggestion
6060 # - splits = [ "", "A", "b", "a", "c", "a", b" ]
6161 # UM M UM M UM M UM (M=Matched, UM=Unmatched)
6262 splits = string .split (RegexpCache .get (term, " (" , " )" ))
63- for index in [0 .. splits .length - 2 ] by 2
63+ for index in [0 .. splits .length - 2 ] by 2
6464 unmatchedText = splits[index]
65- matchedText = splits[index+ 1 ]
65+ matchedText = splits[index + 1 ]
6666 # Add the indices spanning `matchedText` to `ranges`.
6767 textPosition += unmatchedText .length
6868 ranges .push ([textPosition, textPosition + matchedText .length ])
@@ -114,9 +114,11 @@ class BookmarkCompleter
114114 onBookmarksLoaded : -> @ performSearch () if @currentSearch
115115
116116 performSearch : ->
117- # If the folder separator character the first character in any query term, then we'll use the bookmark's full path as its title.
118- # Otherwise, we'll just use the its regular title.
119- usePathAndTitle = @currentSearch .queryTerms .reduce ((prev ,term ) => prev || term .indexOf (@folderSeparator ) == 0 ), false
117+ # If the folder separator character the first character in any query term, then we'll use the bookmark's
118+ # full path as its title. Otherwise, we'll just use the its regular title.
119+ usePathAndTitle = @currentSearch .queryTerms .reduce (prev,term) =>
120+ prev || term .indexOf (@folderSeparator ) == 0
121+ , false
120122 results =
121123 if @currentSearch .queryTerms .length > 0
122124 @bookmarks .filter (bookmark) =>
@@ -137,7 +139,8 @@ class BookmarkCompleter
137139 @bookmarks = @ traverseBookmarks (bookmarks).filter ((bookmark ) -> bookmark .url ? )
138140 @ onBookmarksLoaded ()
139141
140- # If these names occur as top-level bookmark names, then they are not included in the names of bookmark folders.
142+ # If these names occur as top-level bookmark names, then they are not included in the names of bookmark
143+ # folders.
141144 ignoreTopLevel :
142145 ' Other Bookmarks' : true
143146 ' Mobile Bookmarks' : true
@@ -151,14 +154,15 @@ class BookmarkCompleter
151154 results
152155
153156 # Recursive helper for `traverseBookmarks`.
154- traverseBookmarksRecursive : (bookmark , results , parent = {pathAndTitle : " " }) ->
157+ traverseBookmarksRecursive : (bookmark , results , parent = {pathAndTitle : " " }) ->
155158 bookmark .pathAndTitle =
156159 if bookmark .title and not (parent .pathAndTitle == " " and @ignoreTopLevel [bookmark .title ])
157160 parent .pathAndTitle + @folderSeparator + bookmark .title
158161 else
159162 parent .pathAndTitle
160163 results .push bookmark
161- bookmark .children .forEach ((child ) => @ traverseBookmarksRecursive child, results, bookmark) if bookmark .children
164+ if bookmark .children
165+ bookmark .children .forEach ((child ) => @ traverseBookmarksRecursive child, results, bookmark)
162166
163167 computeRelevancy : (suggestion ) ->
164168 RankingUtils .wordRelevancy (suggestion .queryTerms , suggestion .url , suggestion .title )
@@ -186,8 +190,9 @@ class HistoryCompleter
186190
187191 refresh : ->
188192
189- # The domain completer is designed to match a single-word query which looks like it is a domain. This supports
190- # the user experience where they quickly type a partial domain, hit tab -> enter, and expect to arrive there.
193+ # The domain completer is designed to match a single-word query which looks like it is a domain. This
194+ # supports the user experience where they quickly type a partial domain, hit tab -> enter, and expect to
195+ # arrive there.
191196class DomainCompleter
192197 # A map of domain -> { entry: <historyEntry>, referenceCount: <count> }
193198 # - `entry` is the most recently accessed page in the History within this domain.
@@ -275,8 +280,10 @@ class SearchEngineCompleter
275280 searchEngineMatch = this .getSearchEngineMatches (queryTerms[0 ])
276281 suggestions = []
277282 if searchEngineMatch
278- searchEngineMatch = searchEngineMatch .replace (/ %s/ g , queryTerms[1 .. ].join (" " ))
279- suggestion = new Suggestion (queryTerms, " search" , searchEngineMatch, queryTerms[0 ] + " : " + queryTerms[1 .. ].join (" " ), @computeRelevancy )
283+ searchUrl = searchEngineMatch .replace (/ %s/ g , queryTerms[1 .. ].join (" " ))
284+ queryTerms[0 ] += " :"
285+ queryStr = queryTerms .join (" " )
286+ suggestion = new Suggestion (queryTerms, " search" , searchUrl, queryStr, @computeRelevancy )
280287 suggestions .push (suggestion)
281288 onComplete (suggestions)
282289
@@ -288,8 +295,8 @@ class SearchEngineCompleter
288295 getSearchEngineMatches : (queryTerm ) ->
289296 this .searchEngines [queryTerm]
290297
291- # A completer which calls filter() on many completers, aggregates the results, ranks them, and returns the top
292- # 10. Queries from the vomnibar frontend script come through a multi completer.
298+ # A completer which calls filter() on many completers, aggregates the results, ranks them, and returns the
299+ # top 10. Queries from the vomnibar frontend script come through a multi completer.
293300class MultiCompleter
294301 constructor : (@completers ) -> @maxResults = 10
295302
@@ -325,7 +332,7 @@ class MultiCompleter
325332# Utilities which help us compute a relevancy score for a given item.
326333RankingUtils =
327334 # Whether the given things (usually URLs or titles) match any one of the query terms.
328- # This is used to prune out irrelevant suggestions before we try to rank them, and for calculating word relevancy.
335+ # This is used to prune out irrelevant suggestions before ranking them, and for calculating word relevancy.
329336 # Every term must match at least one thing.
330337 matches : (queryTerms , things ... ) ->
331338 for term in queryTerms
@@ -338,17 +345,19 @@ RankingUtils =
338345
339346 # Weights used for scoring matches.
340347 matchWeights :
341- matchAnywhere : 1
342- matchStartOfWord : 1
343- matchWholeWord : 1
348+ matchAnywhere : 1
349+ matchStartOfWord : 1
350+ matchWholeWord : 1
344351 # The following must be the sum of the three weights above; it is used for normalization.
345- maximumScore : 3
352+ maximumScore : 3
346353 #
347354 # Calibration factor for balancing word relevancy and recency.
348- recencyCalibrator : 2.0 / 3.0
355+ recencyCalibrator : 2.0 / 3.0
349356 # The current value of 2.0/3.0 has the effect of:
350- # - favoring the contribution of recency when matches are not on word boundaries ( because 2.0/3.0 > (1)/3 )
351- # - favoring the contribution of word relevance when matches are on whole words ( because 2.0/3.0 < (1+1+1)/3 )
357+ # - favoring the contribution of recency when matches are not on word boundaries
358+ # ( because 2.0/3.0 > (1)/3 )
359+ # - favoring the contribution of word relevance when matches are on whole words
360+ # ( because 2.0/3.0 < (1+1+1)/3 )
352361
353362 # Calculate a score for matching term against string.
354363 # The score is in the range [0, matchWeights.maximumScore], see above.
@@ -448,13 +457,14 @@ RegexpCache =
448457 # - string="go", prefix="\b", suffix=""
449458 # - this returns regexp matching "google", but not "agog" (the "go" must occur at the start of a word)
450459 # TODO: `prefix` and `suffix` might be useful in richer word-relevancy scoring.
451- get : (string , prefix = " " , suffix = " " ) ->
460+ get : (string , prefix = " " , suffix = " " ) ->
452461 @ init () unless @initialized
453462 regexpString = string .replace (@escapeRegExp , " \\ $&" )
454- # Avoid cost of constructing new strings if prefix/suffix are empty (which is expected to be a common case ).
463+ # Avoid cost of constructing new strings if prefix/suffix are empty (which is expected to be common).
455464 regexpString = prefix + regexpString if prefix
456465 regexpString = regexpString + suffix if suffix
457- # Smartcase: Regexp is case insensitive, unless `string` contains a capital letter (testing `string`, not `regexpString`).
466+ # Smartcase: Regexp is case insensitive, unless `string` contains a capital letter (testing `string`, not
467+ # `regexpString`).
458468 @cache [regexpString] ||= new RegExp regexpString, (if Utils .hasUpperCase (string) then " " else " i" )
459469
460470# Provides cached access to Chrome's history. As the user browses to new pages, we add those pages to this
@@ -503,7 +513,7 @@ HistoryCache =
503513 @history = []
504514 else
505515 toRemove .urls .forEach (url) =>
506- i = HistoryCache .binarySearch ({url : url}, @history , @compareHistoryByUrl )
516+ i = HistoryCache .binarySearch ({url : url}, @history , @compareHistoryByUrl )
507517 if i < @history .length and @history [i].url == url
508518 @history .splice (i, 1 )
509519
0 commit comments