'Searches for matching channels against a given query in the database.'

def search_in_local_channels_db(self, query):

    search_results = []
    keywords = split_into_keywords(query, to_filter_stopwords=True)
    sql = 'SELECT    id,    dispersy_cid,    name,    description,    nr_torrents,    nr_favorite,    nr_spam,    modified    FROM    Channels    WHERE    '
    for _ in xrange(len(keywords)):
        sql += '    name    LIKE    ?    OR    description    LIKE    ?    OR    '
    sql = sql[:(-4)]
    bindings = list(chain.from_iterable((([('%%%s%%' % keyword)] * 2) for keyword in keywords)))
    results = self._db.fetchall(sql, bindings)
    my_votes = self.votecast_db.getMyVotes()
    for result in results:
        my_vote = my_votes.get(result[0], 0)
        relevance_score = ChannelCastDBHandler.calculate_score_channel(keywords, result[2], result[3])
        extended_result = (result[0], str(result[1]), result[2], result[3], result[4], result[5], result[6], my_vote, result[7], relevance_score)
        search_results.append(extended_result)
    return search_results
