Beispiel #1
0
        /// <summary>
        /// 生成所有索引
        /// </summary>
        /// <param name="itemCallback"></param>
        public void MakeLuceneIndex(Action <Document> callback)
        {
            #region 大学专业

            SpecialtyDao     dao  = new SpecialtyDao();
            List <Specialty> list = dao.GetSpecialtyList();

            PanGuAnalyzer analyzer = new PanGuAnalyzer(true);

            string textIndexDir = LuceneManager.GetLuceneTextIndexDirectoryPath(LuceneTextIndexType.Specialty, null);

            List <Document> documentList = new List <Document>();
            foreach (Specialty item in list)
            {
                Document indexDoc = new Document();

                #region 根据需要添加要被索引的数据列

                indexDoc.Add(new NumericField("SpecialtyId", Field.Store.YES, true).SetIntValue(item.SpecialtyId));
                indexDoc.Add(new Field("Name", item.Name.ToLower(), Field.Store.YES, Field.Index.ANALYZED));
                #endregion 根据需要添加要被索引的数据列

                documentList.Add(indexDoc);
            }
            LuceneManager.MakeIndex(documentList, textIndexDir, callback);

            #endregion
        }
        /// <summary>
        /// 生成所有索引
        /// </summary>
        /// <param name="itemCallback"></param>
        public void MakeLuceneIndex(Action <Document> callback)
        {
            #region 中国大学

            ChinaUniversityDao     chinaUniverisityDao = new ChinaUniversityDao();
            List <ChinaUniversity> universityList      = chinaUniverisityDao.GetChinaUniversityList();

            PanGuAnalyzer analyzer = new PanGuAnalyzer(true);

            string textIndexDir = LuceneManager.GetLuceneTextIndexDirectoryPath(LuceneTextIndexType.ChinaUniversity, null);

            List <Document> documentList = new List <Document>();
            foreach (ChinaUniversity university in universityList)
            {
                Document indexDoc = new Document();

                #region 根据需要添加要被索引的数据列

                indexDoc.Add(new NumericField("UniversityId", Field.Store.YES, true).SetIntValue(university.UniversityId));
                indexDoc.Add(new Field("CnName", university.Name.ToLower(), Field.Store.YES, Field.Index.ANALYZED));
                indexDoc.Add(new Field("Pinyin", university.Pinyin.ToLower(), Field.Store.YES, Field.Index.ANALYZED));
                #endregion 根据需要添加要被索引的数据列

                documentList.Add(indexDoc);
            }
            LuceneManager.MakeIndex(documentList, textIndexDir, callback);

            #endregion 中国大学
        }
        /// <summary>
        /// 生成所有院校索引
        /// </summary>
        /// <param name="itemCallback"></param>
        public void MakeAllSchoolIndex(Action <Document> callback)
        {
            #region 所有海外大学

            string directoryPath = ConfigurationManager.AppSettings["UNIVERTITY_INDEX_FILE_DIRECTORY"].ToString();
            OverseaUniversityDao     overseaUniversityDao = new OverseaUniversityDao();
            List <OverseaUniversity> universityList       = overseaUniversityDao.Backstage_GetAllUniversityList();
            List <Document>          documentList         = new List <Document>();
            foreach (OverseaUniversity university in universityList)
            {
                Document indexDoc = new Document();

                #region 根据需要添加要被索引的数据列
                indexDoc.Add(new Field("Key", string.Concat("OverseaUniversity_", university.UniversityId), Field.Store.YES, Field.Index.ANALYZED));
                indexDoc.Add(new NumericField("SchoolId", Field.Store.YES, true).SetIntValue(university.UniversityId));
                indexDoc.Add(new Field("Name", university.Name, Field.Store.YES, Field.Index.ANALYZED));
                indexDoc.Add(new Field("LC_Name", university.Name.ToLower(), Field.Store.NO, Field.Index.ANALYZED));
                indexDoc.Add(new Field("CnName", university.CnName, Field.Store.YES, Field.Index.ANALYZED));
                indexDoc.Add(new Field("LC_CnName", university.CnName.ToLower(), Field.Store.NO, Field.Index.ANALYZED));
                indexDoc.Add(new Field("Pinyin", university.Pinyin, Field.Store.YES, Field.Index.ANALYZED));
                indexDoc.Add(new Field("LC_Pinyin", university.Pinyin.ToLower(), Field.Store.NO, Field.Index.ANALYZED));
                #endregion

                documentList.Add(indexDoc);
                LuceneManager.MakeIndex(documentList, directoryPath, callback);

                #endregion
            }
        }
        /// <summary>
        /// 生成文章索引
        /// </summary>
        /// <param name="itemCallback"></param>
        public void MakeLuceneIndex(Action <Document> callback)
        {
            List <Article>  list         = dao.GetArticleList();
            List <Document> documentList = new List <Document>();

            foreach (Article item in list)
            {
                Document indexDoc = new Document();

                #region 根据需要添加要被索引的数据列

                indexDoc.Add(new Field("Id", string.Concat("", item.Id), Field.Store.YES, Field.Index.ANALYZED));
                indexDoc.Add(new Field("Title", item.Title, Field.Store.YES, Field.Index.ANALYZED));
                indexDoc.Add(new Field("Content", item.Content, Field.Store.YES, Field.Index.ANALYZED));

                #endregion 根据需要添加要被索引的数据列

                documentList.Add(indexDoc);
                LuceneManager.MakeIndex(documentList, directoryPath, callback);
            }
        }