lucene测试demo
2014-05-19 21:50
267 查看
1、在http://lucene.apache.org/下lucene4.8.0版本
2、新建工程依赖lucene-core、lucene-analyzers-common两个jar包
3、测试代码(从《lucene实战》里面弄出来的,稍微适配一下版本)
2、新建工程依赖lucene-core、lucene-analyzers-common两个jar包
3、测试代码(从《lucene实战》里面弄出来的,稍微适配一下版本)
package search.basictest; import java.io.IOException; import java.io.StringReader; import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.TokenStream; import org.apache.lucene.analysis.core.SimpleAnalyzer; import org.apache.lucene.analysis.core.StopAnalyzer; import org.apache.lucene.analysis.core.WhitespaceAnalyzer; import org.apache.lucene.analysis.standard.StandardAnalyzer; import org.apache.lucene.analysis.tokenattributes.CharTermAttribute; import org.apache.lucene.util.Version; public class BasicTest { private static final String[] examples = { "The quick brown fox jumped over the lazy dog", "XY&Z Corporation = xyz@example.com" }; private static final Analyzer[] analyzers = new Analyzer[] { new WhitespaceAnalyzer(Version.LUCENE_48), new SimpleAnalyzer(Version.LUCENE_48), new StopAnalyzer(Version.LUCENE_48), new StandardAnalyzer(Version.LUCENE_48) }; public static void main(String[] args) throws IOException { String[] strs = examples; if (args.length > 0) { strs = args; } for (String text : strs) { analyze(text); } } private static void analyze(String text) throws IOException { System.out.println("\n\nAnalyzing \"" + text + "\""); for (Analyzer analyzer : analyzers) { String name = analyzer.getClass().getSimpleName(); System.out.println("\n " + name + ":"); System.out.print(" "); displayTokens(analyzer, text); } } private static void displayTokens(Analyzer analyzer, String text) throws IOException { TokenStream t = analyzer.tokenStream("contents, ", new StringReader( text)); t.reset(); displayTokens(t); t.close(); } private static void displayTokens(TokenStream tokenStream) throws IOException { CharTermAttribute term = tokenStream.addAttribute(CharTermAttribute.class); while (tokenStream.incrementToken()) { System.out.print("[" + term.toString() + "] "); } } }4、输出
Analyzing "The quick brown fox jumped over the lazy dog" WhitespaceAnalyzer: [The] [quick] [brown] [fox] [jumped] [over] [the] [lazy] [dog] SimpleAnalyzer: [the] [quick] [brown] [fox] [jumped] [over] [the] [lazy] [dog] StopAnalyzer: [quick] [brown] [fox] [jumped] [over] [lazy] [dog] StandardAnalyzer: [quick] [brown] [fox] [jumped] [over] [lazy] [dog] Analyzing "XY&Z Corporation = xyz@example.com" WhitespaceAnalyzer: [XY&Z] [Corporation] [=] [xyz@example.com] SimpleAnalyzer: [xy] [z] [corporation] [xyz] [example] [com] StopAnalyzer: [xy] [z] [corporation] [xyz] [example] [com] StandardAnalyzer: [xy] [z] [corporation] [xyz] [example.com]
相关文章推荐
- 用APNS Tool测试推送证书是否有效,结合真机运行demo实验
- Windows Phone开发之ToastPrompt测试Demo与Coding4Fun效果对比(有图有真相)
- RobotFrameWork接口报文测试-----(二)demo的升级版
- Lucene_demo04_分页
- 一个完整的linux 驱动demo 加应用测试 demo
- Asterisk11 webrtc 安装及demo测试(SIPML5)
- opendir ,readdir 测试demo
- Android中的测试小demo
- 在Ubuntu12.10-32bit上构建、测试WebRTC之Android示例WebRTCDemo(video_engine)
- lucene6.4.2高亮测试源码 一定要导入这个包lucene-memory-6.4.2.jar
- less 初学 测试demo
- kafka2.9.2的伪分布式集群安装和demo(java api)测试
- Android 测试框架简单demo
- lucene 索引 demo
- kafka2.9.2的分布式集群安装和demo(java api)测试
- 这个是测试demo
- 使用Lucene实现多个文档关键词检索demo(一)
- OpenGL环境的配置及其一个测试Demo
- lucene中demo的运行及配置
- LUCENE 配置及DEMO使用