Lucene常见的分词

刚上班第一个任务就是将db查询改为Lucene查询,之前也没有接触过Lucene,也是慢慢自学Lucene,Lucene大概的意思就是将原先的数据库重新生成重组成新的数据库,它生成的Lucene数据库会有多个文件夹。用Lucene查询会大大提高查询的速度。下面介绍的是Lucene中常见的几种分词。

public class Lucene分词 {
    private static String str="  我爱你中国, 我的母亲";
    public static void print(Analyzer analyzer){
        StringReader reader=new StringReader(str);
        try {
            TokenStream tokenStream=analyzer.tokenStream("", reader);
            tokenStream.reset();
            CharTermAttribute term=tokenStream.getAttribute(CharTermAttribute.class);
            System.out.println("分词技术"+analyzer.getClass());
            while(tokenStream.incrementToken()){
                System.out.println(term.toString()+"|");
            }
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    public static void main(String[] args) {
        Analyzer analyzer=null;
        //这个是标准分词器    将汉字分成一个一个
        analyzer=new StandardAnalyzer(Version.LUCENE_36);
        Lucene分词.print(analyzer);
        //这个是根据空格的经行分割
        analyzer=new WhitespaceAnalyzer(Version.LUCENE_36);
        Lucene分词.print(analyzer);
        //这个是根据空格和标点符号经行分割
        analyzer=new SimpleAnalyzer(Version.LUCENE_36);
        Lucene分词.print(analyzer);
        //这个是将前后两个字经行分割,每个字出现2次
        analyzer=new CJKAnalyzer(Version.LUCENE_36);
        Lucene分词.print(analyzer);
        //这个是将一整句话进行分割
        analyzer=new KeywordAnalyzer();
        Lucene分词.print(analyzer);
        //按照空格和标点符号经行分割
        analyzer=new StopAnalyzer(Version.LUCENE_36);
        Lucene分词.print(analyzer);

    }

}

《Android版本更新、热更新》系列课程视频

版本更新6.0,7.0统统搞定!!

热修复不在麻烦,再也不用担心上线后出bug!!

http://edu.csdn.net/course/detail/6523

http://edu.csdn.net/course/play/6523/131198

《Kotlin语法基础到实战开发》系列课程视频

http://edu.csdn.net/course/detail/6409?locationNum=7&fps=1&ref=srch&loc=1

http://edu.csdn.net/course/play/6409/123752

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值