lucene.net 3.0.3、结合盘古分词进行搜索的小例子(分页功能)

.net5 开启Lucene的全文搜索之旅 .net 平台下的lucene.net 开源项目维护进度一直不是很理想,因为需要移植的包太多,因此维护者的进度比较慢,虽然网上有一些文章是针对.net core平台移植之前3.0.3版本的改造版,但文章数目极少,能有个参考已经很不错了,因此我就把今天的趟坑之旅写出来,以供大家实施中参考。 1、Lucene介绍 按照惯例,先抄袭一段描述,这里省略8000字,自己脑补吧。 简言之,Lucene就是apache基金会下的开源全文搜索类库,其强劲的搜索能力不是其他类库可以比拟的。而Lucene.net是 其.n. 阅读详情

转自:http://blog.youkuaiyun.com/pukuimin1226/article/details/17558247

//封装类

  
[csharp] view plain copy print ?
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Web;  
  5. using Lucene.Net.Analysis;  
  6. using Lucene.Net.Index;  
  7. using Lucene.Net.Documents;  
  8. using System.Reflection;  
  9. using Lucene.Net.QueryParsers;  
  10. using Lucene.Net.Search;  
  11. namespace SearchTest  
  12. {  
  13.     /// <summary>  
  14.     /// 盘古分词在lucene.net中的使用帮助类  
  15.     /// 调用PanGuLuceneHelper.instance  
  16.     /// </summary>  
  17.     public class PanGuLuceneHelper  
  18.     {  
  19.         private PanGuLuceneHelper() { }  
  20.  
  21.         #region 单一实例  
  22.         private static PanGuLuceneHelper _instance = null;  
  23.         /// <summary>  
  24.         /// 单一实例  
  25.         /// </summary>  
  26.         public static PanGuLuceneHelper instance  
  27.         {  
  28.             get  
  29.             {  
  30.                 if (_instance == null) _instance = new PanGuLuceneHelper();  
  31.                 return _instance;  
  32.             }  
  33.         }  
  34.         #endregion  
  35.  
  36.         #region 分词测试  
  37.         /// <summary>  
  38.         /// 分词测试  
  39.         /// </summary>  
  40.         /// <param name="keyword"></param>  
  41.         /// <returns></returns>  
  42.         public string Token(string keyword)  
  43.         {  
  44.             string ret = "";  
  45.             System.IO.StringReader reader = new System.IO.StringReader(keyword);  
  46.             Lucene.Net.Analysis.TokenStream ts = analyzer.TokenStream(keyword, reader);  
  47.             bool hasNext = ts.IncrementToken();  
  48.             Lucene.Net.Analysis.Tokenattributes.ITermAttribute ita;  
  49.             while (hasNext)  
  50.             {  
  51.                 ita = ts.GetAttribute<Lucene.Net.Analysis.Tokenattributes.ITermAttribute>();  
  52.                 ret += ita.Term + "|";  
  53.                 hasNext = ts.IncrementToken();  
  54.             }  
  55.             ts.CloneAttributes();  
  56.             reader.Close();  
  57.             analyzer.Close();  
  58.             return ret;  
  59.         }  
  60.         #endregion  
  61.  
  62.         #region 创建索引  
  63.         /// <summary>  
  64.         /// 创建索引  
  65.         /// </summary>  
  66.         /// <param name="datalist"></param>  
  67.         /// <returns></returns>  
  68.         public bool CreateIndex(List<MySearchUnit> datalist)  
  69.         {  
  70.             IndexWriter writer = null;  
  71.             try  
  72.             {  
  73.                 writer = new IndexWriter(directory_luce, analyzer, false, IndexWriter.MaxFieldLength.LIMITED);//false表示追加(true表示删除之前的重新写入)  
  74.             }  
  75.             catch  
  76.             {  
  77.                 writer = new IndexWriter(directory_luce, analyzer, true, IndexWriter.MaxFieldLength.LIMITED);//false表示追加(true表示删除之前的重新写入)  
  78.             }  
  79.             foreach (MySearchUnit data in datalist)  
  80.             {  
  81.                 CreateIndex(writer, data);  
  82.             }  
  83.             writer.Optimize();  
  84.             writer.Dispose();  
  85.             return true;  
  86.         }  
  87.   
  88.         public bool CreateIndex(IndexWriter writer, MySearchUnit data)  
  89.         {  
  90.             try  
  91.             {  
  92.   
  93.                 if (data == null) return false;  
  94.                 Document doc = new Document();  
  95.                 Type type = data.GetType();//assembly.GetType("Reflect_test.PurchaseOrderHeadManageModel", true, true); //命名空间名称 + 类名      
  96.   
  97.                 //创建类的实例      
  98.                 //object obj = Activator.CreateInstance(type, true);    
  99.                 //获取公共属性      
  100.                 PropertyInfo[] Propertys = type.GetProperties();  
  101.                 for (int i = 0; i < Propertys.Length; i++)  
  102.                 {  
  103.                     //Propertys[i].SetValue(Propertys[i], i, null); //设置值  
  104.                     PropertyInfo pi = Propertys[i];  
  105.                     string name=pi.Name;  
  106.                     object objval = pi.GetValue(data, null);  
  107.                     string value = objval == null ? "" : objval.ToString(); //值  
  108.                     if (name == "id" || name=="flag" )//id在写入索引时必是不分词,否则是模糊搜索和删除,会出现混乱  
  109.                     {  
  110.                         doc.Add(new Field(name, value, Field.Store.YES, Field.Index.NOT_ANALYZED));//id不分词  
  111.                     }  
  112.                     else  
  113.                     {  
  114.                         doc.Add(new Field(name, value, Field.Store.YES, Field.Index.ANALYZED));  
  115.                     }  
  116.                 }  
  117.                 writer.AddDocument(doc);  
  118.             }  
  119.             catch (System.IO.FileNotFoundException fnfe)  
  120.             {  
  121.                 throw fnfe;  
  122.             }  
  123.             return true;  
  124.         }  
  125.         #endregion  
  126.  
  127.         #region 在title和content字段中查询数据  
  128.         /// <summary>  
  129.         /// 在title和content字段中查询数据  
  130.         /// </summary>  
  131.         /// <param name="keyword"></param>  
  132.         /// <returns></returns>  
  133.         public List<MySearchUnit> Search(string keyword)  
  134.         {  
  135.   
  136.             string[] fileds = { "title", "content" };//查询字段  
  137.             //Stopwatch st = new Stopwatch();  
  138.             //st.Start();  
  139.             QueryParser parser = null;// new QueryParser(Lucene.Net.Util.Version.LUCENE_30, field, analyzer);//一个字段查询  
  140.             parser = new MultiFieldQueryParser(version, fileds, analyzer);//多个字段查询  
  141.             Query query = parser.Parse(keyword);  
  142.             int n = 1000;  
  143.             IndexSearcher searcher = new IndexSearcher(directory_luce, true);//true-表示只读  
  144.             TopDocs docs = searcher.Search(query, (Filter)null, n);  
  145.             if (docs == null || docs.TotalHits == 0)  
  146.             {  
  147.                 return null;  
  148.             }  
  149.             else  
  150.             {  
  151.                 List<MySearchUnit> list = new List<MySearchUnit>();  
  152.                 int counter = 1;  
  153.                 foreach (ScoreDoc sd in docs.ScoreDocs)//遍历搜索到的结果  
  154.                 {  
  155.                     try  
  156.                     {  
  157.                         Document doc = searcher.Doc(sd.Doc);  
  158.                         string id = doc.Get("id");  
  159.                         string title = doc.Get("title");  
  160.                         string content = doc.Get("content");  
  161.                         string flag = doc.Get("flag");  
  162.                         string imageurl = doc.Get("imageurl");  
  163.                         string updatetime = doc.Get("updatetime");  
  164.   
  165.                         string createdate = doc.Get("createdate");  
  166.                         PanGu.HighLight.SimpleHTMLFormatter simpleHTMLFormatter = new PanGu.HighLight.SimpleHTMLFormatter("<font color=\"red\">", "</font>");  
  167.                         PanGu.HighLight.Highlighter highlighter = new PanGu.HighLight.Highlighter(simpleHTMLFormatter, new PanGu.Segment());  
  168.                         highlighter.FragmentSize = 50;  
  169.                         content = highlighter.GetBestFragment(keyword, content);  
  170.                         string titlehighlight = highlighter.GetBestFragment(keyword, title);  
  171.                         if (titlehighlight != "") title = titlehighlight;  
  172.                         list.Add(new MySearchUnit(id, title, content, flag,imageurl, updatetime));  
  173.                     }  
  174.                     catch (Exception ex)  
  175.                     {  
  176.                         Console.WriteLine(ex.Message);  
  177.                     }  
  178.                     counter++;  
  179.                 }  
  180.                 return list;  
  181.             }  
  182.             //st.Stop();  
  183.             //Response.Write("查询时间:" + st.ElapsedMilliseconds + " 毫秒<br/>");  
  184.   
  185.         }  
  186.         #endregion  
  187.  
  188.         #region 在不同的分类下再根据title和content字段中查询数据(分页)  
  189.         /// <summary>  
  190.         /// 在不同的类型下再根据title和content字段中查询数据(分页)  
  191.         /// </summary>  
  192.         /// <param name="_flag">分类,传空值查询全部</param>  
  193.         /// <param name="keyword"></param>  
  194.         /// <param name="PageIndex"></param>  
  195.         /// <param name="PageSize"></param>  
  196.         /// <param name="TotalCount"></param>  
  197.         /// <returns></returns>  
  198.         public List<MySearchUnit> Search(string _flag,string keyword, int PageIndex, int PageSize, out int TotalCount)  
  199.         {  
  200.             if (PageIndex < 1) PageIndex = 1;  
  201.             //Stopwatch st = new Stopwatch();  
  202.             //st.Start();  
  203.             BooleanQuery bq = new BooleanQuery();  
  204.             if (_flag != "")  
  205.             {  
  206.                 QueryParser qpflag = new QueryParser(version, "flag", analyzer);  
  207.                 Query qflag = qpflag.Parse(_flag);  
  208.                 bq.Add(qflag, Occur.MUST);//与运算  
  209.             }  
  210.             if (keyword != "")  
  211.             {  
  212.                 string[] fileds = { "title", "content" };//查询字段  
  213.                 QueryParser parser = null;// new QueryParser(version, field, analyzer);//一个字段查询  
  214.                 parser = new MultiFieldQueryParser(version, fileds, analyzer);//多个字段查询  
  215.                 Query queryKeyword = parser.Parse(keyword);  
  216.                 bq.Add(queryKeyword, Occur.MUST);//与运算  
  217.             }  
  218.               
  219.             TopScoreDocCollector collector = TopScoreDocCollector.Create(PageIndex * PageSize, false);  
  220.             IndexSearcher searcher = new IndexSearcher(directory_luce, true);//true-表示只读  
  221.             searcher.Search(bq, collector);  
  222.             if (collector == null || collector.TotalHits == 0)  
  223.             {  
  224.                 TotalCount = 0;  
  225.                 return null;  
  226.             }  
  227.             else  
  228.             {  
  229.                 int start = PageSize * (PageIndex - 1);  
  230.                 //结束数  
  231.                 int limit = PageSize;  
  232.                 ScoreDoc[] hits = collector.TopDocs(start, limit).ScoreDocs;  
  233.                 List<MySearchUnit> list = new List<MySearchUnit>();  
  234.                 int counter = 1;  
  235.                 TotalCount = collector.TotalHits;  
  236.                 foreach (ScoreDoc sd in hits)//遍历搜索到的结果  
  237.                 {  
  238.                     try  
  239.                     {  
  240.                         Document doc = searcher.Doc(sd.Doc);  
  241.                         string id = doc.Get("id");  
  242.                         string title = doc.Get("title");  
  243.                         string content = doc.Get("content");  
  244.                         string flag = doc.Get("flag");  
  245.                         string imageurl = doc.Get("imageurl");  
  246.                         string updatetime = doc.Get("updatetime");  
  247.   
  248.                         PanGu.HighLight.SimpleHTMLFormatter simpleHTMLFormatter = new PanGu.HighLight.SimpleHTMLFormatter("<font color=\"red\">", "</font>");  
  249.                         PanGu.HighLight.Highlighter highlighter = new PanGu.HighLight.Highlighter(simpleHTMLFormatter, new PanGu.Segment());  
  250.                         highlighter.FragmentSize = 50;  
  251.                         content = highlighter.GetBestFragment(keyword, content);  
  252.                         string titlehighlight = highlighter.GetBestFragment(keyword, title);  
  253.                         if (titlehighlight != "") title = titlehighlight;  
  254.                         list.Add(new MySearchUnit(id, title, content, flag,imageurl, updatetime));  
  255.                     }  
  256.                     catch (Exception ex)  
  257.                     {  
  258.                         Console.WriteLine(ex.Message);  
  259.                     }  
  260.                     counter++;  
  261.                 }  
  262.                 return list;  
  263.             }  
  264.             //st.Stop();  
  265.             //Response.Write("查询时间:" + st.ElapsedMilliseconds + " 毫秒<br/>");  
  266.   
  267.         }  
  268.         #endregion  
  269.  
  270.         #region 删除索引数据(根据id)  
  271.         /// <summary>  
  272.         /// 删除索引数据(根据id)  
  273.         /// </summary>  
  274.         /// <param name="id"></param>  
  275.         /// <returns></returns>  
  276.         public bool Delete(string id)  
  277.         {  
  278.             bool IsSuccess = false;  
  279.             Term term = new Term("id", id);  
  280.             //Analyzer analyzer = new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30);  
  281.             //Version version = new Version();  
  282.             //MultiFieldQueryParser parser = new MultiFieldQueryParser(version, new string[] { "name", "job" }, analyzer);//多个字段查询  
  283.             //Query query = parser.Parse("小王");  
  284.   
  285.             //IndexReader reader = IndexReader.Open(directory_luce, false);  
  286.             //reader.DeleteDocuments(term);  
  287.             //Response.Write("删除记录结果: " + reader.HasDeletions + "<br/>");  
  288.             //reader.Dispose();  
  289.   
  290.             IndexWriter writer = new IndexWriter(directory_luce, analyzer, false, IndexWriter.MaxFieldLength.LIMITED);  
  291.             writer.DeleteDocuments(term); // writer.DeleteDocuments(term)或者writer.DeleteDocuments(query);  
  292.             ////writer.DeleteAll();  
  293.             writer.Commit();  
  294.             //writer.Optimize();//  
  295.             IsSuccess = writer.HasDeletions();  
  296.             writer.Dispose();  
  297.             return IsSuccess;  
  298.         }  
  299.         #endregion  
  300.  
  301.         #region 删除全部索引数据  
  302.         /// <summary>  
  303.         /// 删除全部索引数据  
  304.         /// </summary>  
  305.         /// <returns></returns>  
  306.         public bool DeleteAll()  
  307.         {  
  308.             bool IsSuccess = true;  
  309.             try  
  310.             {  
  311.                 IndexWriter writer = new IndexWriter(directory_luce, analyzer, false, IndexWriter.MaxFieldLength.LIMITED);  
  312.                 writer.DeleteAll();  
  313.                 writer.Commit();  
  314.                 //writer.Optimize();//  
  315.                 IsSuccess = writer.HasDeletions();  
  316.                 writer.Dispose();  
  317.             }  
  318.             catch  
  319.             {  
  320.                 IsSuccess = false;  
  321.             }  
  322.             return IsSuccess;  
  323.         }  
  324.         #endregion  
  325.  
  326.         #region directory_luce  
  327.         private Lucene.Net.Store.Directory _directory_luce = null;  
  328.         /// <summary>  
  329.         /// Lucene.Net的目录-参数  
  330.         /// </summary>  
  331.         public Lucene.Net.Store.Directory directory_luce  
  332.         {  
  333.             get  
  334.             {  
  335.                 if (_directory_luce == null) _directory_luce = Lucene.Net.Store.FSDirectory.Open(directory);  
  336.                 return _directory_luce;  
  337.             }  
  338.         }   
  339.         #endregion  
  340.  
  341.         #region directory  
  342.         private System.IO.DirectoryInfo _directory = null;  
  343.         /// <summary>  
  344.         /// 索引在硬盘上的目录  
  345.         /// </summary>  
  346.         public System.IO.DirectoryInfo directory  
  347.         {  
  348.             get  
  349.             {  
  350.                 if (_directory == null)  
  351.                 {  
  352.                     string dirPath = AppDomain.CurrentDomain.BaseDirectory + "SearchIndex";  
  353.                     if (System.IO.Directory.Exists(dirPath) == false) _directory = System.IO.Directory.CreateDirectory(dirPath);  
  354.                     else _directory = new System.IO.DirectoryInfo(dirPath);  
  355.                 }  
  356.                 return _directory;  
  357.             }  
  358.         }   
  359.         #endregion  
  360.  
  361.         #region analyzer  
  362.         private Analyzer _analyzer = null;  
  363.         /// <summary>  
  364.         /// 分析器  
  365.         /// </summary>  
  366.         public Analyzer analyzer  
  367.         {  
  368.             get  
  369.             {  
  370.                 //if (_analyzer == null)  
  371.                 {  
  372.                     _analyzer = new Lucene.Net.Analysis.PanGu.PanGuAnalyzer();//盘古分词分析器  
  373.                     //_analyzer = new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30);//标准分析器  
  374.                 }  
  375.                 return _analyzer;  
  376.             }  
  377.         }   
  378.         #endregion  
  379.  
  380.         #region version  
  381.         private static Lucene.Net.Util.Version _version = Lucene.Net.Util.Version.LUCENE_30;  
  382.         /// <summary>  
  383.         /// 版本号枚举类  
  384.         /// </summary>  
  385.         public Lucene.Net.Util.Version version  
  386.         {  
  387.             get  
  388.             {  
  389.                 return _version;  
  390.             }  
  391.         }  
  392.         #endregion  
  393.     }  
  394.  
  395.     #region 索引的一个行单元,相当于数据库中的一行数据  
  396.     /// <summary>  
  397.     /// 索引的一个行单元,相当于数据库中的一行数据  
  398.     /// </summary>  
  399.     public class MySearchUnit  
  400.     {  
  401.         public MySearchUnit(string _id, string _title, string _content, string _flag, string _imageurl, string _updatetime)  
  402.         {  
  403.             this.id = _id;  
  404.             this.title = _title;  
  405.             this.content = _content;  
  406.             this.flag = _flag;  
  407.             this.imageurl = _imageurl;  
  408.             this.updatetime = _updatetime;  
  409.         }  
  410.         /// <summary>  
  411.         /// 唯一的id号  
  412.         /// </summary>  
  413.         public string id { get; set; }  
  414.         /// <summary>  
  415.         /// 标题  
  416.         /// </summary>  
  417.         public string title { get; set; }  
  418.         /// <summary>  
  419.         /// 内容  
  420.         /// </summary>  
  421.         public string content { get; set; }  
  422.         /// <summary>  
  423.         /// 其他信息  
  424.         /// </summary>  
  425.         public string flag { get; set; }  
  426.         /// <summary>  
  427.         /// 图片路径  
  428.         /// </summary>  
  429.         public string imageurl { get; set; }  
  430.         /// <summary>  
  431.         /// 时间  
  432.         /// </summary>  
  433.         public string updatetime { get; set; }  
  434.     }   
  435.     #endregion  
  436. }  

//调用测试


  
[csharp] view plain copy print ?
  1. protected void Page_Load(object sender, EventArgs e)  
  2.  {  
  3.      //PanGuLuceneHelper.instance.DeleteAll();//删除全部  
  4.   
  5.      //PanGuLuceneHelper.instance.Delete("1d");//根据id删除  
  6.      bool exec = false;  
  7.      if (exec)  
  8.      {  
  9.          List<MySearchUnit> list = new List<MySearchUnit>();  
  10.          list.Add(new MySearchUnit("1a", "标题小王", "今天是小王的生日,大家都很高兴去他家喝酒,玩了一整天。", new Random().Next(1, 10).ToString(), "", ""));  
  11.          list.Add(new MySearchUnit("1b", "标题小张", "今天是小张的生日,大家都很高兴去他家喝酒,玩了几天。", new Random().Next(1, 10).ToString(), "", ""));  
  12.          list.Add(new MySearchUnit("1c", "标题小王", "今天是小王的生日,大家都很高兴去他家喝酒,玩了一整天。", new Random().Next(1, 10).ToString(), "", ""));  
  13.          list.Add(new MySearchUnit("1d", "标题小张", "今天是小张的生日,大家都很高兴去他家喝酒,玩了几天。", new Random().Next(1, 10).ToString(), "", ""));  
  14.          PanGuLuceneHelper.instance.CreateIndex(list);//添加索引  
  15.      }  
  16.      int count = 0;  
  17.      int PageIndex=2;  
  18.      int PageSize=4;  
  19.      string html_content = "";  
  20.      List<MySearchUnit> searchlist = PanGuLuceneHelper.instance.Search("3","小王 生日",PageIndex,PageSize,out count);  
  21.      html_content+=("查询结果:" + count + "条数据<br/>");  
  22.      if (searchlist == null || searchlist.Count==0)  
  23.      {  
  24.          html_content += ("未查询到数据。<br/>");  
  25.      }  
  26.      else  
  27.      {  
  28.          foreach (MySearchUnit data in searchlist)  
  29.          {  
  30.              html_content += (string.Format("id:{0},title:{1},content:{2},flag:{3},updatetime:{4}<br/>", data.id, data.title, data.content, data.flag, data.updatetime));  
  31.          }  
  32.      }  
  33.      html_content += (PanGuLuceneHelper.instance.version);  
  34.      div_content.InnerHtml = html_content;  
  35.  }  


//效果:

第一版源码示例下载:http://download.youkuaiyun.com/detail/pukuimin1226/6768179

  最新源码示例下载:http://download.youkuaiyun.com/detail/pukuimin1226/6776049

百度云盘下载链接:http://pan.baidu.com/s/1o69cCD8

Lucene.Net没有判断数据重复性,同一条数据插入多少遍它就有多少条相同的数据,所以,我们人为地用id区分,在数据量大,全部重新创建索引时间长的情况下(数据量到几万以上就耗资源了,从数据库中查询出来,再写入索引,使得数据库和程序本身都增加负担),增量建立索引是很有必要的。

新增一条数据,就直接添加一条索引;

修改一条数据,先删除同一个id的索引(不管有多少个id相同的,都会一次性删除),再添加一条。

数据库中的id建议大家都用guid去掉“-”,还可以加日期“yyyyMMddHHmmss”这样组合,长度一致看起来美观,也充分保证唯一。


Lucene.net 盘古分词C# 工厂将所有LOG放在共享盘里面,用这个来找超级快. 立即下载

相关推荐

盘古PanGu4Lucene_V2.3.1.0

这是盘古分词专门为Lucene.net开发的中文分词API 大家可以下载与Lucene.Net协作使用。本下载中心还有Lucene.net可下载

使用Lucene.net+盘古分词实现搜索查询

这里我的的Demo的逻辑是这样的:首先我基本的数据是储存在Sql数据库中,然后我把我的必需的数据推送到MongoDB中,这样再去利用Lucene.net+盘古创建索引;其中为什么要这样把数据推送到MongoDb中,我的理解是可以从Sql中直接取出来必需的数据,首次推送可能是要推送所有的数据,直接创建索引,但是在第二次推送的时候,可能存...

dazhi0529的博客 524

Lucene-Demo.rar Lucene分词的demo

本压缩包的主要内容是Lucene分词器的demo版本,可以导入到程序中直接使用,包含Lucene分词使用的pom文件,使用前请注意修改存储地址。

盘古分词 lucene.net

-初始化 在进程启动时,我们需要对盘古分词进行初始化,初始化的调用代码如下: PanGu.Segment.Init(); 或 PanGu.Segment.Init(filename); filename 为pangu.xml 的完整路径名,如 “c:\pangu.xml”    -开始记录索引 //创建索引文件夹 FSDire

asds123as12sa的专栏 664

盘古分词 工具

盘古分词 简介: 盘古分词 是由eaglet 开发的一款基于字典的中英文分词组件 主要功能: 中英文分词,未登录词识别,多元歧义自动识别,全角字符识别能力 主要性能指标: 分词准确度:90%以上 处理速度: 300-600KBytes/s Core Duo 1.8GHz 用于测试的句子: 长春市长春节致词 长春市长春药店 IBM的技术和服务都不错 张三在一月份工作会议上说的确实在理 于北京时间5月10日举行运动会 我的和服务必在明天做好

完整的站内搜索引擎(Lucene.Net+盘古分词)

功能简介 站内搜索使用的技术 Log4Net 日志记录 lucene.NET 全文检索开发包,只能检索文本信息 分词(lucene.Net提供StandardAnalyzer一元分词,按照单个字进行分词,一个汉字一个词) 盘古分词 基于词库的分词,可以维护词库 首先我们新增的SearchHelper类需要将其做成一个单例,使用单例是因为:有许多地方需要使用使用,但我们同时又希望只有一个对象去操作。 其次,使用Lucene.Net需要将被搜索的进行索引,然后保存到索引库以便被搜索,我们引入了“生产者,消费者模式”. 生产者就是当我们新增,修改或删除的时候我们就需要将其在索引库进行相应的操作,我们将此操作交给另一个线程去处理,这个线程就是我们的消费者,使用“生产者,消费者模式”是因为:索引库使用前需解锁操作,使用完成之后必须解锁,所以只能有一个对象对索引库进行操作,避免数据混乱,所以要使用生产者,消费者模式 首先我们来看生产者。 代码完善,已经部署到大型电子商务中使用,性能非常好。

盘古分词的使用

下载地址:http://pangusegment.codeplex.com/ 下载的为主程序,正常使用还需下载词库。 引用PanGu.dll, 初始化: PanGu.Segment.Init();或 PanGu.Segment.Init(filename); filename 为pangu.xml 的完整路径名,如 “c:\pangu.xml” pangu.xml为盘古分...

weixin_34367845的博客 460

嵌入式学习之QT学习---14 QT跨平台运行之把QT程序交叉编译到ARM开发板

想要把qt工程放到开发板上运行,就需要用到交叉编译。由于qt是跨平台的,所以只需要换个编译器编译一下就可以。 以“定时器”的例子为例,在移植之前还需要进行一个准备工作,在windows下运行的时候,电脑屏幕很大,但是运行的窗口只有一点点大,开发板也有外接屏幕,如何让运行窗口自动适配开发板的外接屏幕呢?令其占满屏幕显示,而不是一小块。 第一步:需要设置一下,先给ui布局,如果不布局,控件就不会随着屏幕的大小的变化而变化。 第二步:利用代码来获取屏幕的大小,给widget.cpp文件下添加如下代码 #inclu

qq_42822743的博客 5457

Lucene.Net与盘古分词实现站内搜索

Q:站内搜索为什么不能使用Like模糊查找 A:模糊契合度太低,匹配关键字之间不能含有其他内容。最重要的是它会造成全表扫描,效率底下,即使使用视图,也会造成数据库服务器"亚历山大" Lucene简介: Lucene.Net只是一个全文检索开发包,不是一个成型的搜索引擎 它提供了类似SQLServer数据库正式版中的全文检索功能的索引库 你把数据扔给Lucene.Net

wangyizhi58的专栏 1万+

深信服AF设置安全防护策略

防火墙设置安全防护策略,禁止用户访问指定网站

m0_64423407的博客 4844

HFSS新手避坑指南:手把手教你用FR4基板仿真威尔金森功分器(附参数优化技巧)

本文详细介绍了使用HFSS仿真FR4基板威尔金森功分器的12个关键细节,包括介质基板设置、微带线建模、隔离电阻设置等实战技巧。特别针对微波技术中的常见问题,提供了参数优化和结果解读的实用方法,帮助新手快速掌握HFSS仿真技能。

weixin_27310417的博客 227

Lucene.net入门学习(结合盘古分词)

Lucene简介 Lucene是apache软件基金会4 jakarta项目组的一个子项目,是一个开放源代码的全文检索引擎工具包,即它不是一个完整的全文检索引擎,而是一个全文检索引擎的架构,提供了完整的查询引擎和索引引擎,部分文本分析引擎(英文与德文两种西方语言)。Lucene的目的是为软件开发人员提供一个简单易用的工具包,以方便的在目标系统中实现全文检索的功能,或者是以此为基础建...

weixin_30247781的博客 187

从宁德新能源面试官视角,拆解Halcon/OpenCV图像处理工程师的硬核技能树(附避坑指南)

本文从宁德新能源面试官视角出发,详细拆解Halcon/OpenCV图像处理工程师的核心技能树,涵盖硬件选型、算法实现和系统工程思维三大能力维度。文章提供工业视觉工程师面试的实战避坑指南,包括硬件配置要点、算法优化技巧及职业发展路径,助力求职者系统提升图像处理专业技能。

weixin_28732953的博客 129

Lucene.Net.Analysis.PanGu:强大的中文分词功能,提升搜索精度

Lucene.Net.Analysis.PanGu:强大的中文分词功能,提升搜索精度 项目介绍 Lucene.Net.Analysis.PanGu 是一个开源的中文分词项目,基于著名的盘古分词进行升级,以兼容最新的 Lucene.Net 3.0.3 版本。它通过 NuGet 包的方式提供,使得安装和使用过程变得极其简便。此外,项目将词库打包进 DLL 文件中,避免了传统词库配置的复杂性。 项目技术...

gitblog_00331的博客 929

Rockchip平台之RK3566/3568 OS02N10

文章摘要 本文主要介绍了200W摄像头传感器OS02N10在RK3566平台上的兼容与适配过程。作者基于之前的400W摄像头兼容经验,针对200W摄像头进行了类似的适配工作。文章详细阐述了RK3566芯片的特性和OS02N10传感器的技术参数,包括分辨率、接口和功耗等。适配过程分为三个关键部分:DTS设备树文件配置(定义I2C地址、电源域和GPIO控制等)、驱动文件开发(寄存器初始化和操作)以及XML和JSON配置文件调整(图像参数设置)。作者特别强调了初始化数组中空寄存器终止条件的重要性,并分享了兼容过程

different_xzh的博客 2412

万字长文,小白新手怎么开始做YOLO实验,从零开始教!整体思路在这里,科研指南针!

万字长文,小白新手怎么开始做YOLO实验,从零开始教!整体思路在这里,科研指南针!

Coding... 1万+

Lucene.Net3.0.3+盘古分词器学习使用

一、Lucene.Net介绍   Lucene.net是Lucene的.net移植版本,是一个开源的全文检索引擎开发包,即它不是一个完整的全文检索引擎,而是一个全文检索引擎的架构,提供了完整的查询引擎和索引引擎。开发人员可以基于Lucene.net实现全文检索的功能。      Lucene.net是Apache软件基金会赞助的开源项目,基于Apache License协议。    ...

dbc68367的博客 294

Xilinx FPGA平台GTX简易使用教程(四)GTX IP核配置教程

干货来了,GTX IP核配置,搬砖全靠它~~

数字IC/FPGA杂货铺,找一找,或许有你想要的~ 1万+

测试分词工具Lucene.Net.Analysis.PanGu(盘古分词)

学习盘古分词Lucene.Net.Analysis.PanGu包的基本用法、

gc_2299的博客 1019

Python爬虫实战:利用最新技术爬取抖音话题挑战视频

本文将详细介绍如何使用Python最新技术栈构建一个高效的抖音话题挑战视频爬虫。我们将从环境配置开始,逐步讲解请求模拟、数据解析、反反爬策略、数据存储等关键环节,并提供完整的代码实现。本文适合有一定Python基础的开发者学习高级网络爬虫技术。关键词:Python爬虫、抖音API、话题挑战、视频爬取、反反爬本文详细介绍了如何使用Python最新技术栈构建抖音话题挑战视频爬虫。我们从基础请求开始,逐步实现了数据解析、反反爬策略、数据存储等核心功能,并探讨了分布式和增量爬取等高级主题。更智能的反反爬策略。

2201_76125261的博客 1744

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

Lucene.Net v2.9.x + 盘古分词版

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; using Lucene.Net; using Lucene.Net.Analysis; using Lucene.Net.Analysis.Standard; usin

哥是技术人 1301

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

近期做的Lucene+盘古分词总结(.net)

Lucene.Net只是一个全文检索开发包。它的功能就是提供了全文检索功能的一个数据库。Lucene.Net不管文本数据怎么来的,用户可以基于Lucene.Net开发满足自己需求的搜索引擎。Lucene.Net智能对 文本信息进行检索。如果不是文本信息,要转换为文本信息,比如检索Excel文件,就要用NPOI把Excel读取成字符串,然后把字符串扔给Lucene.Net。Lucene.Net

Small_madman的专栏 1万+

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

lucene.net 3.0.3、结合盘古分词进行搜索的小例子(转)

lucene.net 3.0.3、结合盘古分词进行搜索的小例子(分页功能) 添加:2013-12-25 更新:2013-12-26 新增分页功能。 更新:2013-12-27 新增按分类查询功能,调整索引行新增记录的图片字段。 //封装类 [csharp] view plaincopyprint? ...

weixin_30239339的博客 116
上一篇: 使用Lucene.Net实现全文检索
下一篇: LiteDB实践使用
wingahi
博客等级 码龄15年 15粉丝 43原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值