lucene中的四种分词器
来源:互联网 发布:离散数学 视频 知乎 编辑:程序博客网 时间:2024/06/06 19:48
- import java.io.IOException;
- import java.io.StringReader;
- import javax.swing.text.AttributeSet.CharacterAttribute;
- import org.apache.lucene.analysis.Analyzer;
- import org.apache.lucene.analysis.SimpleAnalyzer;
- import org.apache.lucene.analysis.StopAnalyzer;
- import org.apache.lucene.analysis.TokenStream;
- import org.apache.lucene.analysis.WhitespaceAnalyzer;
- import org.apache.lucene.analysis.standard.StandardAnalyzer;
- import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
- import org.apache.lucene.analysis.tokenattributes.OffsetAttribute;
- import org.apache.lucene.analysis.tokenattributes.PositionIncrementAttribute;
- import org.apache.lucene.analysis.tokenattributes.TypeAttribute;
- import org.apache.lucene.util.Version;
- import org.junit.Test;
- public class AnalyzerUtil {
- public static void displayToken(String txt,Analyzer a){
- TokenStream ts = a.tokenStream("content", new StringReader(txt));
- PositionIncrementAttribute pia = ts.addAttribute(PositionIncrementAttribute.class);
- OffsetAttribute oa = ts.addAttribute(OffsetAttribute.class);
- CharTermAttribute ca = ts.addAttribute(CharTermAttribute.class);
- TypeAttribute ta = ts.addAttribute(TypeAttribute.class);
- try {
- while(ts.incrementToken()){
- System.out.println(ca.toString()+" positionincrement:"+pia.getPositionIncrement()+" "+"offset:"+oa.startOffset()+"-"+oa.endOffset()+" type:"+ta.type());
- }
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- System.out.println("-----------");
- }
- @Test
- public void test(){
- String txt = "how are you,thank you!";
- //构建四种分词器
- Analyzer a1 = new StandardAnalyzer(Version.LUCENE_35);
- Analyzer a2 = new StopAnalyzer(Version.LUCENE_35);
- Analyzer a3 = new SimpleAnalyzer(Version.LUCENE_35);
- Analyzer a4 = new WhitespaceAnalyzer(Version.LUCENE_35);
- AnalyzerUtil.displayToken(txt, a1);
- AnalyzerUtil.displayToken(txt, a2);
- AnalyzerUtil.displayToken(txt, a3);
- AnalyzerUtil.displayToken(txt, a4);
- }
- }
本文出自 “Kenan_ITBlog” 博客,请务必保留此出处http://soukenan.blog.51cto.com/5130995/1122415
- lucene中的四种分词器
- lucene(四) lucene分词器
- Lucene中的分词器
- lucene分词器分词
- lucene 中文分词器中的一个Bug
- Lucene中的MMAnalyzer中文分词器
- lucene分词器分词demo
- 4 Lucene笔记(四):第三方分词器IKAnalyzer
- Lucene 分词器学习
- Lucene 自定义分词器
- lucene 分词器Analyzer
- Lucene Analyzer(分词器)
- Lucene分词器测试
- lucene 分词器
- Lucene-分词器
- lucene分词器
- Lucene 分词器
- lucene分词器介绍
- IndexWriter和IndexReader对象分析
- 如何更好的玩转移动广告平台
- lucene的搜索,TermQuery,TermRangeQuery,NumericRangeQuery
- lucene中搜索
- lucene,基于QueryParser的搜索
- lucene中的四种分词器
- SQLServer索引的四个高级特性
- lucene自定义停用词分词器和mmseg中文分词器
- lucene学习之搜索排序
- lucene搜索中filter的使用
- lucene中好用的两个工具luke和Tika
- 一周实战Linux
- Linux_note
- 基于cxf实现的webservice,全程开发指南和笔记,以及代码