mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-01-15 01:48:18 -05:00
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.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user