@RequestMapping(method = RequestMethod.GET, params = "q")
  public String refineSearch(
      @RequestParam("q") final String searchQuery,
      @RequestParam(value = "page", defaultValue = "0") final int page,
      @RequestParam(value = "show", defaultValue = "Page") final ShowMode showMode,
      @RequestParam(value = "sort", required = false) final String sortCode,
      @RequestParam(value = "text", required = false) final String searchText,
      final HttpServletRequest request,
      final Model model)
      throws CMSItemNotFoundException {
    final ProductSearchPageData<SearchStateData, ProductData> searchPageData =
        performSearch(searchQuery, page, showMode, sortCode, getSearchPageSize());

    populateModel(model, searchPageData, showMode);
    model.addAttribute("userLocation", customerLocationService.getUserLocation());

    if (searchPageData.getPagination().getTotalNumberOfResults() == 0) {
      updatePageTitle(searchPageData.getFreeTextSearch(), model);
      storeCmsPageInModel(model, getContentPageForLabelOrId(NO_RESULTS_CMS_PAGE_ID));
    } else {
      storeContinueUrl(request);
      updatePageTitle(searchPageData.getFreeTextSearch(), model);
      storeCmsPageInModel(model, getContentPageForLabelOrId(SEARCH_CMS_PAGE_ID));
    }
    model.addAttribute(
        WebConstants.BREADCRUMBS_KEY, searchBreadcrumbBuilder.getBreadcrumbs(null, searchPageData));
    model.addAttribute("pageType", PageType.PRODUCTSEARCH.name());

    final String metaDescription =
        MetaSanitizerUtil.sanitizeDescription(
            getMessageSource()
                    .getMessage(
                        "search.meta.description.results",
                        null,
                        getI18nService().getCurrentLocale())
                + " "
                + searchText
                + " "
                + getMessageSource()
                    .getMessage(
                        "search.meta.description.on", null, getI18nService().getCurrentLocale())
                + " "
                + getSiteName());
    final String metaKeywords = MetaSanitizerUtil.sanitizeKeywords(searchText);
    setUpMetaData(model, metaKeywords, metaDescription);

    return getViewForPage(model);
  }
  @RequestMapping(method = RequestMethod.GET, params = "!q")
  public String textSearch(
      @RequestParam(value = "text", defaultValue = "") final String searchText,
      final HttpServletRequest request,
      final Model model)
      throws CMSItemNotFoundException {
    if (StringUtils.isNotBlank(searchText)) {
      final PageableData pageableData =
          createPageableData(0, getSearchPageSize(), null, ShowMode.Page);

      final SearchStateData searchState = new SearchStateData();
      final SearchQueryData searchQueryData = new SearchQueryData();
      searchQueryData.setValue(XSSFilterUtil.filter(searchText));
      searchState.setQuery(searchQueryData);

      final ProductSearchPageData<SearchStateData, ProductData> searchPageData =
          productSearchFacade.textSearch(searchState, pageableData);
      if (searchPageData == null) {
        storeCmsPageInModel(model, getContentPageForLabelOrId(NO_RESULTS_CMS_PAGE_ID));
      } else if (searchPageData.getKeywordRedirectUrl() != null) {
        // if the search engine returns a redirect, just
        return "redirect:" + searchPageData.getKeywordRedirectUrl();
      } else if (searchPageData.getPagination().getTotalNumberOfResults() == 0) {
        model.addAttribute("searchPageData", searchPageData);
        storeCmsPageInModel(model, getContentPageForLabelOrId(NO_RESULTS_CMS_PAGE_ID));
        updatePageTitle(searchText, model);
      } else {
        storeContinueUrl(request);
        populateModel(model, searchPageData, ShowMode.Page);
        storeCmsPageInModel(model, getContentPageForLabelOrId(SEARCH_CMS_PAGE_ID));
        updatePageTitle(searchText, model);
      }
      model.addAttribute("userLocation", customerLocationService.getUserLocation());
      getRequestContextData(request).setSearch(searchPageData);
      if (searchPageData != null) {
        model.addAttribute(
            WebConstants.BREADCRUMBS_KEY,
            searchBreadcrumbBuilder.getBreadcrumbs(
                null, searchText, CollectionUtils.isEmpty(searchPageData.getBreadcrumbs())));
      }
    } else {
      storeCmsPageInModel(model, getContentPageForLabelOrId(NO_RESULTS_CMS_PAGE_ID));
    }
    model.addAttribute("pageType", PageType.PRODUCTSEARCH.name());
    model.addAttribute("metaRobots", "no-index,follow");

    final String metaDescription =
        MetaSanitizerUtil.sanitizeDescription(
            getMessageSource()
                    .getMessage(
                        "search.meta.description.results",
                        null,
                        getI18nService().getCurrentLocale())
                + " "
                + searchText
                + " "
                + getMessageSource()
                    .getMessage(
                        "search.meta.description.on", null, getI18nService().getCurrentLocale())
                + " "
                + getSiteName());
    final String metaKeywords = MetaSanitizerUtil.sanitizeKeywords(searchText);
    setUpMetaData(model, metaKeywords, metaDescription);

    return getViewForPage(model);
  }