Beispiel #1
0
        /// <summary>
        /// Gets posts by tag, label, author, or all posts.
        /// </summary>
        /// <param name="node"> </param>
        /// <param name="tag"></param>
        /// <param name="label"></param>
        /// <param name="author"></param>
        /// <param name="searchTerm"> </param>
        /// <param name="commenter"> </param>
        /// <returns></returns>
        public IEnumerable <SearchResult> GetPosts(IPublishedContent node, string tag, string label, string author, string searchTerm, string commenter, string year, string month, string day, out int postCount)
        {
            var searcher = ExamineManager.Instance.SearchProviderCollection["ExternalSearcher"];
            var criteria = GetPostBaseCriteria(node, searcher);

            // add criteria for tags
            criteria = ExamineSearchHelper.AddSvCriteria(criteria, uBlogsy.BusinessLogic.Constants.Examine.uBlogsySearchableTags, tag, ",");

            // add criteria for labels
            criteria = ExamineSearchHelper.AddSvCriteria(criteria, uBlogsy.BusinessLogic.Constants.Examine.uBlogsySearchableLabels, label, ",");

            // add criteria for authors
            criteria = ExamineSearchHelper.AddSvCriteria(criteria, uBlogsy.BusinessLogic.Constants.Examine.uBlogsySearchableAuthor, author, ",");

            // add criteria for year
            criteria = ExamineSearchHelper.AddSvCriteria(criteria, uBlogsy.BusinessLogic.Constants.Examine.uBlogsySearchableYear, year, ",");

            // add criteria for month
            criteria = ExamineSearchHelper.AddSvCriteria(criteria, uBlogsy.BusinessLogic.Constants.Examine.uBlogsySearchableMonth, month, ",");

            criteria = ExamineSearchHelper.AddSvCriteria(criteria, uBlogsy.BusinessLogic.Constants.Examine.uBlogsySearchableDay, day, ",");

            // do search using InternalSearcher
            //var postList = new UmbracoHelper(UmbracoContext.Current).TypedSearch(criteria, searcher);

            IEnumerable <SearchResult> postList = searcher.Search(criteria).ToList();

            // now filter by commenter - does another examine search and filters results
            postList = GetPostsByCommenter(node, commenter, postList);

            // do search using term - does another examine search and combines results
            postList = GetPostsBySearchTerm(node, searchTerm, postList);

            // sort and return
            var sorted = postList
                         .Distinct(new ExamineSearchResultEqualityComparer())
                         .ToList()
                         .OrderByDescending(x => x.GetValue("uBlogsyPostDate"));

            postCount = sorted.Count();

            return(sorted);
        }
Beispiel #2
0
        /// <summary>
        /// Gets posts which have a related tag or label
        /// </summary>
        /// <param name="node"></param>
        /// <param name="itemAlias"></param>
        /// <param name="matchCount"> </param>
        /// <returns></returns>
        public IEnumerable <SearchResult> GetRelatedPosts(IPublishedContent node, string itemAlias, int matchCount)
        {
            // get all posts
            var searcher = ExamineManager.Instance.SearchProviderCollection["ExternalSearcher"];
            var criteria = GetPostBaseCriteria(node, searcher);
            var nodes    = new List <SearchResult>();

            if (!string.IsNullOrEmpty(itemAlias))
            {
                var values = node.GetPropertyValue <string>(itemAlias);
                criteria = ExamineSearchHelper.AddSvCriteria(criteria, itemAlias == "uBlogsyPostTags" ? uBlogsy.BusinessLogic.Constants.Examine.uBlogsySearchableTagIds : uBlogsy.BusinessLogic.Constants.Examine.uBlogsySearchableLabelIds, values, ",");
                var res = searcher.Search(criteria);
                nodes.AddRange(res);
            }
            else
            {
                var tags   = node.GetPropertyValue <string>("uBlogsyPostTags");
                var labels = node.GetPropertyValue <string>("uBlogsyPostLabels");

                // search by tags
                criteria = ExamineSearchHelper.AddSvCriteria(criteria, uBlogsy.BusinessLogic.Constants.Examine.uBlogsySearchableTagIds, tags, ",");
                var resultByTags = searcher.Search(criteria);

                // search by labels
                criteria = GetPostBaseCriteria(node, searcher);
                criteria = ExamineSearchHelper.AddSvCriteria(criteria, uBlogsy.BusinessLogic.Constants.Examine.uBlogsySearchableLabelIds, labels, ",");
                var resultByLabels = searcher.Search(criteria);

                // get both tags and labels
                nodes.AddRange(resultByTags);
                nodes.AddRange(resultByLabels);
            }

            // get distinct, and order by date
            return(nodes.Distinct(new ExamineSearchResultEqualityComparer()).Where(x => x.Id != node.Id));
        }