diff --git a/search/indico_search/base.py b/search/indico_search/base.py index 52a6b71..4f75f71 100644 --- a/search/indico_search/base.py +++ b/search/indico_search/base.py @@ -71,6 +71,8 @@ class SearchEngine(object): def process(self): """Executes the search - :return: an object that's passed directly to the result template + :return: an object that's passed directly to the result template. + if a flask response is returned, it is sent to the client + instead (useful to redirect to an external page) """ raise NotImplementedError diff --git a/search/indico_search/controllers.py b/search/indico_search/controllers.py index a8c7b44..80d2441 100644 --- a/search/indico_search/controllers.py +++ b/search/indico_search/controllers.py @@ -18,6 +18,7 @@ from __future__ import unicode_literals from flask import request, jsonify from flask_pluginengine import current_plugin +from werkzeug.wrappers import Response from indico.util.string import to_unicode from MaKaC.common.indexes import IndexesHolder @@ -30,6 +31,7 @@ from indico_search.views import WPSearchCategory, WPSearchConference class RHSearch(RHCustomizable): + """Performs a search using the search engine plugin""" def _checkParams(self): if 'confId' in request.view_args: self.obj = self._conf = ConferenceHolder().getById(request.view_args['confId']) @@ -49,15 +51,18 @@ class RHSearch(RHCustomizable): def _process(self): with current_plugin.engine_plugin.plugin_context(): form = current_plugin.search_form(prefix='search-') - view_class = WPSearchConference if isinstance(self.obj, Conference) else WPSearchCategory result = None if form.validate_on_submit(): result = current_plugin.perform_search(form.data, self.obj, self.page) + if isinstance(result, Response): # probably a redirect + return result + view_class = WPSearchConference if isinstance(self.obj, Conference) else WPSearchCategory return view_class.render_template('results.html', self.obj, only_public=current_plugin.only_public, form=form, obj_type=self.obj_type, result=result) class RHSearchCategoryTitles(RH): + """Searches for categories with matching titles""" def _process(self): matches = IndexesHolder().getIndex('categoryName').search(request.args['term']) results = []