'Reindex all torrents in the database. Required when upgrading to a newer FTS engine.'

def reindex_torrents(self):

    results = self.db.fetchall('SELECT    torrent_id,    name    FROM    Torrent')
    for torrent_result in results:
        if (torrent_result[1] is None):
            continue
        swarmname = split_into_keywords(torrent_result[1])
        files_results = self.db.fetchall('SELECT    path    FROM    TorrentFiles    WHERE    torrent_id    =    ?', (torrent_result[0],))
        filenames = ''
        fileexts = ''
        for file_result in files_results:
            (filename, ext) = os.path.splitext(file_result[0])
            parts = split_into_keywords(filename)
            filenames += ('    '.join(parts) + '    ')
            fileexts += (ext[1:] + '    ')
        self.db.execute_write(u'INSERT    INTO    FullTextIndex    (rowid,    swarmname,    filenames,    fileextensions)    VALUES(?,?,?,?)', (torrent_result[0], '    '.join(swarmname), filenames[:(-1)], fileexts[:(-1)]))
    self.db.commit_now()
