Я давно создал проект, используя Lucene 4.6.Сейчас требуется обновить до 7.3.
В этом проекте три файла по одному классу (с тем же именем, что и у файла): Main, Indexer, Search.
Я получаюпроблема в Indexer.java , более конкретно в buildIndex () .
Внутри Main.java я определил место с помощьюкаталог данных, где будет находиться индекс, и начал создавать индекс, отправив путь к buildIndex () , где он должен быть построен:
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");
Внутри Индексатор.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);
}
}
Возникают следующие проблемы:
Поле конструктора (String, Reader) не определено.
Индекс не может быть разрешен или не является полем
Как это исправить?
Привести аргумент 'reader' к 'IndexableFieldType'
ИЛИ
Изменить тип 'reader' на 'IndexableFieldType' нельзя.
Примечание: Путь к каталогу данных содержит файл .txt с надписью "Maven".