Пример #1
0
        private void BindRelatedItemRepeater()
        {
            IEnumerable <Guid> categories =
                Sitecore.Context.Item.Fields["Categories"].Value.Split("|".ToCharArray(),
                                                                       StringSplitOptions.RemoveEmptyEntries).Select(Parse).Where(a => a != Guid.Empty);

            IIndexSearchService searchService = new IndexSearchService(new QueryBuilder(true));

            SearchParameters parameters = SearchResultsManager.BuildSearchParameters();

            parameters.Facets.Clear();

            parameters.Facets.Add(new SearchParametersFacet
            {
                Name           = "Categories",
                SelectedValues = categories.Select(SearchResultsManager.Clean)
            });

            var results = searchService.Search(parameters);

            RelatedItemRepeater.DataSource = results.SearchResults
                                             .Where(a => a.Guid != Sitecore.Context.Item.ID.Guid)
                                             .Take(5)
                                             .Select(b => Sitecore.Context.Database.GetItem(b));

            RelatedItemRepeater.DataBind();
        }
Пример #2
0
 protected void SearchClick(object sender, EventArgs e)
 {
     if (SearchTerm.Text.Trim().Length > 0)
     {
         Response.Redirect(SearchResultsManager.AddSearchToUrl(SearchTerm.Text));
     }
 }
Пример #3
0
        protected string AddFacetToUrl(object dataItem)
        {
            Tuple <FacetValue, Item, string> tuple = dataItem as Tuple <FacetValue, Item, string>;

            Url url = new Url(Request.RawUrl);

            url.RemoveQueryParam(SearchResultsManager.PageQueryString);

            List <Guid> allFacets = SearchResultsManager.ExtractFacetsFromQueryString(QueryStringParameter);

            if (allFacets.Contains(tuple.Item2.ID.Guid))
            {
                allFacets.Remove(tuple.Item2.ID.Guid);
            }
            else
            {
                allFacets.Add(tuple.Item2.ID.Guid);
            }

            string fullQueryString = String.Join("|", allFacets.Distinct());

            url.QueryParams[QueryStringParameter] = fullQueryString;

            return(url);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            int currentPage = SearchResultsManager.CurrentPage();

            bool hasNextPage = currentPage < TotalPages;

            PreviousUrl = new PaginationEntry
            {
                ItemUrl = SearchResultsManager.SetPage(currentPage - 1)
            };

            FirstUrl = new PaginationEntry
            {
                ItemUrl = SearchResultsManager.SetPage(0)
            };

            LastUrl = new PaginationEntry
            {
                ItemUrl = SearchResultsManager.SetPage(TotalPages)
            };

            NextUrl = new PaginationEntry
            {
                ItemUrl = SearchResultsManager.SetPage(currentPage + 1)
            };

            if (currentPage == 0)
            {
                FirstUrl.CssClass = PreviousUrl.CssClass = "disabled";
                FirstUrl.ItemUrl  = PreviousUrl.ItemUrl = "#";
            }

            if (!hasNextPage)
            {
                LastUrl.CssClass = NextUrl.CssClass = "disabled";
                LastUrl.ItemUrl  = NextUrl.ItemUrl = "#";
            }

            List <PaginationEntry> entries = new List <PaginationEntry>();

            for (int i = 0; i <= TotalPages; i++)
            {
                entries.Add(new PaginationEntry
                {
                    ItemUrl  = SearchResultsManager.SetPage(i),
                    Text     = (i + 1).ToString(),
                    CssClass = i == currentPage ? "active" : ""
                });
            }

            if (entries.Count > MaxPaginationEntries)
            {
                entries = CenterEntries(entries, currentPage).ToList();
            }

            ResultsRepeater.DataSource = entries;

            ResultsRepeater.DataBind();
        }
Пример #5
0
        private SearchParameters BuildSearchParameters()
        {
            string searchTerm = HttpContext.Current.Request.QueryString[SearchResultsManager.SearchTermQueryString];

            SearchTerm.Text = searchTerm;

            return(SearchResultsManager.BuildSearchParameters());
        }
Пример #6
0
 private static IList <SearchParametersFacet> BuildFacets()
 {
     return(new List <SearchParametersFacet>
     {
         new SearchParametersFacet
         {
             Name = "Categories",
             SelectedValues = SearchResultsManager.ExtractCategoriesFromQueryString().Select(Clean)
         },
         new SearchParametersFacet
         {
             Name = "Journal Types",
             SelectedValues = SearchResultsManager.ExtractJournalTypesFromQueryString().Select(Clean)
         }
     });
 }
Пример #7
0
 protected void ResetClick(object sender, EventArgs e)
 {
     Response.Redirect(SearchResultsManager.RemoveSearchTerm());
 }
Пример #8
0
 protected bool AnyFacets()
 {
     return(SearchResultsManager.ExtractFacetsFromQueryString(QueryStringParameter).Any());
 }
Пример #9
0
        protected bool FacetExists(object dataItem)
        {
            Tuple <FacetValue, Item, string> tuple = dataItem as Tuple <FacetValue, Item, string>;

            return(SearchResultsManager.ExtractFacetsFromQueryString(QueryStringParameter).Contains(tuple.Item2.ID.Guid));
        }