def _collections(request):
    """Handle the request for collections."""

    # Sorting by relevance isn't an option. Instead the default is `weekly`.
    initial = dict(sort='weekly')
    # Update with GET variables.
    initial.update(request.GET.items())
    # Ignore appver/platform and set default number of collections per page.
    initial.update(appver=None, platform=None, pp=DEFAULT_NUM_COLLECTIONS)

    form = SecondarySearchForm(initial)
    form.is_valid()

    qs = Collection.search().filter(listed=True, app=request.APP.id)
    filters = ['sort']
    mapping = {'weekly': '-weekly_subscribers',
               'monthly': '-monthly_subscribers',
               'all': '-subscribers',
               'rating': '-rating',
               'created': '-created',
               'name': 'name_sort',
               'updated': '-modified'}
    results = _filter_search(request, qs, form.cleaned_data, filters,
                             sorting=mapping,
                             sorting_default='-weekly_subscribers',
                             types=amo.COLLECTION_SEARCH_CHOICES)

    form_data = form.cleaned_data.get('q', '')

    search_opts = {}
    search_opts['limit'] = form.cleaned_data.get('pp', DEFAULT_NUM_COLLECTIONS)
    page = form.cleaned_data.get('page') or 1
    search_opts['offset'] = (page - 1) * search_opts['limit']
    search_opts['sort'] = form.cleaned_data.get('sort')

    pager = amo.utils.paginate(request, results, per_page=search_opts['limit'])
    c = dict(pager=pager, form=form, query=form_data, opts=search_opts,
             filter=get_filter_view(request),
             search_placeholder='collections')
    return render(request, 'search/collections.html', c)
dataset/ETHPy150Open mozilla/addons-server/src/olympia/search/views.py/_collections/original