Example #1
0
        public ResultSet SearchAllArticles(string terms, string type, int page, string lang)
        {
            ResultSet results = new ResultSet();

            SetContextLanguage(lang);

            int blurbLimit         = 150; // TODO: move to constant
            SearchResultsItem item = Sitecore.Context.Database.GetItem(Constants.Pages.SearchResults);

            if (item != null && !string.IsNullOrEmpty(item.SearchResultSummaryCharacterLimit.Raw))
            {
                blurbLimit = item.SearchResultSummaryCharacterLimit.Integer;
            }

            int                  totalResults   = 0;
            List <Article>       articles       = SearchHelper.PerformArticleSearch(terms, type, page, out totalResults);
            List <SearchArticle> searchArticles = new List <SearchArticle>();

            foreach (Article article in articles)
            {
                DefaultArticlePageItem articleItem = article.GetItem();
                if (articleItem == null)
                {
                    continue;
                }

                // Handle cases such as invalid link format exception
                try
                {
                    var sa = new SearchArticle
                    {
                        Title     = Common.Helpers.TextHelper.HighlightSearchTitle(terms, HttpUtility.HtmlDecode(articleItem.ContentPage.PageTitle.Rendered)),
                        Url       = articleItem.GetUrl(),
                        Thumbnail = articleItem.GetArticleThumbnailUrl(230, 129),
                        Blurb     = articleItem.GetSearchResultBlurb(blurbLimit),
                        Type      = articleItem.GetArticleType()
                    };

                    searchArticles.Add(sa);
                }
                catch (Exception ex)
                {
                    Sitecore.Diagnostics.Log.Error("Error populating search result", ex, this);
                }
            }

            results.Articles     = searchArticles;
            results.TotalMatches = totalResults;

            results.HasMoreResults = HasMoreResults(page, Constants.SEARCH_RESULTS_ENTRIES_PER_PAGE, results.Articles.Count(), totalResults);

            return(results);
        }