Lucene分词器(搜索关键字解析器)
来源:互联网 发布:微信单删软件 编辑:程序博客网 时间:2024/05/18 01:44
import java.io.StringReader;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.KeywordAnalyzer;
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.TermAttribute;
import org.apache.lucene.util.Version;
public class luncens {
public static void analyze(Analyzer analyzer, String text) throws Exception {
System.out.println("分词器:" + analyzer.getClass());
TokenStream tokenStream = analyzer.tokenStream("content", new StringReader(text));
tokenStream.addAttribute(TermAttribute.class);
while (tokenStream.incrementToken()) {
TermAttribute termAttribute =tokenStream.getAttribute(TermAttribute.class);
System.out.println(termAttribute.term());
}
}
public static void main(String[] args) throws Exception {
String enText = "China is a great country!JC-46C(16tt)dd";
// String chText = "昨天,一阵雷阵雨后,空气异常 地清新!46C";
String chText = "SICAO新潮半导体电子酒柜JC-46C(16支)";
SimpleAnalyzer analyzer1 = new SimpleAnalyzer();
analyze(analyzer1,enText);
analyze(analyzer1,chText);
StopAnalyzer analyzer2 = new StopAnalyzer(Version.LUCENE_CURRENT);
analyze(analyzer2,enText);
analyze(analyzer2,chText);
StandardAnalyzer analyzer3 = new StandardAnalyzer(Version.LUCENE_CURRENT);
analyze(analyzer3,enText);
analyze(analyzer3,chText);//逐个字切分
WhitespaceAnalyzer analyzer4 = new WhitespaceAnalyzer();
analyze(analyzer4,enText);
analyze(analyzer4,chText);
KeywordAnalyzer analyzer5 = new KeywordAnalyzer();
analyze(analyzer5,enText);
analyze(analyzer5,chText);
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = new Date();
//当前时间
String endtime = format.format(date).substring(11, 13);
System.out.println("时间="+endtime);
}
}
- Lucene分词器(搜索关键字解析器)
- lucene分词器解析
- Lucene用标准分词器搜索索引
- lucene分词器分词
- Lucene分词器解析-代码篇
- lucene分词器分词demo
- 第61天(就业班) Lucene索引库优化、内置分词器、IK分词器、关键字高亮、单字段和多字段搜索、easyui入门
- lucene(四) lucene分词器
- Lucene 分词器学习
- Lucene 自定义分词器
- lucene 分词器Analyzer
- Lucene Analyzer(分词器)
- Lucene分词器测试
- lucene 分词器
- Lucene-分词器
- lucene分词器
- Lucene 分词器
- Lucene中的分词器
- 反编译---先随便写了
- 服务接口里获取文档路径的方法
- 目前网络中存在的攻击方式
- 项目管理之源码目录下的代码行数统计
- Linux下memcache的安装
- Lucene分词器(搜索关键字解析器)
- memcache Java客户端调用小例子
- poj 3056 区间dp
- JAVA----第四周 任务一
- Foxmail 6x, 7x解密
- 迟来的祝福
- Java内存泄露监控工具:JVM监控工具介绍
- PC客户端与Android服务端的Socket同步通信
- 在C应用中嵌入http服务器libmicrohttp