         previous = range
     mergedRanges
 
-  # Wraps each occurence of the query terms in the given string in a <span>.
-  highlightTerms: (string) ->
-    ranges = []
-    for term in @queryTerms
-      i = string.search(RegexpCache.get(term))
-      ranges.push([i, i + term.length]) if i >= 0
-
-    return string if ranges.length == 0
-
-    ranges = @mergeRanges(ranges.sort (a, b) -> a[0] - b[0])
-    # Replace portions of the string from right to left.
-    ranges = ranges.sort (a, b) -> b[0] - a[0]
-    for [start, end] in ranges
-      string =
-        string.substring(0, start) +
-        "<span class='match'>" + string.substring(start, end) + "</span>" +
-        string.substring(end)
-    string
-
-  computeRelevancy: -> @relevancy = @computeRelevancyFunction(@queryTerms, this)
 
 class BookmarkCompleter
   currentSearch: null

        suggestion
      onComplete(suggestions)

  computeRelevancy: (queryTerms, suggestion) ->
    RankingUtils.wordRelevancy(queryTerms, suggestion.url, suggestion.title)

class MultiCompleter
  constructor: (@completers) ->
    @maxResults = 10 # TODO(philc): Should this be configurable?

  refresh: -> completer.refresh() for completer in @completers when completer.refresh

  filter: (queryTerms, onComplete) ->
    # Only allow one query to run at a time.
    if @filterInProgress
      @mostRecentQuery = { queryTerms: queryTerms, onComplete: onComplete }
      return

# This file contains the definition of the completers used for the Vomnibox's suggestion UI. A completer will
# take a query (whatever the user typed into the Vomnibox) and return a list of Suggestions, e.g. bookmarks,
# domains, URLs from history.
#
# The Vomnibox frontend script makes a "filterCompleter" request to the background page, which in turn calls
# filter() on each these completers.
#
# A completer is a class which has two functions:
#  - filter(query, onComplete): "query" will be whatever the user typed into the Vomnibox.
#  - refresh(): (optional) refreshes the completer's data source (e.g. refetches the list of bookmarks).

# A Suggestion is a bookmark or history entry which matches the current query.
# It also has an attached "computeRelevancyFunction" which determines how well this item matches the given
# query terms.
class Suggestion
  showRelevancy: false # Set this to true to render relevancy when debugging the ranking scores.

  # - type: one of [bookmark, history, tab].
  # - computeRelevancyFunction: a function which takes a Suggestion and returns a relevancy score
  #   between [0, 1]
  # - extraRelevancyData: data (like the History item itself) which may be used by the relevancy function.
  constructor: (@queryTerms, @type, @url, @title, @computeRelevancyFunction, @extraRelevancyData) ->
    @title ||= ""

  computeRelevancy: -> @relevancy = @computeRelevancyFunction(this)

  generateHtml: ->
    return @html if @html
