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:
Florence Yeun
2015-04-24 17:30:57 -07:00
parent 6fd9cb472e
commit fff2bbc92c
2 changed files with 19 additions and 13 deletions

View File

@@ -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

View File

@@ -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)