From fff2bbc92c1a70ea8da46c855e9d87fa012c57d2 Mon Sep 17 00:00:00 2001 From: Florence Yeun Date: Fri, 24 Apr 2015 17:30:57 -0700 Subject: [PATCH] Search API: Add subreddits results to search Support for subreddit search results in api requests. When both subreddit and link results are requested, the json response will be an array of listing objects. --- r2/r2/controllers/front.py | 30 ++++++++++++++++++------------ r2/r2/lib/pages/pages.py | 2 +- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/r2/r2/controllers/front.py b/r2/r2/controllers/front.py index 3ef0b0fd4..70e5fb088 100644 --- a/r2/r2/controllers/front.py +++ b/r2/r2/controllers/front.py @@ -1000,19 +1000,25 @@ class FrontController(RedditController): else: faceting = None - result_type = request.GET.get('type') - sr_num = 0 + # specify link or subreddit result types (when supported) + result_types = set(request.GET.getall('type')) + if is_api(): + result_types = result_types or {'link'} + elif feature.is_enabled('subreddit_search'): + result_types = result_types or {'link', 'sr'} + else: + result_types = {'link'} - # combined results on first page only, html site only - if c.render_style == 'html' and feature.is_enabled('subreddit_search'): - if after is None and not restrict_sr and not result_type: - # hardcoded to 5 subreddits (or fewer) - sr_num = min(5, int(num / 5)) - num = num - sr_num - elif result_type == 'sr': - sr_num = num - num = 0 - restrict_sr = False + # combined results on first page only + if not after and not restrict_sr and result_types == {'link', 'sr'}: + # hardcoded to 5 subreddits (or fewer) + sr_num = min(5, int(num / 5)) + num = num - sr_num + elif result_types == {'sr'}: + sr_num = num + num = 0 + else: + sr_num = 0 content = None subreddits = None diff --git a/r2/r2/lib/pages/pages.py b/r2/r2/lib/pages/pages.py index b8a6cf029..938b6f261 100644 --- a/r2/r2/lib/pages/pages.py +++ b/r2/r2/lib/pages/pages.py @@ -1414,7 +1414,7 @@ class SearchPage(BoringPage): self.subreddits = subreddits # generate the over18 redirect url for the current search if needed - if not c.over18 and feature.is_enabled('safe_search'): + if kw['nav_menus'] and not c.over18 and feature.is_enabled('safe_search'): u = UrlParser(add_sr('/search')) if prev_search: u.update_query(q=prev_search)