Example #1
0
        /// <summary>
        /// Gets the root keyword for the given <see cref="P:taxonomyUri" />
        /// </summary>
        /// <param name="taxonomyUri">Taxonomy <see cref="T:TcmCDService.Tridion.TcmUri" /></param>
        /// <param name="taxonomyFilter"><see cref="T:TcmCDService.Contracts.TaxonomyFilter" /></param>
        /// <param name="taxonomyFilter"><see cref="T:TcmCDService.Contracts.TaxonomyFilter" /> to apply.</param>
        /// <returns><see cref="T:Tridion.ContentDelivery.Taxonomies.Keyword" /></returns>
        internal static Keyword GetKeywords(TcmUri taxonomyUri, Contracts.TaxonomyFilter taxonomyFilter, Contracts.TaxonomyFormatter taxonomyFormatter)
        {
            return(mInstance.ProcessItem(0, (factory) =>
            {
                TaxonomyFormatter formatter;

                switch (taxonomyFormatter)
                {
                case Contracts.TaxonomyFormatter.List:
                    formatter = new TaxonomyListFormatter();
                    break;

                case Contracts.TaxonomyFormatter.HierarchyRelink:
                    formatter = new TaxonomyHierarchyFormatter(true);
                    break;

                default:
                    formatter = new TaxonomyHierarchyFormatter();
                    break;
                }

                if (taxonomyFilter == null)
                {
                    return factory.GetTaxonomyKeywords(taxonomyUri, formatter);
                }
                else
                {
                    using (TaxonomyFilter filter = taxonomyFilter.ToTaxonomyFilter())
                    {
                        return factory.GetTaxonomyKeywords(taxonomyUri, filter, formatter);
                    }
                }
            }));
        }
Example #2
0
        public ActionResult HealthIS_Blog_CategoryAndTagPage(int?page)
        {
            HealthIS.Apps.MVC.Blog.Models.ListPage lp = new HealthIS.Apps.MVC.Blog.Models.ListPage();
            lp.PageSize = Int32.Parse(lp.CurrentPage.Fields["Page Size"].Value);

            if (Request["name"] == null || String.IsNullOrEmpty(Request["name"].Trim()))
            {
                lp.ParameterName = "No Result Found";
                //return PartialView(lp);
                return(Redirect("/is/blog"));
            }

            string searchTerm = Request["name"].ToLower().Trim();
            string filterName = "";

            if (lp.CurrentPage.Name.ToLower().Trim() == "category" && Request["name"] != null)
            {
                filterName = "healthisblogcategory";
                Item categoryItem = lp.CategoryRepository.Axes.GetDescendants().Where(d => d.Fields["Key"].Value.ToLower() == searchTerm).FirstOrDefault();
                if (categoryItem != null)
                {
                    lp.ParameterName = categoryItem.Fields["Phrase"].Value;
                }
                else
                {
                    lp.ParameterName = searchTerm;
                }
            }
            else if (lp.CurrentPage.Name.ToLower().Trim() == "tag" && Request["name"] != null)
            {
                filterName       = "healthisblogtag";
                lp.ParameterName = searchTerm;
            }
            else
            {
                return(PartialView(lp));
            }

            if (!String.IsNullOrEmpty(filterName))
            {
                if (String.IsNullOrEmpty(searchTerm))
                {
                    searchTerm = "";
                }

                lp.AllArticles = TaxonomyFilter.GetSearchPredicate(lp.CurrentPage, filterName, searchTerm)
                                 .Where(l => l != null && l.Versions.IsLatestVersion())
                                 //.Distinct()
                                 .OrderBy(o => o.Statistics.Created)
                                 .Reverse()
                                 .ToList();
            }

            return(PartialView(lp));
        }
Example #3
0
        private void processData()
        {
            try
            {
                if (this.SearchList != null)
                {
                    // Validate();

                    int actualMaxResult = this.SearchList.MaxResults;

                    DateTime startDate = StartDate, endDate = EndDate;
                    string   keyWord  = KeyWords;
                    string   siteName = SiteName;
                    if (this.SearchList.SearchType == "keyword")
                    {
                        startDate = DateTime.MinValue;
                        endDate   = DateTime.MaxValue;
                    }
                    else if (this.SearchList.SearchType == "date")
                    {
                        keyWord = string.Empty;
                    }

                    int year = 0;
                    Dictionary <string, string> filters = GetUrlFilters();
                    if (startDate == DateTime.MinValue && endDate == DateTime.MaxValue && filters.ContainsKey("year"))
                    {
                        try
                        {
                            year = Int32.Parse(filters["year"]);
                            if (filters.ContainsKey("month"))
                            {
                                try
                                {
                                    int month   = Int32.Parse(filters["month"]);
                                    int lastDay = DateTime.DaysInMonth(year, month);
                                    startDate = new DateTime(year, month, 1);
                                    endDate   = new DateTime(year, month, lastDay);
                                }
                                catch
                                {
                                    NCI.Web.CDE.Application.ErrorPageDisplayer.RaisePageByCode("BaseSearchSnippet", 404, "Invalid month parameter in dynamic list filter");
                                }
                            }
                            else
                            {
                                startDate = new DateTime(year, 1, 1);
                                endDate   = new DateTime(year, 12, 31);
                            }
                        }
                        catch
                        {
                            NCI.Web.CDE.Application.ErrorPageDisplayer.RaisePageByCode("BaseSearchSnippet", 404, "Invalid year parameter in dynamic list filter");
                        }
                    }

                    if (startDate == DateTime.MinValue && endDate == DateTime.MaxValue && filters.ContainsKey("month") && !filters.ContainsKey("year"))
                    {
                        NCI.Web.CDE.Application.ErrorPageDisplayer.RaisePageByCode("BaseSearchSnippet", 404, "Invalid parameter in dynamic list filter: cannot have month without year");
                    }

                    List <TaxonomyFilter> filtersForSql = new List <TaxonomyFilter>(this.SearchList.SearchFilters.TaxonomyFilters.Where(filter => filter.Taxons.Count() > 0));
                    foreach (KeyValuePair <string, string> entry in filters)
                    {
                        if (entry.Key != "year" && entry.Key != "month")
                        {
                            bool contains = filtersForSql.Any(filter => filter.TaxonomyName == entry.Key);
                            if (!contains)
                            {
                                TaxonomyFilter newFilter = new TaxonomyFilter();
                                newFilter.TaxonomyName = entry.Key;
                                List <int>   taxonIDs  = entry.Value.Split(',').Select(Int32.Parse).ToList();
                                List <Taxon> newTaxons = new List <Taxon>();
                                foreach (int ID in taxonIDs)
                                {
                                    Taxon newTaxon = new Taxon();
                                    newTaxon.ID = ID;
                                    newTaxons.Add(newTaxon);
                                }
                                newFilter.Taxons = newTaxons.ToArray <Taxon>();
                                filtersForSql.Add(newFilter);
                            }
                        }
                    }


                    // Call the  datamanger to perform the search
                    ICollection <SearchResult> searchResults =
                        SearchDataManager.Execute(CurrentPage,
                                                  startDate,
                                                  endDate,
                                                  keyWord,
                                                  ReturnTaxonomySqlParam(filtersForSql),
                                                  this.SearchList.RecordsPerPage,
                                                  this.SearchList.MaxResults,
                                                  this.SearchList.SearchFilter,
                                                  this.SearchList.ExcludeSearchFilter,
                                                  this.SearchList.ResultsSortOrder,
                                                  this.SearchList.Language,
                                                  Settings.IsLive,
                                                  out actualMaxResult, siteName);

                    DynamicSearch dynamicSearch = new DynamicSearch();
                    dynamicSearch.Results         = searchResults;
                    dynamicSearch.StartDate       = String.Format("{0:MM/dd/yyyy}", startDate);
                    dynamicSearch.EndDate         = String.Format("{0:MM/dd/yyyy}", endDate);
                    dynamicSearch.KeyWord         = keyWord;
                    dynamicSearch.SiteName        = siteName;
                    dynamicSearch.DisqusShortname = this.SearchList.DisqusShortname;
                    dynamicSearch.SearchTitle     = this.SearchList.SearchTitle;

                    // check if the site is in production
                    bool isProd = PageAssemblyContext.Current.IsProd;
                    // append a shortname prefix based on the production state
                    dynamicSearch.DisqusShortname = dynamicSearch.DisqusShortname + (isProd ? "-prod" : "-dev");

                    this.PageInstruction.AddUrlFilter("Print", (name, url) =>
                    {
                        if (url.QueryParameters.ContainsKey("keyword") == false)
                        {
                            url.QueryParameters.Add("keyword", keyWord);
                        }
                        if (!((dynamicSearch.StartDate == "01/01/0001") || (dynamicSearch.EndDate == "12/31/9999")))
                        {
                            url.QueryParameters.Add("startmonth", startDate.Month.ToString());
                            url.QueryParameters.Add("startyear", startDate.Year.ToString());
                            url.QueryParameters.Add("endmonth", endDate.Month.ToString());
                            url.QueryParameters.Add("endyear", endDate.Year.ToString());
                        }
                    });

                    if (actualMaxResult > 0)
                    {
                        if (CurrentPage > 1)
                        {
                            dynamicSearch.StartCount = (this.SearchList.RecordsPerPage * (CurrentPage - 1)) + 1;
                        }
                        else
                        {
                            dynamicSearch.StartCount = 1;
                        }

                        if (CurrentPage == 1)
                        {
                            dynamicSearch.EndCount = this.SearchList.RecordsPerPage;
                            if (searchResults.Count < this.SearchList.RecordsPerPage)
                            {
                                dynamicSearch.EndCount = actualMaxResult;
                            }
                        }
                        else
                        {
                            dynamicSearch.EndCount = dynamicSearch.StartCount + this.SearchList.RecordsPerPage - 1;
                            if (searchResults.Count < this.SearchList.RecordsPerPage)
                            {
                                dynamicSearch.EndCount = actualMaxResult;
                            }
                        }
                    }

                    int recCount = 0;
                    foreach (SearchResult sr in searchResults)
                    {
                        sr.RecNumber = dynamicSearch.StartCount + recCount++;
                    }

                    int validCount = this.SearchList.MaxResults;

                    if (actualMaxResult < this.SearchList.MaxResults || this.SearchList.MaxResults == 0)
                    {
                        validCount = actualMaxResult;
                    }
                    else
                    {
                        validCount = this.SearchList.MaxResults;
                    }

                    dynamicSearch.ResultCount = validCount;
                    LiteralControl ltl = new LiteralControl(VelocityTemplate.MergeTemplateWithResultsByFilepath(this.SearchList.ResultsTemplate, dynamicSearch));
                    Controls.Add(ltl);

                    if (this.SearchList.ResultsTemplate.Contains("Blog"))
                    {
                        SetupBlogPager(this.SearchList.RecordsPerPage, validCount, filters);
                    }
                    else
                    {
                        SetupPager(this.SearchList.RecordsPerPage, validCount, filters);
                    }
                }
            }
            catch (ThreadAbortException)
            {
                throw;
            }
            catch (Exception ex)
            {
                log.Error("this.SearchListSnippet:processData", ex);
            }
        }