class SearchController {

    @ResponseBody
    @RequestMapping(value = "/search", method = RequestMethod.POST)
    public ResponseEntity<String> searchForFiles(@RequestParam("searchedText") final String searchedText, final HttpSession session) {
        List<List<String>> searchResult = new ArrayList<List<String>>();
        ResponseEntity<String> result;
        HttpHeaders responseHeaders = setHeadersForJSON();
        try {
            searchResult = searchForText(searchedText);
            addResultToSession(searchResult, session);
            if (!indexStatus.isReady()) {
                result = new ResponseEntity<String>(getJson(searchResult), responseHeaders, HttpStatus.PARTIAL_CONTENT);
            } else {
                result = new ResponseEntity<String>(getJson(searchResult), responseHeaders, HttpStatus.CREATED);
            }
        } catch (QueryCannotBeParsedException e) {
            logger.warn("Invalid query");
            result = new ResponseEntity<String>(QUERY_ERROR_MESSAGE, HttpStatus.BAD_REQUEST);
        }
        return result;
    }

}