IEnumerable <DemoSearchResult> DoSearch(List <string[]> requests, DemoRootPage rootPage)
        {
            var results = new List <DemoSearchResult>();

            foreach (var page in rootPage.Pages)
            {
                int resultCount = results.Count;
                foreach (var section in page.PageSections)
                {
                    results.AddRange(GetRes(requests, page, section, DemoSearchAgregator.HighlightOccurences(section.Title, requests)));
                }
                if (results.Count == resultCount)
                {
                    results.AddRange(GetRes(requests, page, null, DemoSearchAgregator.HighlightOccurences(page.Title, requests)));
                }
            }
            results.AddRange(GetRes(requests, rootPage, null, DemoSearchAgregator.HighlightOccurences(rootPage.Title, requests)));
            return(results);
        }
        int CalculateRank(List <string[]> requests, DemoPageBase page, DemoPageSection section)
        {
            int resultRank  = 0;
            int keywordRank = 0;

            foreach (var request in requests)
            {
                int requestRank = -1;
                if (section != null && page is DemoPage && ((DemoPage)page).PageSections.Length > 1 && DemoSearchAgregator.CalculateRank(request, GetKeywordsRankList(section), out keywordRank))
                {
                    requestRank += keywordRank;
                }
                if (page != null && DemoSearchAgregator.CalculateRank(request, GetKeywordsRankList(page), out keywordRank))
                {
                    requestRank += keywordRank;
                }
                if (page is DemoRootPage && DemoSearchAgregator.CalculateRank(request, GetKeywordsRankList(page), out keywordRank))
                {
                    requestRank += keywordRank;
                }
                if (requestRank == -1 && SearchAgregator.WordsExclusions.Any(re => re.Equals(request[0], DemoSearchAgregator.DefaultStringComparison)))
                {
                    requestRank = 0;
                }

                if (requestRank > -1)
                {
                    resultRank += requestRank;
                }
                else
                {
                    return(-1);
                }
            }
            return(resultRank);
        }
 public DemoSearchHelper(DemoSearchModel searchModel, IEnumerable <DemoRootPage> rootPages)
 {
     RootPages       = rootPages;
     SearchAgregator = new DemoSearchAgregator(searchModel);
 }