执行最简单索引过程需要的几个类:IndexWriter、Directory、Analyzer、Document、Field。简单例子如下所示:
public static int index(File indexDir, File dataDir)
throws IOException {
if (!dataDir.exists() || !dataDir.isDirectory()) {
throw new IOException(dataDir
+ " does not exist or is not a directory");
}
if (dataDir.isHidden() || !dataDir.canRead()||!dataDir.getName().endsWith(".txt")) {
throw new IOException(dataDir
+ " error!");
}
IndexWriter writer = new IndexWriter(indexDir,
new StandardAnalyzer(), true);
writer.setUseCompoundFile(false);
//使用 IndexWriter's setUseCompoundFile(true) 创建复合文件,减少索引文件数量。
System.out.println("Indexing " + dataDir.getCanonicalPath());
Document doc = new Document();
doc.add(Field.Text("contents", new FileReader(dataDir)));
doc.add(Field.Keyword("filename", dataDir.getCanonicalPath()));
writer.addDocument(doc);
int numIndexed = writer.docCount();
writer.optimize();
writer.close();
return numIndexed;
}
相关推荐
lucene in action 第二版(pdf),内为英文彩色原版。
lucene in action lucene in action lucene in action lucene in action lucene in action lucene in action lucene in action lucene in action
lucene in action源码
Lucene in action 中文版 电子版,超清晰
【Manning eBook】Lucene in Action 2nd Edition MEAP新版 Jun 2010
《Lucene in Action》配套源码
Lucene In Action,入门Lucene经典教程。
lecene4.x教程,有很多简单明了的demo,是学习开发的好助手
Lucene In Action 2书的配套源代码
使用其他编程语言访问Lucene Lucene管理和性能调优等内容 最后还提供了三大经典成功案例 为读者展示了一个奇妙的搜索世界 《Lucene实战 第2版 》适合于已具有一定Java编程基本的读者 以及希望能够把强大的搜索...
Lucene In Action 第二版 高清中文版+附书源代码 Lucene In Action 第二版 高清中文版+附书源代码
lucene in action的配套源代码
包括认识Lucene、建立索引、为应用程序添加搜索功能、高级搜索技术、扩展搜索、使用Tika提取文本、Lucene的高级扩展、使用其他编程语言访问Lucene、Lucene管理和性能调优等内容,最后还提供了三大经典成功案例,为...
《lucene in action》第二版
lucene in action 中文
lucene in action 第二版中文版,
lucene使用总结笔记lucene使用总结笔记lucene使用总结笔记lucene使用总结笔记lucene使用总结笔记
lucene in action 书中的实例代码,包括相应的jar包。 lucene 是3.0版本的 由于上传大小限制,jar包稍后传上