[TestCase("uk", "uk")]                                                                                 // Do NOT replace (user might to search by 'uk')
        public void EmployerSearchParameters_RemoveTheMostCommonTermsOnOurDatabaseFromTheKeywords(string keywordsToClean,
                                                                                                  string expectedOutcome)
        {
            // Arrange
            var employerSearchParameters = new EmployerSearchParameters {
                Keywords = keywordsToClean
            };

            // Act
            string actualOutcome = employerSearchParameters.RemoveTheMostCommonTermsOnOurDatabaseFromTheKeywords();

            // Assert
            Assert.AreEqual(expectedOutcome, actualOutcome);
        }
        public async Task <SearchViewModel> SearchAsync(EmployerSearchParameters searchParams)
        {
            var searchResults = new PagedResult <EmployerSearchModel>();

            var facets = new Dictionary <string, Dictionary <object, long> >();

            facets.Add("Size", null);
            facets.Add("SicSectionIds", null);
            facets.Add("ReportedYears", null);
            facets.Add("ReportedLateYears", null);
            facets.Add("ReportedExplanationYears", null);

            var searchTermEnteredOnScreen = searchParams.Keywords;

            if (searchParams.SearchType == SearchTypes.BySectorType)
            {
                var list =
                    await GetListOfSicCodeSuggestionsFromIndexAsync(searchParams.Keywords);

                searchParams.FilterCodeIds = list.Select(x => int.Parse(x.Value.SicCodeId));

                #region Log the search

                if (!string.IsNullOrEmpty(searchParams.Keywords))
                {
                    var detailedListOfReturnedSearchTerms =
                        string.Join(", ", list.Take(5).Select(x => x.Value.ToLogFriendlyString()));

                    var telemetryProperties = new Dictionary <string, string>
                    {
                        { "TimeStamp", VirtualDateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") },
                        { "QueryTerms", searchParams.Keywords },
                        { "ResultCount", list.Count().ToString() },
                        { "SearchType", searchParams.SearchType.ToString() },
                        { "SampleOfResultsReturned", detailedListOfReturnedSearchTerms }
                    };

                    //SharedBusinessLogic.SharedOptions.AppInsightsClient?.TrackEvent("Gpg_SicCode_Suggest", telemetryProperties);

                    await _viewingService.SearchBusinessLogic.SearchLog.WriteAsync(telemetryProperties);
                }

                #endregion

                searchParams.SearchFields =
                    $"{nameof(EmployerSearchModel.SicCodeIds)};{nameof(EmployerSearchModel.SicCodeListOfSynonyms)}";
                searchParams.Keywords = "*"; // searchTermModified

                if (list.Any())
                {
                    searchResults = await DoSearchAsync(searchParams, facets);
                }
            }

            if (searchParams.SearchType == SearchTypes.ByEmployerName)
            {
                searchParams.Keywords = searchParams.Keywords?.Trim();
                searchParams.Keywords = searchParams.RemoveTheMostCommonTermsOnOurDatabaseFromTheKeywords();
                searchResults         = await DoSearchAsync(searchParams, facets);
            }

            // build the result view model
            return(new SearchViewModel
            {
                SizeOptions = GetOrgSizeOptions(searchParams.FilterEmployerSizes, facets["Size"]),
                SectorOptions = await GetSectorOptionsAsync(searchParams.FilterSicSectionIds, facets["SicSectionIds"]),
                ReportingYearOptions = GetReportingYearOptions(searchParams.FilterReportedYears),
                ReportingStatusOptions = GetReportingStatusOptions(searchParams.FilterReportingStatus),
                Employers = searchResults,
                search = searchTermEnteredOnScreen,
                p = searchParams.Page,
                s = searchParams.FilterSicSectionIds,
                es = searchParams.FilterEmployerSizes,
                y = searchParams.FilterReportedYears,
                st = searchParams.FilterReportingStatus,
                t = searchParams.SearchType.ToInt32().ToString()
            });
        }