国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網站 > 建站經驗 > 正文

使用Lucene.N!ET實現站內搜索

2019-11-02 15:42:22
字體:
來源:轉載
供稿:網友

   提到Lucene,想必大家都有所耳聞,已經是數年前就出現的開源技術。很多站點都是利用它搭建自己網站的站內搜索。由于最近也在做數據檢索方面的東西,也學習了下Lucene.net的使用。

  導入Lucene.NET 開發包

  Lucene 是apache軟件基金會一個開放源代碼的全文檢索引擎工具包,是一個全文檢索引擎的架構,提供了完整的查詢引擎和索引引擎,部分文本分析引擎。Lucene的目的是為軟件開發人員提供一個簡單易用的工具包,以方便的在目標系統中實現全文檢索的功能,或者是以此為基礎建立起完整的全文檢索引擎。Lucene.Net 是 .NET 版的Lucene。

  你可以在這里下載到最新的Lucene.NET

  創建索引、更新索引、刪除索引

  搜索,根據索引查找

  IndexHelper 添加、更新、刪除索引

  ?

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 using System; using Lucene.Net.Store; using Lucene.Net.Index; using Lucene.Net.Analysis.PanGu; using Lucene.Net.Documents;   namespace BLL { class IndexHelper { /// <summary> /// 日志小助手 /// </summary> static Common.LogHelper logger = new Common.LogHelper(typeof(SearchBLL)); /// <summary> /// 索引保存的位置,保存在配置文件中從配置文件讀取 /// </summary> static string indexPath = Common.ConfigurationHelper.AppSettingMapPath("IndexPath");   /// <summary> /// 創建索引文件或更新索引文件 /// </summary> /// <param name="item">索引信息</param> public static void CreateIndex(Model.HelperModel.IndexFileHelper item) { try { //索引存儲庫 FSDirectory directory = FSDirectory.Open(new System.IO.DirectoryInfo(indexPath), new NativeFSLockFactory()); //判斷索引是否存在 bool isUpdate = IndexReader.IndexExists(directory); if (isUpdate) { //如果索引目錄被鎖定(比如索引過程中程序異常退出),則首先解鎖 if (IndexWriter.IsLocked(directory)) { //解鎖索引庫 IndexWriter.Unlock(directory); } } //創建IndexWriter對象,添加索引 IndexWriter writer = new IndexWriter(directory, new PanGuAnalyzer(), !isUpdate, Lucene.Net.Index.IndexWriter.MaxFieldLength.UNLIM
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 长沙市| 高青县| 莎车县| 泰兴市| 临武县| 浠水县| 咸阳市| 准格尔旗| 佛坪县| 托克逊县| 余庆县| 喀什市| 建平县| 荥阳市| 内黄县| 扎赉特旗| 宣化县| 玛纳斯县| 旬邑县| 德州市| 谢通门县| 柘荣县| 保靖县| 丹东市| 平度市| 琼结县| 手机| 辉南县| 赤壁市| 瑞安市| 商河县| 西林县| 穆棱市| 天等县| 丹寨县| 定结县| 库车县| 新田县| 陕西省| 房山区| 富阳市|