Пример #1
0
        private void DumpSearchResults(IEnumerable <ID> searchResults)
        {
            List <Tuple <SearchResult, Item> > results = new List <Tuple <SearchResult, Item> >();

            foreach (ID id in searchResults)
            {
                Item relatedItem = Sitecore.Context.Database.GetItem(id);

                Field titleField = relatedItem?.Fields["Title"];

                if (titleField != null)
                {
                    results.Add(new Tuple <SearchResult, Item>(BuildResult(relatedItem, titleField), relatedItem));
                }
            }

            ResultRepeater.DataSource = results;

            ResultRepeater.DataBind();
        }
Пример #2
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            string searchType = Strings.Clean(Request.Params["cbsubmit"]);
            int    startMonth = Strings.ToInt(Strings.Clean(Request.Params["startMonth"]));
            int    startYear  = Strings.ToInt(Strings.Clean(Request.Params["startYear"]));
            int    endMonth   = Strings.ToInt(Strings.Clean(Request.Params["endMonth"]));
            int    endYear    = Strings.ToInt(Strings.Clean(Request.Params["endYear"]));

            keyword = Strings.Clean(Request.Params["cbkeyword"]);
            int  currentPage  = Strings.ToInt(Strings.Clean(Request.Params["page"]));
            bool bSearchRange = false;

            if (Page.Request.HttpMethod == "POST")
            {
                bSearchRange = (Request.Params["searchRangeButton"] != null);
            }
            else
            {
                bSearchRange = (searchType != null && string.Compare(searchType, "range", true) == 0);
            }



            firstRecord = 0;
            lastRecord  = 0;
            totalItems  = 0;

            if (currentPage < 0)
            {
                currentPage = 1;
            }
            int pageSize = 10;

            if (keyword == null)
            {
                resultsHtml = "<br><br>Please enter a search phrase.<br><br><br>";
            }
            else
            {
                firstRecord = (currentPage - 1) * pageSize + 1;
                recordIndex = firstRecord;

                //set up the search collection
                //determine what text needs to be removed from the title e.g. - National Cancer Institute
                SiteWideSearchConfig searchConfig = ModuleObjectFactory <SiteWideSearchConfig> .GetModuleObject(SnippetInfo.Data);

                if (searchConfig != null)
                {
                    SearchCollection = searchConfig.SearchCollection;
                    ResultTitleText  = searchConfig.ResultTitleText;
                }

                ISiteWideSearchResultCollection results;
                try
                {
                    results = NCI.Search.SiteWideSearch.GetSearchResults(SearchCollection, Keyword, pageSize,
                                                                         (currentPage - 1) * pageSize);

                    if (results != null && results.ResultCount > 0)
                    {
                        lastRecord = firstRecord + (int)results.ResultCount - 1;
                        totalItems = (int)results.ResultCount;

                        ResultRepeater.DataSource = results;
                        ResultRepeater.DataBind();

                        //pager code
                        string urlFormat;
                        string pagerUrl;
                        if (bSearchRange)
                        {
                            urlFormat = PrettyUrl + "?cbsubmit=range&cbkeyword={0}&startMonth={1}&startYear={2}&endMonth={3}&endYear={4}";
                            pagerUrl  = String.Format(urlFormat, Server.UrlEncode(keyword), startMonth.ToString(), startYear.ToString(), endMonth.ToString(), endYear.ToString());
                        }
                        else
                        {
                            urlFormat = PrettyUrl + "?cbkeyword={0}";
                            pagerUrl  = String.Format(urlFormat, Server.UrlEncode(keyword));
                        }

                        ResultPager objPager = new ResultPager(pagerUrl, currentPage, pageSize, 2, totalItems);
                        pager = objPager.RenderPager();
                    }
                    else
                    {
                        firstRecord = 0;
                    }
                }
                catch (Exception ex)
                {
                    //capture exactly which keyword caused the error
                    log.ErrorFormat("{0} - Search with the following keyword returned an error: {1}", ex, PrettyUrl, Keyword);
                    this.RaiseErrorPage();
                }


                //eSearch.FillSearchResults(eSearchResults);
            }

            this.PageInstruction.AddFieldFilter("channelName", (fieldName, data) =>
            {
                data.Value = "Newsletter";
            });
        }