【发布时间】:2014-03-31 05:44:21
【问题描述】:
首先,对于 Tika 和 Lucene,我完全是个菜鸟。我正在通过 Tika in Action 书尝试示例。在第 5 章中给出了这个例子:
package tikatest01;
import java.io.File;
import org.apache.tika.Tika;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.Field.Index;
import org.apache.lucene.document.Field.Store;
import org.apache.lucene.index.IndexWriter;
public class LuceneIndexer {
private final Tika tika;
private final IndexWriter writer;
public LuceneIndexer(Tika tika, IndexWriter writer) {
this.tika = tika;
this.writer = writer;
}
public void indexDocument(File file) throws Exception {
Document document = new Document();
document.add(new Field(
"filename", file.getName(),
Store.YES, Index.ANALYZED));
document.add(new Field(
"fulltext", tika.parseToString(file),
Store.NO, Index.ANALYZED));
writer.addDocument(document);
}
}
还有这个主要方法:
package tikatest01;
import java.io.File;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.store.SimpleFSDirectory;
import org.apache.lucene.util.Version;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.tika.Tika;
public class TikaTest01 {
public static void main(String[] args) throws Exception {
String filename = "C:\\testdoc.pdf";
File file = new File(filename);
IndexWriter writer = new IndexWriter(
new SimpleFSDirectory(file),
new StandardAnalyzer(Version.LUCENE_30),
MaxFieldLength.UNLIMITED);
try {
LuceneIndexer indexer = new LuceneIndexer(new Tika(), writer);
indexer.indexDocument(file);
}
finally {
writer.close();
}
}
}
我已将库 tika-app-1.5.jar、lucene-core-4.7.0.jar 和 lucene-analyzers-common-4.7.0.jar 添加到项目中。
问题:
在当前版本的 Lucene 中,Field.Index 已被弃用,我应该改用什么?
未找到 MaxFieldLength。我缺少导入?
【问题讨论】:
-
使用 Lucene 3.6 或者更全面地学习所有这些 API。
-
更全面地学习 API 正是我阅读这些书籍的原因。然而,一切似乎都写在 Lucene 3.x 上,而不是 4.x :S
-
好的。部分回答了我的第二个问题。我需要将 lucene-analyzers-common-4.7.0.jar 添加到我的项目中并导入 org.apache.lucene.analysis.standard.StandardAnalyzer MaxFieldLength 问题仍然存在。为此更新了问题。
标签: java lucene apache-tika