class SearchController {

    @PostMapping(value = "/v1/search")
    public ResponseEntity<Object> search(@RequestBody SearchCriteria criteria) {
        long start = System.currentTimeMillis();
        LOGGER.info("Start Search API.............");

        SearchResult searchResult = new SearchResult();
        if (criteria.getSize() <= 0) {
            return ResponseUtils.buildFailureResponse(new Exception("Size should be greater than zero."));
        }
        if (criteria.getFrom() < 0) {
            return ResponseUtils.buildFailureResponse(new Exception("From should be >= zero."));
        }
        if (null == criteria.getSearchText() || StringUtils.isEmpty(criteria.getSearchText())) {
            return ResponseUtils.buildFailureResponse(new Exception("Search Text cannot be blank."));
        }
        if (null == criteria.getAg() || StringUtils.isEmpty(criteria.getAg())) {
            return ResponseUtils.buildFailureResponse(new Exception("Asset Group cannot be blank."));
        }

        try {
            searchResult = searchService.search(criteria);
        } catch (SearchException e) {
            LOGGER.error("Error in search",e);
            return ResponseUtils.buildFailureResponse(new Exception(e.getMessage()));

        } catch (Exception e) {
            LOGGER.error("Error in search",e);
            return ResponseUtils.buildSucessResponse(searchResult);

        }
        long end = System.currentTimeMillis();
        LOGGER.info("..........End Search API. Took(in ms): {}" , (end - start));
        return ResponseUtils.buildSucessResponse(searchResult);

    }

}