From 08f0162d4d44e30e3444ba70d1f58bcb1badad52 Mon Sep 17 00:00:00 2001 From: Will Kahn-Greene Date: Fri, 6 Feb 2015 10:58:47 -0500 Subject: [PATCH] [bug 1122539] Handle the 0 case If max_questions or max_documents (or both) are 0, then we should do the least amount of work and just return []. --- kitsune/search/api.py | 3 +++ kitsune/search/tests/test_api.py | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/kitsune/search/api.py b/kitsune/search/api.py index 669fb827efd..2720e30925a 100644 --- a/kitsune/search/api.py +++ b/kitsune/search/api.py @@ -47,6 +47,9 @@ def suggest(request): def _question_suggestions(searcher, text, locale, product, max_results): + if max_results <= 0: + return [] + search_filter = es_utils.F( model='questions_question', question_is_archived=False, diff --git a/kitsune/search/tests/test_api.py b/kitsune/search/tests/test_api.py index b2c8a570811..a4b2088c0b4 100644 --- a/kitsune/search/tests/test_api.py +++ b/kitsune/search/tests/test_api.py @@ -74,6 +74,13 @@ def test_it_works(self): req = self.client.get(reverse('search.suggest'), {'q': 'emails'}) eq_([q['id'] for q in req.data['questions']], [q1.id]) + def test_max_results_0(self): + self._make_question() + self.refresh() + + req = self.client.get(reverse('search.suggest'), {'q': 'emails', 'max_questions': '0'}) + eq_(len(req.data['questions']), 0) + def test_product_filter_works(self): p1 = product(save=True) p2 = product(save=True)