def __init__(self, basenames):
    # The basenames come out of a hashtable so they are usually pretty badly
    # shuffled around. Sort them here so that we get somewhat predictable results
    # as a query is incrementally refined.
    basenames.sort()

    # Build the lower basenames list, removing dupes as needed.
    lower_basenames = set()
    for basename in basenames:
      lower_basename = basename.lower()
      lower_basenames.add(lower_basename)

    # Build two giant strings that contain all the basenames [and lowercase basenames]
    # concatenated together. This is what we will use to handle fuzzy queries.
    self.basenames_unsplit = ("\n" + "\n".join(basenames) + "\n").encode('utf8')
    self.lower_basenames_unsplit = ("\n" + "\n".join(lower_basenames) + "\n").encode('utf8')
    assert type(self.lower_basenames_unsplit) == str

    self._basename_ranker = BasenameRanker()
    wordstarts = {}
    for basename in basenames:
      start_letters = self._basename_ranker.get_start_letters(basename)
      if len(start_letters) <= 1:
        continue
      lower_basename = basename.lower()
      for i in range(len(start_letters) + 1 - 2): # abcd -> ab abc abcd
        ws = ''.join(start_letters[0:2+i])
        if ws not in wordstarts:
          wordstarts[ws] = []
        loss = len(start_letters) - (2 + i)
        wordstarts[ws].append((lower_basename, loss))

    # now, order the actual entries so high qualities are at front
    self.basenames_by_wordstarts = {}
    for ws,items in wordstarts.iteritems():
      items.sort(lambda x,y: cmp(x[1],y[1]))
      self.basenames_by_wordstarts[ws] = [i[0] for i in items]
dataset/ETHPy150Open natduca/quickopen/src/db_index_shard.py/DBIndexShard.__init__/original