Example #1
0
        Dictionary <string, int> GetKeywordsRankList(DemoPageSection model)
        {
            if (!KeywordsRankList.ContainsKey(model))
            {
                List <TextRank> textRanks = new List <TextRank>();

                var rootPage = model as DemoRootPage;
                var page     = model as DemoPage;

                if (rootPage != null)
                {
                    textRanks.Add(new TextRank(rootPage.Title, 15));
                    textRanks.Add(new TextRank(rootPage.Id, 7));
                    textRanks.Add(new TextRank(rootPage.SeoTitle, 5));
                    textRanks.Add(new TextRank(rootPage.Keywords, 3));
                }
                else if (page != null)
                {
                    textRanks.Add(new TextRank(page.Title, 5));
                    textRanks.Add(new TextRank(page.Id, 3));
                    textRanks.Add(new TextRank(page.Keywords, 3));
                    textRanks.Add(new TextRank(page.SeoTitle, 2));
                }
                else
                {
                    textRanks.Add(new TextRank(model.Title, 5));
                    textRanks.Add(new TextRank(model.Id, 3));
                }
                KeywordsRankList.Add(model, SearchAgregator.GetKeywordsRankList(textRanks));
            }
            return(KeywordsRankList[model]);
        }
Example #2
0
        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);
        }
Example #3
0
        IEnumerable <DemoSearchResult> GetRes(List <string[]> requests, DemoPageBase page, DemoPageSection section, string text)
        {
            var results = new List <DemoSearchResult>();
            var rank    = CalculateRank(requests, page, section);

            if (rank > -1)
            {
                var sr = new DemoSearchResult(page, section, rank);
                sr.Text = text;
                results.Add(sr);
            }
            return(results);
        }
Example #4
0
 public DemoSearchResult(DemoPageBase page, DemoPageSection section, int rank)
 {
     Page    = page;
     Section = section;
     Rank    = rank;
 }