Skip to content

Commit

Permalink
Search: Expose sort parameter for subreddit search
Browse files Browse the repository at this point in the history
Remove feature flag for subreddit relevancy and expose the sort
parameter for subreddit search.

This restores the `activity` sort option that was broken when
search was providerized.
  • Loading branch information
Florence Yeun committed May 20, 2015
1 parent 0297a2e commit ce5c263
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
15 changes: 5 additions & 10 deletions r2/r2/controllers/front.py
Original file line number Diff line number Diff line change
Expand Up @@ -896,9 +896,11 @@ def GET_duplicates(self, article, num, after, reverse, count):

@base_listing
@require_oauth2_scope("read")
@validate(query=nop('q', docs={"q": "a search query"}))
@validate(query=nop('q', docs={"q": "a search query"}),
sort=VOneOf('sort', ('relevance', 'activity'),
default='relevance'))
@api_doc(api_section.subreddits, uri='/subreddits/search', supports_rss=True)
def GET_search_reddits(self, query, reverse, after, count, num):
def GET_search_reddits(self, query, reverse, after, count, num, sort):
"""Search subreddits by title and description."""

# trigger redirect to /over18
Expand All @@ -909,10 +911,6 @@ def GET_search_reddits(self, query, reverse, after, count, num):
return self.intermediate_redirect('/over18', sr_path=False,
fullpath=search_url)

# do not officially expose sort api yet
vsort = VMenu('sort', SubredditSearchSortMenu, remember=False)
sort = vsort.run(request.GET.get('sort'), '')

# show NSFW to API and RSS users unless obey_over18=true
is_api_or_rss = (c.render_style in API_TYPES
or c.render_style in RSS_TYPES)
Expand All @@ -923,9 +921,6 @@ def GET_search_reddits(self, query, reverse, after, count, num):
else:
include_over18 = True

if feature.is_enabled('subreddit_relevancy') and sort == 'relevance':
sort = 'rel1'

if query:
q = g.search.SubredditSearchQuery(query, sort=sort, faceting={},
include_over18=include_over18)
Expand Down Expand Up @@ -1068,7 +1063,7 @@ def GET_search(self, query, num, reverse, after, count, sort, recent,

# extra search request for subreddit results
if sr_num > 0 and has_query:
sr_q = g.search.SubredditSearchQuery(query, sort='rel1',
sr_q = g.search.SubredditSearchQuery(query, sort='relevance',
faceting={},
include_over18=include_over18)
subreddits = self._search(sr_q, num=sr_num, reverse=reverse,
Expand Down
6 changes: 1 addition & 5 deletions r2/r2/lib/providers/search/cloudsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -788,16 +788,12 @@ def _restrict_sr(sr):
class CloudSearchSubredditSearchQuery(CloudSearchQuery):
search_api = g.CLOUDSEARCH_SUBREDDIT_SEARCH_API
sorts = {
'relevance': '-activity',
'relevance': '-relevance',
'activity': '-activity',
'rel1': '-rel1',
'rel2': '-rel2',
}
sorts_menu_mapping = {
'relevance': 1,
'activity': 2,
'rel1': 3,
'rel2': 4,
}

known_syntaxes = ("plain",)
Expand Down

0 comments on commit ce5c263

Please sign in to comment.