Lucene.Net简介
说明:Lucene.Net 只是一个全文检索开发包 .查询数据的时候从Lucene.Net查询数据.可以看做是一个提供了全文检索功能的数据库.
注意:只能搜索文本字符串.
重要概念:分词,基于词库的分词算法.(庖丁解牛,盘古分词)
1.1 添加一个窗体应用程序
1.2 添加引用-https://pan.baidu.com/s/1dFnB3NV中的15目录下
1.3 添加字典文件夹-https://pan.baidu.com/s/1dFnB3NV中的15目录下,并修改属性=复制到输出目录
具体编写代码
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
using Lucene.Net.Analysis; using Lucene.Net.Analysis.PanGu; using Lucene.Net.Analysis.Standard; using NSharp.SearchEngine.Lucene.Analysis.Cjk; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace BFFJ.LuceneNetDemo { public partial class Form1 : Form { public Form1() { InitializeComponent(); } //一元分词 private void button1_Click(object sender, EventArgs e) { Analyzer analyzer = new StandardAnalyzer(); TokenStream tokenStream = analyzer.TokenStream("",new StringReader("北京,Hi欢迎你们大家")); Lucene.Net.Analysis.Token token = null; while ((token = tokenStream.Next()) != null) { Console.WriteLine(token.TermText()); } } //二元分词 private void button2_Click(object sender, EventArgs e) { Analyzer analyzer = new CJKAnalyzer(); TokenStream tokenStream = analyzer.TokenStream("", new StringReader("北京,Hi欢迎你们大家")); Lucene.Net.Analysis.Token token = null; while ((token = tokenStream.Next()) != null) { Console.WriteLine(token.TermText()); } } private void button3_Click(object sender, EventArgs e) { Analyzer analyzer = new PanGuAnalyzer(); TokenStream tokenStream = analyzer.TokenStream("", new StringReader("北京,Hi欢迎你们大家")); Lucene.Net.Analysis.Token token = null; while ((token = tokenStream.Next()) != null) { Console.WriteLine(token.TermText()); } } } }
运行效果