Exemple #1
0
        /// <summary>
        /// 根据帖吧搜索查询条件构建Lucene查询条件
        /// </summary>
        /// <param name="Query"></param>
        /// <returns></returns>
        private LuceneSearchBuilder BuildLuceneSearchBuilder(BlogFullTextQuery blogQuery)
        {
            LuceneSearchBuilder searchBuilder = new LuceneSearchBuilder();
            //范围
            Dictionary <string, BoostLevel> fieldNameAndBoosts = new Dictionary <string, BoostLevel>();

            //如果查的是相关日志
            if (blogQuery.IsRelationBlog)
            {
                fieldNameAndBoosts.Add(BlogIndexDocument.Subject, BoostLevel.Hight);
                fieldNameAndBoosts.Add(BlogIndexDocument.Tag, BoostLevel.Medium);
                fieldNameAndBoosts.Add(BlogIndexDocument.OwnerCategoryName, BoostLevel.Low);
                searchBuilder.WithPhrases(fieldNameAndBoosts, blogQuery.Keywords, BooleanClause.Occur.SHOULD, false);
                searchBuilder.WithField(BlogIndexDocument.PrivacyStatus, ((int)PrivacyStatus.Public).ToString(), true, BoostLevel.Hight, true);
                searchBuilder.NotWithField(BlogIndexDocument.ThreadId.ToString(), blogQuery.CurrentThreadId.ToString());
            }
            else
            {
                switch (blogQuery.BlogRange)
                {
                case BlogRange.MYBlOG:
                    searchBuilder.WithField(BlogIndexDocument.UserId, blogQuery.LoginId.ToString(), true, BoostLevel.Hight, false);
                    break;

                case BlogRange.SOMEONEBLOG:
                    searchBuilder.WithField(BlogIndexDocument.UserId, blogQuery.UserId.ToString(), true, BoostLevel.Hight, false);
                    break;

                case BlogRange.SITECATEGORY:
                    if (blogQuery.LoginId != 0)
                    {
                        searchBuilder.WithField(BlogIndexDocument.UserId, blogQuery.LoginId.ToString(), true, BoostLevel.Hight, false);
                    }
                    if (blogQuery.UserId != 0)
                    {
                        searchBuilder.WithField(BlogIndexDocument.UserId, blogQuery.UserId.ToString(), true, BoostLevel.Hight, false);
                    }
                    if (blogQuery.SiteCategoryId != 0)
                    {
                        searchBuilder.WithField(BlogIndexDocument.SiteCategoryId, blogQuery.SiteCategoryId.ToString(), true, BoostLevel.Hight, false);
                    }
                    break;

                default:
                    break;
                }
                if (!string.IsNullOrEmpty(blogQuery.Keyword))
                {
                    switch (blogQuery.Range)
                    {
                    case BlogSearchRange.SUBJECT:
                        searchBuilder.WithPhrase(BlogIndexDocument.Subject, blogQuery.Keyword, BoostLevel.Hight, false);
                        break;

                    case BlogSearchRange.BODY:
                        searchBuilder.WithPhrase(BlogIndexDocument.Body, blogQuery.Keyword, BoostLevel.Hight, false);
                        break;

                    case BlogSearchRange.AUTHOR:
                        searchBuilder.WithPhrase(BlogIndexDocument.Author, blogQuery.Keyword, BoostLevel.Hight, false);
                        break;

                    case BlogSearchRange.TAG:
                        searchBuilder.WithPhrase(BlogIndexDocument.Tag, blogQuery.Keyword, BoostLevel.Hight, false);
                        break;

                    case BlogSearchRange.OWNERCATEGORYNAME:
                        searchBuilder.WithPhrase(BlogIndexDocument.OwnerCategoryName, blogQuery.Keyword, BoostLevel.Hight, false);
                        break;

                    default:
                        fieldNameAndBoosts.Add(BlogIndexDocument.Subject, BoostLevel.Hight);
                        fieldNameAndBoosts.Add(BlogIndexDocument.Keywords, BoostLevel.Hight);
                        fieldNameAndBoosts.Add(BlogIndexDocument.Tag, BoostLevel.Medium);
                        fieldNameAndBoosts.Add(BlogIndexDocument.Summary, BoostLevel.Medium);
                        fieldNameAndBoosts.Add(BlogIndexDocument.Body, BoostLevel.Medium);
                        fieldNameAndBoosts.Add(BlogIndexDocument.OwnerCategoryName, BoostLevel.Medium);
                        fieldNameAndBoosts.Add(BlogIndexDocument.Author, BoostLevel.Low);
                        searchBuilder.WithPhrases(fieldNameAndBoosts, blogQuery.Keyword, BooleanClause.Occur.SHOULD, false);
                        break;
                    }
                }

                //某个站点分类
                if (blogQuery.SiteCategoryId != 0)
                {
                    searchBuilder.WithField(BlogIndexDocument.SiteCategoryId, blogQuery.SiteCategoryId.ToString(), true, BoostLevel.Hight, true);
                }

                if (!(UserContext.CurrentUser != null && UserContext.CurrentUser.UserId == blogQuery.LoginId && blogQuery.AllId != 0))
                {
                    searchBuilder.NotWithField(BlogIndexDocument.PrivacyStatus, ((int)PrivacyStatus.Private).ToString());
                }
            }

            //筛选
            //全部、某人的日志
            if (blogQuery.AllId != 0)
            {
                if (blogQuery.LoginId != 0)
                {
                    searchBuilder.WithField(BlogIndexDocument.UserId, blogQuery.LoginId.ToString(), true, BoostLevel.Hight, true);
                }
                else if (blogQuery.UserId != 0)
                {
                    searchBuilder.WithField(BlogIndexDocument.UserId, blogQuery.UserId.ToString(), true, BoostLevel.Hight, true);
                }
            }

            //过滤可以显示的日志
            switch (publiclyAuditStatus)
            {
            case PubliclyAuditStatus.Again:
            case PubliclyAuditStatus.Fail:
            case PubliclyAuditStatus.Pending:
            case PubliclyAuditStatus.Success:
                searchBuilder.WithField(BlogIndexDocument.AuditStatus, ((int)publiclyAuditStatus).ToString(), true, BoostLevel.Hight, true);
                break;

            case PubliclyAuditStatus.Again_GreaterThanOrEqual:
            case PubliclyAuditStatus.Pending_GreaterThanOrEqual:
                searchBuilder.WithinRange(BlogIndexDocument.AuditStatus, ((int)publiclyAuditStatus).ToString(), ((int)PubliclyAuditStatus.Success).ToString(), true);
                break;
            }

            return(searchBuilder);
        }
Exemple #2
0
        /// <summary>
        /// 根据微博搜索查询条件构建Lucene查询条件
        /// </summary>
        /// <param name="userQuery"></param>
        /// <returns></returns>
        private LuceneSearchBuilder BuildLuceneSearchBuilder(MicroblogFullTextQuery microblogQuery)
        {
            LuceneSearchBuilder searchBuilder = new LuceneSearchBuilder();
            //微博搜索词匹配范围
            string fieldName = null;

            switch (microblogQuery.SearchRange)
            {
            case MicroblogSearchRange.TOPIC:
                fieldName = MicroblogIndexDocument.Topic;
                break;

            default:
                fieldName = MicroblogIndexDocument.Body;
                break;
            }
            if (microblogQuery.Keywords != null && microblogQuery.Keywords.Count() != 0)
            {
                //是否模糊查询
                if (microblogQuery.IsFuzzy)
                {
                    searchBuilder.WithPhrases(fieldName, microblogQuery.Keywords, BoostLevel.Hight, false);
                }
                else
                {
                    searchBuilder.WithFields(fieldName, microblogQuery.Keywords, true, BoostLevel.Hight, false);
                }
            }
            else
            {
                searchBuilder.WithPhrase(fieldName, microblogQuery.Keyword, BoostLevel.Hight);
            }

            //微博搜索条件过滤
            switch (microblogQuery.SearchTerm)
            {
            case MicroblogSearchTerm.ISORIGINALITY:
                searchBuilder.WithField(MicroblogIndexDocument.IsOriginality, 1, true, BoostLevel.Hight, true);
                break;

            case MicroblogSearchTerm.HASPHOTO:
                searchBuilder.WithField(MicroblogIndexDocument.HasPhoto, 1, true, BoostLevel.Hight, true);
                break;

            case MicroblogSearchTerm.HASMUSIC:
                searchBuilder.WithField(MicroblogIndexDocument.HasMusic, 1, true, BoostLevel.Hight, true);
                break;

            case MicroblogSearchTerm.HASVIDEO:
                searchBuilder.WithField(MicroblogIndexDocument.HasVideo, 1, true, BoostLevel.Hight, true);
                break;

            default:
                break;
            }

            ////筛选租户类型
            //if (!string.IsNullOrEmpty(microblogQuery.TenantTypeId))
            //{
            //    searchBuilder.WithField(MicroblogIndexDocument.TenantTypeId, microblogQuery.TenantTypeId, true, BoostLevel.Hight, true);
            //}
            if (!microblogQuery.IsGroup)
            {
                searchBuilder.NotWithField(MicroblogIndexDocument.TenantTypeId, TenantTypeIds.Instance().Group());
            }

            //微博排序
            searchBuilder.SortByString(MicroblogIndexDocument.DateCreated, true);

            return(searchBuilder);
        }
Exemple #3
0
        /// <summary>
        /// 根据照片搜索条件构建lucene查询条件
        /// </summary>
        /// <param name="query">查询条件</param>
        /// <returns>lucene条件</returns>
        private LuceneSearchBuilder BuildLuceneSearchBuilder(PhotoFullTextQuery query)
        {
            LuceneSearchBuilder             searchBuilder      = new LuceneSearchBuilder();
            Dictionary <string, BoostLevel> fieldNameAndBoosts = new Dictionary <string, BoostLevel>();

            if (query.UserId > 0)
            {
                searchBuilder.WithField(PhotoIndexDocument.UserId, query.UserId.ToString(), true, BoostLevel.Hight, false);
            }

            if (!string.IsNullOrEmpty(query.Keyword))
            {
                switch (query.Filter)
                {
                case PhotoSearchRange.DESCRIPTION:
                    searchBuilder.WithPhrase(PhotoIndexDocument.Description, query.Keyword, BoostLevel.Hight, false);
                    break;

                case PhotoSearchRange.AUTHOR:
                    searchBuilder.WithPhrase(PhotoIndexDocument.Author, query.Keyword, BoostLevel.Hight, false);
                    break;

                case PhotoSearchRange.TAG:
                    searchBuilder.WithPhrase(PhotoIndexDocument.Tag, query.Keyword, BoostLevel.Hight, false);
                    break;

                default:
                    fieldNameAndBoosts.Add(PhotoIndexDocument.Tag, BoostLevel.Hight);
                    fieldNameAndBoosts.Add(PhotoIndexDocument.Description, BoostLevel.Hight);
                    fieldNameAndBoosts.Add(PhotoIndexDocument.Author, BoostLevel.Medium);
                    searchBuilder.WithPhrases(fieldNameAndBoosts, query.Keyword, BooleanClause.Occur.SHOULD, false);
                    break;
                }
            }

            //筛选 全部、某人的照片
            if (query.UserId > 0)
            {
                searchBuilder.WithField(PhotoIndexDocument.UserId, query.UserId.ToString(), true, BoostLevel.Hight, true);
            }

            //过滤审核状态和隐私状态
            if (!query.IgnoreAuditAndPrivacy)
            {
                searchBuilder.NotWithField(PhotoIndexDocument.PrivacyStatus, ((int)PrivacyStatus.Private).ToString());
                switch (publiclyAuditStatus)
                {
                case PubliclyAuditStatus.Again:
                case PubliclyAuditStatus.Fail:
                case PubliclyAuditStatus.Pending:
                case PubliclyAuditStatus.Success:
                    searchBuilder.WithField(PhotoIndexDocument.AuditStatus, ((int)publiclyAuditStatus).ToString(), true, BoostLevel.Hight, true);
                    break;

                case PubliclyAuditStatus.Again_GreaterThanOrEqual:
                case PubliclyAuditStatus.Pending_GreaterThanOrEqual:
                    searchBuilder.WithinRange(PhotoIndexDocument.AuditStatus, ((int)publiclyAuditStatus).ToString(), ((int)PubliclyAuditStatus.Success).ToString(), true);
                    break;
                }
            }

            return(searchBuilder);
        }
        /// <summary>
        /// 根据帖吧搜索查询条件构建Lucene查询条件
        /// </summary>
        /// <param name="Query"></param>
        /// <returns></returns>
        private LuceneSearchBuilder BuildLuceneSearchBuilder(JournalFullTextQuery journalQuery)
        {
            LuceneSearchBuilder searchBuilder = new LuceneSearchBuilder();
            //范围
            Dictionary <string, BoostLevel> fieldNameAndBoosts = new Dictionary <string, BoostLevel>();

            //如果查的是相关日志
            if (journalQuery.IsRelationJournal)
            {
                fieldNameAndBoosts.Add(JournalIndexDocument.journalname, BoostLevel.Hight);
                fieldNameAndBoosts.Add(JournalIndexDocument.subcat, BoostLevel.Medium);
                fieldNameAndBoosts.Add(JournalIndexDocument.publisher, BoostLevel.Low);
                searchBuilder.WithPhrases(fieldNameAndBoosts, journalQuery.Keywords, BooleanClause.Occur.SHOULD, false);
                //searchBuilder.WithField(JournalIndexDocument.PrivacyStatus, ((int)PrivacyStatus.Public).ToString(), true, BoostLevel.Hight, true);
                searchBuilder.NotWithField(JournalIndexDocument.id.ToString(), journalQuery.CurrentThreadId.ToString());
            }
            else
            {
                switch (journalQuery.JournalRange)
                {
                /*case JournalRange.MYBlOG:
                 *  searchBuilder.WithField(JournalIndexDocument.UserId, journalQuery.LoginId.ToString(), true, BoostLevel.Hight, false);
                 *  break;
                 * case JournalRange.SOMEONEBLOG:
                 *  searchBuilder.WithField(JournalIndexDocument.UserId, journalQuery.UserId.ToString(), true, BoostLevel.Hight, false);
                 *  break;
                 * case JournalRange.SITECATEGORY:
                 *  if (journalQuery.LoginId != 0)
                 *      searchBuilder.WithField(JournalIndexDocument.UserId, journalQuery.LoginId.ToString(), true, BoostLevel.Hight, false);
                 *  if (journalQuery.UserId != 0)
                 *      searchBuilder.WithField(JournalIndexDocument.UserId, journalQuery.UserId.ToString(), true, BoostLevel.Hight, false);
                 *  if (journalQuery.SiteCategoryId != 0)
                 *      searchBuilder.WithField(JournalIndexDocument.SiteCategoryId, journalQuery.SiteCategoryId.ToString(), true, BoostLevel.Hight, false);
                 *  break;**/
                default:
                    break;
                }
                if (!string.IsNullOrEmpty(journalQuery.Keyword))
                {
                    switch (journalQuery.Range)
                    {
                    /*case JournalSearchRange.SUBJECT:
                     *  searchBuilder.WithPhrase(JournalIndexDocument.Subject, journalQuery.Keyword, BoostLevel.Hight, false);
                     *  break;
                     * case JournalSearchRange.BODY:
                     *  searchBuilder.WithPhrase(JournalIndexDocument.Body, journalQuery.Keyword, BoostLevel.Hight, false);
                     *  break;
                     * case JournalSearchRange.AUTHOR:
                     *  searchBuilder.WithPhrase(JournalIndexDocument.Author, journalQuery.Keyword, BoostLevel.Hight, false);
                     *  break;
                     * case JournalSearchRange.TAG:
                     *  searchBuilder.WithPhrase(JournalIndexDocument.Tag, journalQuery.Keyword, BoostLevel.Hight, false);
                     *  break;
                     * case JournalSearchRange.OWNERCATEGORYNAME:
                     *  searchBuilder.WithPhrase(JournalIndexDocument.OwnerCategoryName, journalQuery.Keyword, BoostLevel.Hight, false);
                     *  break;*/
                    default:
                        fieldNameAndBoosts.Add(JournalIndexDocument.journalname, BoostLevel.Hight);
                        fieldNameAndBoosts.Add(JournalIndexDocument.publisher, BoostLevel.Hight);
                        fieldNameAndBoosts.Add(JournalIndexDocument.subcat, BoostLevel.Medium);
                        fieldNameAndBoosts.Add(JournalIndexDocument.jdescrip, BoostLevel.Medium);
                        fieldNameAndBoosts.Add(JournalIndexDocument.abbr, BoostLevel.Medium);
                        //fieldNameAndBoosts.Add(JournalIndexDocument.OwnerCategoryName, BoostLevel.Medium);
                        //fieldNameAndBoosts.Add(JournalIndexDocument.Author, BoostLevel.Low);
                        searchBuilder.WithPhrases(fieldNameAndBoosts, journalQuery.Keyword, BooleanClause.Occur.SHOULD, false);
                        break;
                    }
                }

                //某个站点分类

                /*if (journalQuery.SiteCategoryId != 0)
                 * {
                 *  searchBuilder.WithField(JournalIndexDocument.SiteCategoryId, journalQuery.SiteCategoryId.ToString(), true, BoostLevel.Hight, true);
                 * }
                 *
                 * if (!(UserContext.CurrentUser != null && UserContext.CurrentUser.UserId == journalQuery.LoginId && journalQuery.AllId != 0))
                 * {
                 *  searchBuilder.NotWithField(JournalIndexDocument.PrivacyStatus, ((int)PrivacyStatus.Private).ToString());
                 * }*/
            }

            //筛选
            //全部、某人的日志

            /*if (journalQuery.AllId != 0)
             * {
             *  if (journalQuery.LoginId != 0)
             *  {
             *      searchBuilder.WithField(JournalIndexDocument.UserId, journalQuery.LoginId.ToString(), true, BoostLevel.Hight, true);
             *  }
             *  else if (journalQuery.UserId != 0)
             *  {
             *      searchBuilder.WithField(JournalIndexDocument.UserId, journalQuery.UserId.ToString(), true, BoostLevel.Hight, true);
             *  }
             * }
             */
            //过滤可以显示的日志

            /*switch (publiclyAuditStatus)
             * {
             *  case PubliclyAuditStatus.Again:
             *  case PubliclyAuditStatus.Fail:
             *  case PubliclyAuditStatus.Pending:
             *  case PubliclyAuditStatus.Success:
             *      searchBuilder.WithField(JournalIndexDocument.AuditStatus, ((int)publiclyAuditStatus).ToString(), true, BoostLevel.Hight, true);
             *      break;
             *  case PubliclyAuditStatus.Again_GreaterThanOrEqual:
             *  case PubliclyAuditStatus.Pending_GreaterThanOrEqual:
             *      searchBuilder.WithinRange(JournalIndexDocument.AuditStatus, ((int)publiclyAuditStatus).ToString(), ((int)PubliclyAuditStatus.Success).ToString(), true);
             *      break;
             * }*/

            return(searchBuilder);
        }