コード例 #1
0
        public List <Entry> BookSearch(BookFilter BookFilter)
        {
            int  count        = 0;
            bool cacheResults = true;

            TimeSpan cacheTimeout = new TimeSpan(0, 0, 30);

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

            SearchFilterHelper filter = SearchFilterHelper.Current;

            CatalogEntrySearchCriteria criteria = filter.CreateSearchCriteria(BookFilter.search, new SearchSort(BookFilter.sort));


            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);
                        }
                    }
                }
            }


            Entries entries = filter.SearchEntries(criteria, BookFilter.startIndex, BookFilter.itemsPerPage, out count, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryInfo), cacheResults, cacheTimeout);

            int resultsCount = entries.Entry != null?entries.Entry.Count() : 0;

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

            return(new List <Entry> (entries.Entry));
        }
コード例 #2
0
        protected void BindSearch()
        {
            int        count        = 0;
            bool       cacheResults = false;
            TimeSpan   cacheTimeout = new TimeSpan(0, 0, 1);
            SearchSort sort         = new SearchSort("TypeSort");

            SearchFilterHelper filter = SearchFilterHelper.Current;

            CatalogEntrySearchCriteria criteria = filter.CreateSearchCriteria(null, sort);

            criteria.CatalogNames.Add("NWTD");

            Entries entries = filter.SearchEntries(criteria, 0, 5, //ECF's API pads the results
                                                   out count,
                                                   new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryInfo),
                                                   cacheResults, cacheTimeout
                                                   );

            this.gvSearchResults.DataSource = entries.Entry;
            this.gvSearchResults.DataBind();
        }
コード例 #3
0
        public ActionResult Search(string keyWord)
        {
            // ToDo: SearchHelper and Criteria
            SearchFilterHelper searchHelper = SearchFilterHelper.Current; // the easy way

            CatalogEntrySearchCriteria criteria = searchHelper.CreateSearchCriteria(keyWord
                                                                                    , CatalogEntrySearchCriteria.DefaultSortOrder);

            criteria.RecordsToRetrieve = 25;
            criteria.StartingRecord    = 0;
            //criteria.Locale = "en"; // needed
            criteria.Locale = ContentLanguage.PreferredCulture.Name;

            int      count       = 0; // "Out"
            bool     cacheResult = true;
            TimeSpan timeSpan    = new TimeSpan(0, 10, 0);

            // ToDo: Search
            // One way of "doing it" ... retrieve it like ISearchResults (preferred, most certainly)
            ISearchResults  searchResult = searchHelper.SearchEntries(criteria);
            ISearchDocument aDoc         = searchResult.Documents.FirstOrDefault();

            int[] ints = searchResult.GetKeyFieldValues <int>();

            /* == ways of loading, keeping some old stuff for enjoying squiggles == */
            // ECF style Entries, old-school & legacy, not recommended at all...
            // ...work with DTOs if not using the ContentModel
            Entries entries = CatalogContext.Current.GetCatalogEntries(ints // Note "ints"
                                                                       , new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryInfo));

            // still interesting
            CatalogContext.Current.GetCatalogEntriesDto(ints
                                                        , new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryInfo));

            // Same thing... ECF-old-style, not recommended... if not absolutely needed...
            // Use the helper and get the entries direct
            // If entries are needed ... like for calculating discounts with legacy StoreHelper()
            Entries entriesDirect = searchHelper.SearchEntries(criteria, out count // Note the different return-types ... akward!
                                                               , new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryInfo)
                                                               , cacheResult, new TimeSpan());

            // CMS style (better)... using ReferenceConverter and ContentLoader
            List <ContentReference> refs = new List <ContentReference>();

            ints.ToList().ForEach(i => refs.Add(_referenceConverter.GetContentLink(i, CatalogContentType.CatalogEntry, 0)));

            // LoaderOptions() is new in CMS 8
            // ILanguageSelector selector = ServiceLocator.Current.GetInstance<ILanguageSelector>(); // obsolete
            _localContent = _contentLoader.GetItems(refs, new LoaderOptions()); // use this in CMS 8+

            // ToDo: Facets
            List <string> facetList = new List <string>();

            int facetGroups = searchResult.FacetGroups.Count();

            foreach (ISearchFacetGroup item in searchResult.FacetGroups)
            {
                foreach (var item2 in item.Facets)
                {
                    facetList.Add(String.Format("{0} {1} ({2})", item.Name, item2.Name, item2.Count));
                }
            }

            // Fill up the ViewModel
            var searchResultViewModel = new SearchResultViewModel();

            searchResultViewModel.totalHits = new List <string> {
                ""
            };                                                         // change
            searchResultViewModel.nodes      = _localContent.OfType <FashionNode>();
            searchResultViewModel.products   = _localContent.OfType <ShirtProduct>();
            searchResultViewModel.variants   = _localContent.OfType <ShirtVariation>();
            searchResultViewModel.allContent = _localContent;
            searchResultViewModel.facets     = facetList;

            return(View(searchResultViewModel));
        }
コード例 #4
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;
            }
        }
コード例 #5
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();
        }
コード例 #6
0
        /// <summary>
        /// Binds the results.
        /// </summary>
        private void BindResults(bool list)
        {
            SearchSort sortObject = CatalogEntrySearchCriteria.DefaultSortOrder;
            //string sort = SortBy.SelectedValue;
            //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}", SiteContext.Current.CurrencyCode).ToLower());
            //    else if (sort.Equals("phl", StringComparison.OrdinalIgnoreCase))
            //        sortObject =
            //            new SearchSort(String.Format("saleprice{0}", SiteContext.Current.CurrencyCode).ToLower(), true);
            //}

            var group = new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull);
            SearchFilterHelper         helper   = SearchFilterHelper.Current;
            CatalogEntrySearchCriteria criteria = helper.CreateSearchCriteria("", sortObject);

            //AddNodesToCriteria(criteria);
            criteria.RecordsToRetrieve = 25;
            criteria.StartingRecord    = _startRowIndex;
            criteria.ClassTypes.Add("Product");

            var searchManager = new SearchManager(AppContext.Current.ApplicationName);

            try
            {
                var results = searchManager.Search(criteria);
                if (results == null)
                {
                    return;
                }

                var resultIndexes = results.GetKeyFieldValues <int>();
                var entries       = CatalogContext.Current.GetCatalogEntries(resultIndexes, group);
                if (entries.Entry != null)
                {
                    var ds = CreateDataSource(entries, results.TotalCount);
                    if (!list)
                    {
                        EntriesList.DataSource = ds;
                        EntriesList.DataBind();
                        EntriesList.Visible = true;
                        listView.Visible    = false;
                    }
                    else
                    {
                        listView.DataSource = ds;
                        listView.DataBind();
                        EntriesList.Visible = false;
                        listView.Visible    = true;
                    }

                    if (results.TotalCount < 25)
                    {
                        DataPager3.Visible = false;
                    }
                }

                _filters = helper.SelectedFilters;
                _facets  = results.FacetGroups;

                if (_filters != null && _filters.Length > 0)
                {
                    ActiveFilterList.DataSource = _filters;
                    ActiveFilterList.DataBind();
                    ActiveFilterList.Visible = true;
                }
                else
                {
                    ActiveFilterList.Visible = false;
                }

                if (_facets != null && _facets.Length > 0)
                {
                    FilterList.Visible    = true;
                    FilterList.DataSource = _facets;
                    FilterList.DataBind();
                }
                else
                {
                    FilterList.Visible = false;
                }
            }
            catch (Exception ex)
            {
                LogManager.GetLogger(GetType()).Error(ex.Message, ex);
            }
        }