def METHOD_NAME(q="", page=1):
    svc = get_service("indexing")
    q = q.strip()
    page = int(request.args.get("page", page))
    search_kwargs = {"limit": page * PAGE_SIZE}
    page_url_kw = OrderedDict(q=q)
    search_kwargs["groupedby"] = _COUNT_OBJECT_TYPE_FACET
    results = svc.search(q, **search_kwargs)
    filtered_by_type = sorted(request.args.getlist("object_type"))
    if filtered_by_type:
        page_url_kw["object_type"] = filtered_by_type
    page_url = partial(url_for, ".search_main", **page_url_kw)
    # get facets groups
    by_object_type = []
    try:
        facet_group = results.groups("object_type")
    except KeyError:
        pass
    else:
        for typename, count in facet_group.items():
            is_active = typename in filtered_by_type
            classname = friendly_fqcn(typename)
            link = page_url(object_type=typename)
            by_object_type.append((classname, count, link, is_active))
        by_object_type.sort(key=lambda t: t[0])
    if by_object_type:
        # Insert 'all' to clear all filters
        is_active = len(filtered_by_type) == 0
        all_types = (_("All"), len(results), page_url(object_type=()), is_active)
        by_object_type.insert(0, all_types)
    if filtered_by_type:
        # FIXME: sanitize input
        results = svc.search(q, object_types=filtered_by_type, **search_kwargs)
    results.formatter = BOOTSTRAP_MARKUP_HIGHLIGHTER
    results.fragmenter = RESULTS_FRAGMENTER
    # paginate results
    results_count = len(results)
    # results.pagecount must be ignored when query is filtered: it ignores
    # filtered_count
    pagecount = 1 + results_count // PAGE_SIZE
    page = min(page, pagecount)
    results = whoosh.searching.ResultsPage(results, page, PAGE_SIZE)
    page = results.pagenum
    first_page = page_url(page=1)
    last_page = page_url(page=pagecount)
    prev_page = page_url(page=page - 1) if page > 1 else None
    next_page = page_url(page=page + 1) if page < pagecount else None
    page_min = max(page - 2, 1)
    page_max = min(page + 4, pagecount)
    next_pages_numbered = [
        (index, page_url(page=index)) for index in range(page_min, page_max + 1)
    ]
    ctx = {
        "q": q,
        "results": results,
        "results_count": results_count,
        "pagecount": pagecount,
        "filtered_by_type": filtered_by_type,
        "by_object_type": by_object_type,
        "prev_page": prev_page,
        "next_page": next_page,
        "first_page": first_page,
        "last_page": last_page,
        "next_pages_numbered": next_pages_numbered,
        "friendly_fqcn": friendly_fqcn,
    }
    return render_template("search/search.html", **ctx)