@require_POST<EOL>def do_search(request, course_id=None):
<EOL>SearchInitializer.set_search_enviroment(request=request, course_id=course_id)<EOL>results = {<EOL>"<STR_LIT:error>": _("<STR_LIT>")<EOL>}<EOL>status_code = <NUM_LIT><EOL>search_term = request.POST.get("<STR_LIT>", None)<EOL>try:<EOL><INDENT>if not search_term:<EOL><INDENT>raise ValueError(_('<STR_LIT>'))<EOL><DEDENT>size, from_, page = _process_pagination_values(request)<EOL>track.emit(<EOL>'<STR_LIT>',<EOL>{<EOL>"<STR_LIT>": search_term,<EOL>"<STR_LIT>": size,<EOL>"<STR_LIT>": page,<EOL>}<EOL>)<EOL>results = perform_search(<EOL>search_term,<EOL>user=request.user,<EOL>size=size,<EOL>from_=from_,<EOL>course_id=course_id<EOL>)<EOL>status_code = <NUM_LIT:200><EOL>track.emit(<EOL>'<STR_LIT>',<EOL>{<EOL>"<STR_LIT>": search_term,<EOL>"<STR_LIT>": size,<EOL>"<STR_LIT>": page,<EOL>"<STR_LIT>": results["<STR_LIT>"],<EOL>}<EOL>)<EOL><DEDENT>except ValueError as invalid_err:<EOL><INDENT>results = {<EOL>"<STR_LIT:error>": six.text_type(invalid_err)<EOL>}<EOL>log.debug(six.text_type(invalid_err))<EOL><DEDENT>except QueryParseError:<EOL><INDENT>results = {<EOL>"<STR_LIT:error>": _('<STR_LIT>')<EOL>}<EOL><DEDENT>except Exception as err:  <EOL><INDENT>results = {<EOL>"<STR_LIT:error>": _('<STR_LIT>').format(search_string=search_term)<EOL>}<EOL>log.exception(<EOL>'<STR_LIT>',<EOL>search_term,<EOL>request.user.id,<EOL>err<EOL>)<EOL><DEDENT>return JsonResponse(results, status=status_code)<EOL>
Search view for http requests

Args:
    request (required) - django request object
    course_id (optional) - course_id within which to restrict search

Returns:
    http json response with the following fields
        "took" - how many seconds the operation took
        "total" - how many results were found
        "max_score" - maximum score from these results
        "results" - json array of result documents

        or

        "error" - displayable information about an error that occured on the server

POST Params:
    "search_string" (required) - text upon which to search
    "page_size" (optional)- how many results to return per page (defaults to 20, with maximum cutoff at 100)
    "page_index" (optional) - for which page (zero-indexed) to include results (defaults to 0)