【发布时间】:2018-06-11 09:27:17
【问题描述】:
我很久以前就使用 Lucene 4.6 构建了一个项目。现在目前想升级到7.3。
这个项目有三个文件,每个文件都有一个类(与文件同名):Main、Indexer、Search。
我在 Indexer.java 中遇到了问题,更具体地说是在 buildIndex() 中。
在Main.java中,我已经定义了数据目录的位置和索引的位置,并通过将路径发送到buildIndex()开始创建索引em> 必须建在哪里:
File dataDirectory = new File("C:\\datalocation");
File indexDirectory = new File("C:\\indexlocation");
(...)
IndexWriter index = Indexer.createIndex(indexDirectory);
Indexer.buildIndex(index, dataDirectory, indexDirectory);
Indexer.closeIndex(index);
System.out.println("Index built");
Indexer.java 的内部:
static void buildIndex(IndexWriter index, File dataDirectory,
File IndexDirectory) throws IOException {
File[] files = dataDirectory.listFiles();
for (int i = 0; i < files.length; i++) {
Document document = new Document();
Reader reader = new FileReader(files[i]);
//the following line is where error 1 appears:
document.add(new Field("contents", reader));
String path = files[i].getCanonicalPath();
//the following line is where error 2 appears:
document.add(new Field("path", path, Field.Store.YES,Field.Index.NOT_ANALYZED));
index.addDocument(document);
}
}
我遇到的问题是:
构造函数 Field(String, Reader) 未定义。
索引无法解析或不是字段
我该如何解决这个问题?
将参数“reader”转换为“IndexableFieldType”
或
不能将“阅读器”类型更改为“IndexableFieldType”。
注意:数据目录路径中有一个.txt文件,里面只写了“Maven”。
【问题讨论】: