public AddOrganisationSearchResults SearchPublic(string query)
        {
            bool          queryContainsPunctuation = WordSplittingRegex.ContainsPunctuationCharacters(query);
            List <string> searchTerms = SearchHelper.ExtractSearchTermsFromQuery(query, queryContainsPunctuation);

            // Get matching organisations from our database
            List <SearchCachedOrganisation> allOrganisations = SearchRepository.CachedOrganisations;
            List <RankedAddOrganisationSearchOrganisation> matchingOrganisations = GetMatchingOrganisationsFromDatabase(allOrganisations, searchTerms, query, queryContainsPunctuation);

            List <RankedAddOrganisationSearchOrganisation> organisationsWithRankings = CalculateOrganisationRankings(matchingOrganisations, searchTerms, query, queryContainsPunctuation);
            List <RankedAddOrganisationSearchOrganisation> rankedOrganisations       = OrderOrganisationsByRank(organisationsWithRankings);

            AddOrganisationSearchResults results = ConvertOrganisationsToSearchResults(rankedOrganisations);

            return(results);
        }
示例#2
0
        public AdminSearchResultsViewModel Search(string query, bool orderByRelevance)
        {
            query = query.Trim();

            bool queryContainsPunctuation = WordSplittingRegex.ContainsPunctuationCharacters(query);

            List <string> searchTerms = SearchHelper.ExtractSearchTermsFromQuery(query, queryContainsPunctuation);

            // Do this before we run the search, in case the cache is updated whilst the search is running
            DateTime timeDetailsLoaded = SearchRepository.CacheLastUpdated;

            var results = new AdminSearchResultsViewModel
            {
                OrganisationResults          = SearchOrganisations(query, searchTerms, queryContainsPunctuation, orderByRelevance),
                UserResults                  = SearchUsers(query, searchTerms, queryContainsPunctuation, orderByRelevance),
                SearchCacheUpdatedSecondsAgo = (int)VirtualDateTime.Now.Subtract(timeDetailsLoaded).TotalSeconds,
            };

            return(results);
        }
        public List <SuggestOrganisationResult> Search(string query)
        {
            query = query.Trim().ToLower();

            bool queryContainsPunctuation = WordSplittingRegex.ContainsPunctuationCharacters(query);

            List <string> searchTerms = SearchHelper.ExtractSearchTermsFromQuery(query, queryContainsPunctuation);

            List <SearchCachedOrganisation> allOrganisations = SearchRepository.CachedOrganisations;

            List <SearchCachedOrganisation> matchingOrganisations = GetMatchingOrganisations(allOrganisations, searchTerms, queryContainsPunctuation);

            List <AutoCompleteOrganisation> organisationsWithRankings = CalculateRankings(matchingOrganisations, searchTerms, query, queryContainsPunctuation);

            List <AutoCompleteOrganisation> top10Organisations = TakeTop10RankingOrganisations(organisationsWithRankings);

            List <SuggestOrganisationResult> results = ConvertOrganisationsToSearchResults(top10Organisations);

            return(results);
        }
        public AddOrganisationSearchResults SearchPrivate(string query)
        {
            bool          queryContainsPunctuation = WordSplittingRegex.ContainsPunctuationCharacters(query);
            List <string> searchTerms = SearchHelper.ExtractSearchTermsFromQuery(query, queryContainsPunctuation);

            // Get matching organisations from our database
            List <SearchCachedOrganisation> allOrganisations = SearchRepository.CachedOrganisations;
            List <RankedAddOrganisationSearchOrganisation> matchingOrganisationsFromDatabase = GetMatchingOrganisationsFromDatabase(allOrganisations, searchTerms, query, queryContainsPunctuation);

            // Get matching organisations from Companies House API
            List <RankedAddOrganisationSearchOrganisation> matchingOrganisationsFromCompaniesHouse = GetMatchingOrganisationsFromCompaniesHouse(query);

            // Merge the results from our database and Companies House
            List <RankedAddOrganisationSearchOrganisation> matchingOrganisations = MergeMatchingOrganisations(matchingOrganisationsFromDatabase, matchingOrganisationsFromCompaniesHouse);

            List <RankedAddOrganisationSearchOrganisation> organisationsWithRankings = CalculateOrganisationRankings(matchingOrganisations, searchTerms, query, queryContainsPunctuation);

            ReduceRankingOfCompaniesHouseOrganisationsThatDoNotMatchEverySearchTermInQuery(organisationsWithRankings, searchTerms, query, queryContainsPunctuation);
            List <RankedAddOrganisationSearchOrganisation> rankedOrganisations = OrderOrganisationsByRank(organisationsWithRankings);

            AddOrganisationSearchResults results = ConvertOrganisationsToSearchResults(rankedOrganisations);

            return(results);
        }
 public static List <string> ExtractSearchTermsFromQuery(string query, bool queryContainsPunctuation)
 {
     return(WordSplittingRegex.SplitValueIntoWords(query, queryContainsPunctuation));
 }
示例#6
0
        public PagedResult <EmployerSearchModel> Search(EmployerSearchParameters searchParams, bool orderByRelevance)
        {
            List <SearchCachedOrganisation> allOrganisations = SearchRepository.CachedOrganisations
                                                               .Where(o => o.IncludeInViewingService)
                                                               .ToList();

            List <SearchCachedOrganisation> filteredOrganisations = FilterByOrganisations(allOrganisations, searchParams);

            if (searchParams.Keywords == null)
            {
                List <SearchCachedOrganisation> orderedOrganisations =
                    filteredOrganisations.OrderBy(o => o.OrganisationName.OriginalValue).ToList();

                List <SearchCachedOrganisation> paginatedResultsForAllOrganisations = PaginateResults(
                    orderedOrganisations,
                    searchParams.Page,
                    searchParams.PageSize);

                return(new PagedResult <EmployerSearchModel>
                {
                    Results = ConvertToEmployerSearchModels(paginatedResultsForAllOrganisations),
                    CurrentPage = searchParams.Page,
                    PageSize = searchParams.PageSize,
                    ActualRecordTotal = orderedOrganisations.Count,
                    VirtualRecordTotal = orderedOrganisations.Count
                });
            }

            string query = searchParams.Keywords.Trim().ToLower();

            bool queryContainsPunctuation = WordSplittingRegex.ContainsPunctuationCharacters(query);

            List <string> searchTerms = SearchHelper.ExtractSearchTermsFromQuery(query, queryContainsPunctuation);

            var matchingOrganisations = new List <SearchCachedOrganisation>();
            var convertedResults      = new List <EmployerSearchModel>();

            if (searchParams.SearchType == SearchType.NotSet)
            {
                throw new NotImplementedException();
            }

            if (searchParams.SearchType == SearchType.ByEmployerName)
            {
                matchingOrganisations = GetMatchingOrganisationsByName(
                    filteredOrganisations,
                    searchTerms,
                    query,
                    queryContainsPunctuation);

                List <RankedViewingSearchOrganisation> organisationsWithRankings = CalculateOrganisationRankings(
                    matchingOrganisations,
                    searchTerms,
                    query,
                    queryContainsPunctuation);

                List <RankedViewingSearchOrganisation> rankedOrganisations = orderByRelevance
                    ? OrderOrganisationsByRank(organisationsWithRankings)
                    : OrderOrganisationsAlphabetically(organisationsWithRankings);

                List <RankedViewingSearchOrganisation> paginatedResults = PaginateResults(
                    rankedOrganisations,
                    searchParams.Page,
                    searchParams.PageSize);

                convertedResults = ConvertRankedOrgsToEmployerSearchModels(paginatedResults);
            }

            if (searchParams.SearchType == SearchType.BySectorType)
            {
                matchingOrganisations = GetMatchingOrganisationsBySicCode(
                    filteredOrganisations,
                    searchTerms,
                    query,
                    queryContainsPunctuation);

                // Only alphabetically for SIC code search
                List <SearchCachedOrganisation> orderedOrganisations =
                    matchingOrganisations.OrderBy(o => o.OrganisationName.OriginalValue).ToList();

                List <SearchCachedOrganisation> paginatedSicCodeResults = PaginateResults(
                    orderedOrganisations,
                    searchParams.Page,
                    searchParams.PageSize);

                convertedResults = ConvertSearchCachedOrganisationsToEmployerSearchModels(paginatedSicCodeResults);
            }

            var pagedResult = new PagedResult <EmployerSearchModel>
            {
                Results            = convertedResults,
                CurrentPage        = searchParams.Page,
                PageSize           = searchParams.PageSize,
                ActualRecordTotal  = matchingOrganisations.Count,
                VirtualRecordTotal = matchingOrganisations.Count
            };

            return(pagedResult);
        }