'Perform the search over TS repositories.
Note that search works over the Whoosh index which you have
to pre-create with scripts/tool_shed/build_ts_whoosh_index.sh manually.
Also TS config option toolshed_search_on has to be True and
whoosh_index_dir has to be specified.'

def _search(self, trans, q, page=1, page_size=10):

    conf = self.app.config
    if (not conf.toolshed_search_on):
        raise ConfigDoesNotAllowException('Searching    the    TS    through    the    API    is    turned    off    for    this    instance.')
    if (not conf.whoosh_index_dir):
        raise ConfigDoesNotAllowException('There    is    no    directory    for    the    search    index    specified.    Please    contact    the    administrator.')
    search_term = q.strip()
    if (len(search_term) < 3):
        raise RequestParameterInvalidException('The    search    term    has    to    be    at    least    3    characters    long.')
    repo_search = RepoSearch()
    Boosts = namedtuple('Boosts', ['repo_name_boost', 'repo_description_boost', 'repo_long_description_boost', 'repo_homepage_url_boost', 'repo_remote_repository_url_boost', 'repo_owner_username_boost'])
    boosts = Boosts(float(conf.get('repo_name_boost', 0.9)), float(conf.get('repo_description_boost', 0.6)), float(conf.get('repo_long_description_boost', 0.5)), float(conf.get('repo_homepage_url_boost', 0.3)), float(conf.get('repo_remote_repository_url_boost', 0.2)), float(conf.get('repo_owner_username_boost', 0.3)))
    results = repo_search.search(trans, search_term, page, page_size, boosts)
    results['hostname'] = web.url_for('/', qualified=True)
    return results
