zoukankan      html  css  js  c++  java
  • 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目录下,并修改属性=复制到输出目录

    具体编写代码

    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());
                }
            }
        }
    }
    View Code

    运行效果

  • 相关阅读:
    Algorithm Gossip (37) 快速排序法 ( 一 )
    Algorithm Gossip (36) Heap排序法( 堆排序 )
    Algorithm Gossip (35) Shaker法
    Algorithm Gossip (34) 希尔排序
    AlgorithmGossip (33) 选择、插入、气泡排序
    Algorithm Gossip (32) 得分排行
    Algorithm Gossip (31) 数字拆解(dp问题)
    Algorithm Gossip (30) m元素集合的 n 个元素子集
    Algorithm Gossip (29) 产生可能的集合
    Algorithm Gossip (27) 排列组合
  • 原文地址:https://www.cnblogs.com/YK2012/p/6676942.html
Copyright © 2011-2022 走看看