コード例 #1
0
        /// <summary>
        /// Binds the fields.
        /// </summary>
        private void BindFields()
        {
            int recordsToRetrieve = DataPager2.PageSize;

            // Perform search
            string   keywords     = Request.QueryString["search"];
            int      count        = 0;
            bool     cacheResults = true;
            TimeSpan cacheTimeout = new TimeSpan(0, 0, 30);

            if (String.IsNullOrEmpty(keywords))
            {
                cacheTimeout = new TimeSpan(0, 1, 0);
            }

            SearchFilterHelper filter = SearchFilterHelper.Current;

            string sort = Request.QueryString["s"];

            SearchSort sortObject = null;

            if (!String.IsNullOrEmpty(sort))
            {
                if (sort.Equals("name", StringComparison.OrdinalIgnoreCase))
                {
                    sortObject = new SearchSort("DisplayName");
                }
                else if (sort.Equals("plh", StringComparison.OrdinalIgnoreCase))
                {
                    sortObject = new SearchSort(String.Format("SalePrice{0}", CMSContext.Current.CurrencyCode));
                }
                else if (sort.Equals("phl", StringComparison.OrdinalIgnoreCase))
                {
                    sortObject = new SearchSort(String.Format("SalePrice{0}", CMSContext.Current.CurrencyCode), true);
                }
            }

            // Put default sort order if none is set
            if (sortObject == null)
            {
                sortObject = CatalogEntrySearchCriteria.DefaultSortOrder;
            }

            CatalogEntrySearchCriteria criteria = filter.CreateSearchCriteria(keywords, sortObject);

            if (_Parameters.Contains("Catalogs"))
            {
                foreach (string catalog in _Parameters["Catalogs"].ToString().Split(new char[',']))
                {
                    if (!String.IsNullOrEmpty(catalog))
                    {
                        criteria.CatalogNames.Add(catalog);
                    }
                }
            }

            if (_Parameters.Contains("NodeCode"))
            {
                foreach (string node in _Parameters["NodeCode"].ToString().Split(new char[',']))
                {
                    if (!String.IsNullOrEmpty(node))
                    {
                        criteria.CatalogNodes.Add(node);
                    }
                }
            }

            if (_Parameters.Contains("EntryClasses"))
            {
                foreach (string node in _Parameters["EntryClasses"].ToString().Split(new char[',']))
                {
                    if (!String.IsNullOrEmpty(node))
                    {
                        criteria.SearchIndex.Add(node);
                    }
                }
            }

            if (_Parameters.Contains("EntryTypes"))
            {
                foreach (string entry in _Parameters["EntryTypes"].ToString().Split(new char[',']))
                {
                    if (!String.IsNullOrEmpty(entry))
                    {
                        criteria.ClassTypes.Add(entry);
                    }
                }
            }

            if (_Parameters.Contains("RecordsPerPage"))
            {
                recordsToRetrieve = Int32.Parse(_Parameters["RecordsPerPage"].ToString());
            }

            // Bind default catalogs if none found
            if (criteria.CatalogNames.Count == 0)
            {
                CatalogDto catalogs = CatalogContext.Current.GetCatalogDto(CMSContext.Current.SiteId);
                if (catalogs.Catalog.Count > 0)
                {
                    foreach (CatalogDto.CatalogRow row in catalogs.Catalog)
                    {
                        if (row.IsActive && row.StartDate <= FrameworkContext.Current.CurrentDateTime && row.EndDate >= FrameworkContext.Current.CurrentDateTime)
                        {
                            criteria.CatalogNames.Add(row.Name);
                        }
                    }
                }
            }

            // No need to perform search if no catalogs specified
            if (criteria.CatalogNames.Count != 0)
            {
                Entries entries = filter.SearchEntries(criteria, _StartRowIndex, recordsToRetrieve, out count, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryInfo), cacheResults, cacheTimeout);
                CatalogSearchDataSource.TotalResults   = count;
                CatalogSearchDataSource.CatalogEntries = entries;
            }
            _Results = filter.Results;

            if (count == 0)
            {
                PagingHeader.Visible = false;
                PagingFooter.Visible = false;
                DataPager2.Visible   = false;
                DataPager3.Visible   = false;
                MyMenu.Visible       = false;
            }
            else
            {
                MyMenu.Filters = filter.SelectedFilters;
                MyMenu.Facets  = filter.GetFacets(cacheResults, cacheTimeout);
                MyMenu.Visible = true;
                //MyMenu.DataBind();
                PagingHeader.Visible = true;
                PagingFooter.Visible = true;
                DataPager2.Visible   = true;
                DataPager3.Visible   = true;
            }
        }
コード例 #2
0
        /// <summary>
        /// When the page loads, we'll perform the search based on the criteria defined in the query string.
        /// Some of this is automatically done by ECF, for better or for worse, other things are done by us in our
        /// public properties such as KeyWords
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            //before we conduct the search, we'd better make sure the prices are set for the user
            global::NWTD.Profile.SetSaleInformation();

            //Hide the "Add Selected items to cart" button on the top of the results
            this.srBookSearch.AddToCartTop.Visible = false;


            //The criteria for this search is going to be based on the query string.

            //first get some variables ready
            int      count        = 0;
            bool     cacheResults = true;
            TimeSpan cacheTimeout = new TimeSpan(0, 0, 30);             //by default we'll have our cache timeout after 30 seconds

            if (String.IsNullOrEmpty(this.KeyWords))
            {
                cacheTimeout = new TimeSpan(0, 1, 0);                 //if there's no keyword search, we'll up the timeout to a minute
            }
            //get the current filter
            //(ECF will automatically pull filters from the query string)
            SearchFilterHelper filter = SearchFilterHelper.Current;


            string keyWords = this.KeyWords;
            ////check to see if the KeyWords matches an ISBN Pattern
            //if(System.Text.RegularExpressions.Regex.IsMatch(keyWords, @"^[0-9-]+[a-z-0-9]?$")){ //any string of all hyphens or numbers and possibly an alpha character at the end
            //    keyWords = keyWords.Replace("-",string.Empty);
            //}


            //build the criteria based on sort and keywords
            CatalogEntrySearchCriteria criteria = filter.CreateSearchCriteria(keyWords, this.SortBy);


            // the current catalog if that's not been added yet (which it shouldn't be)
            if (criteria.CatalogNames.Count == 0)
            {
                CatalogDto catalogs = CatalogContext.Current.GetCatalogDto(CMSContext.Current.SiteId);
                if (catalogs.Catalog.Count > 0)
                {
                    foreach (CatalogDto.CatalogRow row in catalogs.Catalog)
                    {
                        if (row.IsActive && row.StartDate <= FrameworkContext.Current.CurrentDateTime && row.EndDate >= FrameworkContext.Current.CurrentDateTime)
                        {
                            criteria.CatalogNames.Add(row.Name);
                        }
                    }
                }
            }

            //Incorporate the state availablity flag
            criteria.Add(
                global::NWTD.Catalog.UserStateAvailablityField,
                new SimpleValue()
            {
                key          = string.Empty,
                value        = "y",
                locale       = "en-us",
                Descriptions = new Descriptions()
                {
                    defaultLocale = "en-us"
                }
            });

            //setting this in the helper class now
            //Lucene.Net.Search.BooleanQuery.SetMaxClauseCount(Int32.MaxValue);
            //exectute the search
            Entries entries = filter.SearchEntries(
                criteria,
                this.StartIndex,
                this.ItemsPerPage,
                out count,
                new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryInfo),
                cacheResults,
                cacheTimeout
                );

            //Lucene.Net.Search.BooleanQuery.SetMaxClauseCount(1024);
            //the number of results that were returned
            int resultsCount = entries.Entry != null?entries.Entry.Count() : 0;

            if (entries.Entry != null && entries.Entry.Count() > this.ItemsPerPage)               //ECF's search helper pads the results by 5
            {
                Entry[] entryset = entries.Entry;
                Array.Resize <Entry>(ref entryset, this.ItemsPerPage);

                entries.Entry = entryset;
            }

            int fromResult = (this.StartIndex + 1);
            int toResult   = this.StartIndex + (this.ItemsPerPage > resultsCount ? resultsCount : this.ItemsPerPage);

            //indicate to the user what page we're on
            if (resultsCount > 0)
            {
                this.litPageNumber.Text = string.Format("({0}-{1} of {2})", fromResult.ToString(), toResult.ToString(), count.ToString());
            }
            else
            {
                //this.ddlSortBy.Visible = false;
            }

            decimal numberOfPages = 1 + Convert.ToDecimal(Math.Floor(Convert.ToDouble((count / this.ItemsPerPage))));

            //if we're not on page 1, add a prev button to the pager
            if (this.PageNumber != 1)
            {
                this.blPager.Items.Add(new ListItem("Prev", SearchFilterHelper.GetQueryStringNavigateUrl("page", (PageNumber - 1).ToString())));
                this.blBottomPager.Items.Add(new ListItem("Prev", SearchFilterHelper.GetQueryStringNavigateUrl("page", (PageNumber - 1).ToString())));
            }
            //if we're not on the last page, add a next button to the pager
            if (this.PageNumber != numberOfPages)
            {
                this.blPager.Items.Add(new ListItem("Next", SearchFilterHelper.GetQueryStringNavigateUrl("page", (PageNumber + 1).ToString())));
                this.blBottomPager.Items.Add(new ListItem("Next", SearchFilterHelper.GetQueryStringNavigateUrl("page", (PageNumber + 1).ToString())));
            }

            //this.srBookSearch.ResultsGrid.ShowFooter = true;
            this.srBookSearch.ResultsGrid.Parent.Controls.AddAt(this.srBookSearch.ResultsGrid.Parent.Controls.IndexOf(this.srBookSearch.ResultsGrid) + 1, this.pnlBottomPager);

            //I can't figure out why this needs to be cast. For some reason VS is calling it a UserControl, not a SideMenu
            FiltersSideMenu.Filters = filter.SelectedFilters;

            //Only show facet if results are more than 1 - Heath Gardner 01/22/16 ////////////////////////////////////////
            FacetGroup[] facets = null;


            if (resultsCount > 1)
            {
                facets = filter.GetFacets(cacheResults, cacheTimeout);
            }

            FiltersSideMenu.Facets = facets;
            //End modify//////////////////////////////////////////////////////////////////////////////////////////////////

            //Original facet logic that was replaced with the above - Heath Gardner 01/22/16
            //FacetGroup[]  facets = filter.GetFacets(cacheResults, cacheTimeout);
            //FiltersSideMenu.Facets = facets;

            //Bind the results to our search results control
            this.srBookSearch.Entries      = entries;
            this.srBookSearch.TotalResults = count;

            //We don't want them to be able to just view everything with no search (for reasons unbeknownst to me)
            if (Request.QueryString.Count == 0)
            {
                this.srBookSearch.Visible     = false;
                this.blPager.Visible          = false;
                this.blBottomPager.Visible    = false;
                this.litPageNumber.Visible    = false;
                this.pnlBrowseCatalog.Visible = true;
                this.pnlSearchHead.Visible    = false;
                //return;
            }
            //if there are no results, we need to hide certain things
            else if (count == 0)
            {
                this.srBookSearch.Visible  = false;
                this.blPager.Visible       = false;
                this.blBottomPager.Visible = false;
                this.litPageNumber.Visible = false;
                this.pnlNoResults.Visible  = true;
                this.pnlSearchHead.Visible = false;
                //return;
            }

            if (!string.IsNullOrEmpty(this.KeyWords))
            {
                this.litSearchString.Text = string.Format("<span class=\"nwtd-searchString\">for \"{0}\"</span>", this.KeyWords);
            }

            DataBind();
        }