/// <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) { #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="keywords"></param> /// <param name="pagerInfo"></param> /// <returns></returns> public List <SchoolSample> SearchSchoolList(string keywords, PagerInfo pagerInfo) { List <SchoolSample> list = new List <SchoolSample>(); try { BooleanQuery query = new BooleanQuery(); if (!string.IsNullOrEmpty(keywords)) { string[] keywordsParts = StringHelper.Split <string>(keywords, StringSplitOptions.RemoveEmptyEntries, " ", ","); foreach (string keywordsPart in keywordsParts) { string lowerCaseKeywordsPart = keywordsPart.ToLower(); BooleanQuery groupQuery = new BooleanQuery(); groupQuery.Add(new WildcardQuery(new Term("Name", "*" + keywordsPart + "*")), Lucene.Net.Search.BooleanClause.Occur.SHOULD); groupQuery.Add(new WildcardQuery(new Term("CnName", "*" + keywordsPart + "*")), Lucene.Net.Search.BooleanClause.Occur.SHOULD); groupQuery.Add(new WildcardQuery(new Term("Pinyin", "*" + keywordsPart + "*")), Lucene.Net.Search.BooleanClause.Occur.SHOULD); groupQuery.Add(new WildcardQuery(new Term("LC_Name", "*" + lowerCaseKeywordsPart + "*")), Lucene.Net.Search.BooleanClause.Occur.SHOULD); groupQuery.Add(new WildcardQuery(new Term("LC_CnName", "*" + lowerCaseKeywordsPart + "*")), Lucene.Net.Search.BooleanClause.Occur.SHOULD); groupQuery.Add(new WildcardQuery(new Term("LC_Pinyin", "*" + lowerCaseKeywordsPart + "*")), Lucene.Net.Search.BooleanClause.Occur.SHOULD); query.Add(groupQuery, BooleanClause.Occur.MUST); } Sort sort = null; LuceneManager.SearchLuceneData(LuceneTextIndexType.AllSchool, query, sort, pagerInfo, delegate(Document doc) { SchoolSample school = new SchoolSample(doc); list.Add(school); }); } } catch (Exception ex) { LogHelper.WriteLog(ex); pagerInfo.RecordCount = 0; } return(list); }
public List <SchoolSample> SearchList(string keywords, PagerInfo pagerInfo) { List <SchoolSample> list = new List <SchoolSample>(); try { BooleanQuery query = new BooleanQuery(); if (!string.IsNullOrEmpty(keywords)) { string[] keywordsParts = keywords.Split(' ', ','); foreach (string keywordsPart in keywordsParts) { string lowerCaseKeywordsPart = keywordsPart.ToLower(); BooleanQuery groupQuery = new BooleanQuery(); groupQuery.Add(new WildcardQuery(new Term("CnName", "*" + lowerCaseKeywordsPart + "*")), BooleanClause.Occur.SHOULD); groupQuery.Add(new WildcardQuery(new Term("Pinyin", "*" + lowerCaseKeywordsPart + "*")), BooleanClause.Occur.SHOULD); query.Add(groupQuery, BooleanClause.Occur.MUST); } } Sort sort = null; string textIndexDir = LuceneManager.GetLuceneTextIndexDirectoryPath(LuceneTextIndexType.ChinaUniversity, null); LuceneManager.SearchLuceneData(textIndexDir, query, sort, pagerInfo, delegate(Document doc) { SchoolSample school = new SchoolSample(doc); list.Add(school); }); } catch (Exception ex) { pagerInfo.RecordCount = 0; } return(list); }
/// <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); } }
/// <summary> /// 按关键词搜索文章 /// </summary> /// <param name="keywords"></param> /// <param name="pagerInfo"></param> /// <returns></returns> public List <LuceneArticle> SearchArticleList(string keywords, PagerInfo pagerInfo) { List <LuceneArticle> list = new List <LuceneArticle>(); BooleanQuery query = new BooleanQuery(); if (!string.IsNullOrEmpty(keywords)) { string[] keywordsParts = keywords.Split(',');//逗号分隔 foreach (string keywordsPart in keywordsParts) { string lowerCaseKeywordsPart = keywordsPart.ToLower(); BooleanQuery groupQuery = new BooleanQuery(); groupQuery.Add(new WildcardQuery(new Term("Id", "*" + keywordsPart + "*")), BooleanClause.Occur.SHOULD); groupQuery.Add(new WildcardQuery(new Term("Title", "*" + keywordsPart + "*")), BooleanClause.Occur.SHOULD); groupQuery.Add(new WildcardQuery(new Term("Content", "*" + keywordsPart + "*")), BooleanClause.Occur.SHOULD); query.Add(groupQuery, BooleanClause.Occur.MUST); } Sort sort = null; try { List <Document> documentList = LuceneManager.SearchLuceneData(directoryPath, query, sort, pagerInfo, null); if (documentList != null && documentList.Count > 0) { documentList.ForEach(item => { list.Add(new LuceneArticle(item)); }); } } catch (Exception ex) { LogHelper.Info(this, ex.ToString()); pagerInfo.RecordCount = 0; } } return(list); }