<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      CJCMS系列---說說項目中如何使用搜索引擎

        開源全文搜索引擎,比較火的當屬Lucene.net。

        Lucene.net是Lucene的.net移植版本,是一個開源的全文檢索引擎開發包,即它不是一個完整的全文檢索引擎,而是一個全文檢索引擎的架構,提供了完整的查詢引擎和索引引擎。開發人員可以基于Lucene.net實現全文檢索的功能。

        Lucene.net并不是一個爬行搜索引擎,也不會自動地索引內容。我們得先將要索引的文檔中的文本抽取出來,然后再將其加到Lucene.net索引中。標準的步驟是先初始化一個Analyzer、打開一個IndexWriter、然后再將文檔一個接一個地加進去。一旦完成這些步驟,索引就可以在關閉前得到優化,同時所做的改變也會生效。這個過程可能比開發者習慣的方式更加手工化一些,但卻在數據的索引上給予你更多的靈活性。

        比較麻煩的是,Lucene.net關于中文的分詞,我好想沒有找到,所以我從網上發現了盤古分詞,盤古分詞據說在中文分詞上面做的很好,所以我也就將他引入到項目中來了。

        首先是索引元,索引元怎么實現呢?為了實現通用的索引元數據,我使用了如下的抽象。

       

       1 using System;
       2 using System.Collections.Generic;
       3 using System.Linq;
       4 using System.Text;
       5 using Lucene.Net.Documents;
       6 
       7 namespace CJCMS.Framework.Lucene
       8 {
       9     public interface IIndexItem
      10     {
      11         string Id { get; set; }
      12 
      13         List<Field> IndexItemsFieldList { get; set; }
      14 
      15         void InitIndexItem();
      16     }
      17 }

       

       1 using System;
       2 using System.Collections.Generic;
       3 using System.Linq;
       4 using System.Text;
       5 using Lucene.Net.Documents;
       6 
       7 namespace CJCMS.Framework.Lucene
       8 {
       9     public interface IIndexManager
      10     {
      11         string IndexPath { get; set; }
      12 
      13         void Add(IIndexItem item);
      14 
      15         void Update(IIndexItem item);
      16 
      17         void Delete(IIndexItem item);
      18 
      19         void Delete(string Id);
      20 
      21         List<Document> Fetch(string keywords, int pageNum, int count);
      22         
      23     }
      24 }

       

       1 using System;
       2 using System.Collections.Generic;
       3 using System.Linq;
       4 using System.Text;
       5 using Lucene.Net.Search;
       6 using Lucene.Net.Index;
       7 using Lucene.Net.Analysis;
       8 using Lucene.Net.Analysis.PanGu;
       9 using Lucene.Net.Documents;
      10 using Lucene.Net.QueryParsers;
      11 
      12 namespace CJCMS.Framework.Lucene
      13 {
      14     public class DefaultIndexManager:IIndexManager
      15     {
      16         private string indexpath = "";
      17 
      18         public string IndexPath 
      19         {
      20             get { return this.indexpath; }
      21             set { value = this.indexpath; }
      22         }
      23 
      24         public DefaultIndexManager(string indexpath)
      25         {
      26             IndexPath = indexpath;
      27         }
      28 
      29         public void Add(IIndexItem item)
      30         {
      31             IndexWriter indexwriter = new IndexWriter(IndexPath, new PanGuAnalyzer(), true);
      32             Document doc = new Document();
      33             foreach (Field f in item.IndexItemsFieldList)
      34             {
      35                 doc.Add(f);
      36             }
      37             indexwriter.AddDocument(doc);
      38         }
      39 
      40         public void Update(IIndexItem item)
      41         {
      42             Delete(item);
      43             Add(item);
      44         }
      45 
      46         public void Delete(IIndexItem item)
      47         {
      48             IndexWriter indexwriter = new IndexWriter(IndexPath, new PanGuAnalyzer(), true);
      49             QueryParser queryParser = new QueryParser("ItemId", new PanGuAnalyzer()); 
      50             Query query = queryParser.Parse(item.Id);
      51             indexwriter.DeleteDocuments(query);
      52         }
      53 
      54         public void Delete(string Id)
      55         { 
      56             IndexWriter indexwriter = new IndexWriter(IndexPath, new PanGuAnalyzer(), true);
      57             QueryParser queryParser = new QueryParser("ItemId", new PanGuAnalyzer()); 
      58             Query query = queryParser.Parse(Id);
      59             indexwriter.DeleteDocuments(query);
      60         }
      61         /// <summary>
      62         /// 分頁搜索
      63         /// </summary>
      64         /// <param name="keywords"></param>
      65         /// <param name="pageNum">初始為1</param>
      66         /// <param name="count"></param>
      67         /// <returns></returns>
      68         public List<Document> Fetch(string keywords, int pageNum, int count)
      69         {
      70             IndexSearcher search = new IndexSearcher(IndexPath); 
      71             QueryParser queryParser = new QueryParser("ItemId", new PanGuAnalyzer());
      72             Query query = queryParser.Parse(keywords);
      73             Hits hits = search.Search(query);
      74             List<Document> list=new List<Document>();
      75             for(int i=(pageNum-1)*count;i<hits.Length();i++)
      76             {
      77               list.Add(hits.Doc(i));
      78             }
      79             return list;
      80         }
      81     }
      82 }
      posted @ 2012-09-06 12:20  不要理我  閱讀(566)  評論(0)    收藏  舉報
      主站蜘蛛池模板: 丰满人妻无码∧v区视频 | 色av综合av综合无码网站| 国产免费播放一区二区三区| 久久精品国产亚洲αv忘忧草| 无码A级毛片免费视频下载| 88国产精品视频一区二区三区| 精品亚洲国产成人av在线| 欧美极品色午夜在线视频| 成av免费大片黄在线观看 | 女人被狂躁到高潮视频免费软件| 日韩熟女熟妇久久精品综合| 久久午夜无码免费| 欧美寡妇xxxx黑人猛交| 日韩亚洲国产激情一区二区| 国产精品中文字幕日韩| 精品 日韩 国产 欧美 视频| 天堂av网一区二区三区| 精品国产中文字幕av| 精品无码成人片一区二区| 极品人妻少妇一区二区三区| 久久精品这里热有精品| 上犹县| 少妇激情一区二区三区视频| 熟妇人妻不卡中文字幕| 日韩有码中文在线观看| 欧美一区二区三区欧美日韩亚洲| 99久久无色码中文字幕| 国产精品大片中文字幕| 特级做a爰片毛片免费看无码| 精品日韩亚洲AV无码| 色狠狠色婷婷丁香五月| 天堂va蜜桃一区二区三区| 欧美精品日韩精品一卡| 国产资源精品中文字幕| 连平县| 最近中文国语字幕在线播放| 精品一区二区成人精品| 精品久久人人做爽综合| 五月天中文字幕mv在线| 狠狠噜天天噜日日噜视频麻豆| 中文字幕av国产精品|