This commit is contained in:
Carl Eberhard
2015-02-09 16:41:04 -05:00
2 changed files with 16 additions and 2 deletions
+15 -2
View File
@@ -1,8 +1,8 @@
"""API for searching the toolshed repositories"""
from galaxy import exceptions
from galaxy import eggs
from galaxy import util
from galaxy.web import _future_expose_api as expose_api
# from galaxy.web import _future_expose_api_anonymous as expose_api_anonymous
from galaxy.web import _future_expose_api_raw_anonymous as expose_api_raw_anonymous
from galaxy.web.base.controller import BaseAPIController
from galaxy.webapps.tool_shed.search.repo_search import RepoSearch
@@ -22,19 +22,32 @@ class SearchController ( BaseAPIController ):
The index has to be pre-created with build_ts_whoosh_index.sh.
TS config option toolshed_search_on has to be turned on and
toolshed_whoosh_index_dir has to be specified and existing.
:param search_term:
:param page:
:param jsonp:
:param callback:
:returns dict:
"""
if not self.app.config.toolshed_search_on:
raise exceptions.ConfigDoesNotAllowException( 'Searching the TS through the API is turned off for this instance.' )
if not self.app.config.toolshed_whoosh_index_dir:
raise exceptions.ConfigDoesNotAllowException( 'There is no directory for the search index specified. Please ontact the administrator.' )
search_term = search_term.strip()
if len( search_term ) < 3:
raise exceptions.RequestParameterInvalidException( 'The search term has to be at least 3 characters long.' )
page = kwd.get( 'page', 1 )
return_jsonp = util.asbool( kwd.get( 'jsonp', False ) )
callback = kwd.get( 'callback', 'callback' )
repo_search = RepoSearch()
results = repo_search.search( trans, search_term, page )
results[ 'hostname' ] = url_for( '/', qualified = True )
response = '%s(%s);' % ( callback, json.dumps( results ) )
if jsonp:
response = '%s(%s);' % ( callback, json.dumps( results ) )
else:
response = json.dumps( results )
return response
@@ -33,6 +33,7 @@ try:
full_last_updated = STORED )
except ImportError, e:
log.error( 'There was an error while importing the Whoosh library.' )
search_ready = False
schema = None