def METHOD_NAME(request):
    """Search the database for annotations matching with the given query."""
    schema = SearchParamsSchema()
    params = validate_query_params(schema, request.params)
    separate_replies = params.pop("_separate_replies", False)
    result = search_lib.Search(request, separate_replies=separate_replies).run(params)
    svc = request.find_service(name="annotation_json")
    out = {
        "total": result.total,
        "rows": svc.present_all_for_user(
            annotation_ids=result.annotation_ids, user=request.user
        ),
    }
    if separate_replies:
        out["replies"] = svc.present_all_for_user(
            annotation_ids=result.reply_ids, user=request.user
        )
    return out