[英]Lucene indexwriter destination folder
我正在研究一个小型 lucene 项目,我必须在其中索引一堆文本文件。 到目前为止,我已经设法创建了索引,我想。 代码运行,我得到一堆名为 0_ 的文件。 * fdt/fdx/fnm 等。
我想知道的是,我可以选择一个目标文件夹来创建索引吗?
我正在遵循本指南,我定义了一个索引文件夹和一个索引文件夹的文件,但我在 indexwriter 构造函数中找不到任何可以实现这一点的参数。
这是我创建索引的代码
public static void createIndex() throws CorruptIndexException, LockObtainFailedException, IOException {
File[] files = FILES_TO_INDEX_DIRECTORY.listFiles();
Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_33);
SimpleFSDirectory d = new SimpleFSDirectory(FILES_TO_INDEX_DIRECTORY);
IndexWriter indexWriter = new IndexWriter(d, analyzer, IndexWriter.MaxFieldLength.LIMITED);
for (File file : files) {
Document document = new Document();
String path = file.getCanonicalPath();
byte[] bytes = path.getBytes();
document.add(new Field(FIELD_PATH, bytes));
Reader reader = new FileReader(file);
document.add(new Field(FIELD_CONTENTS, reader));
indexWriter.addDocument(document);
}
indexWriter.optimize();
indexWriter.close();
}
我在目录中使用类型文件而不是字符串
public static File FILES_TO_INDEX_DIRECTORY = new File("C:\\Users\\k\\Dropbox\\Public\\afgansprojekt\\RouteLogger\\Lucene\\FilesToIndex");
public static final File INDEX_DIRECTORY = new File("C:\\Users\\k\\Dropbox\\Public\\afgansprojekt\\RouteLogger\\Lucene\\Index");
实际上,您正在使用SimpleFSDirectory d = new SimpleFSDirectory(FILES_TO_INDEX_DIRECTORY);
设置目标文件夹
只需更改SimpleFSDirectory(FILES_TO_INDEX_DIRECTORY);
到SimpleFSDirectory(INDEX_DIRECTORY);
.
编辑:
File[] files = FILES_TO_INDEX_DIRECTORY.listFiles(); //this is where you set the files to index
SimpleFSDirectory d = new SimpleFSDirectory(FILES_TO_INDEX_DIRECTORY); //here you are setting the index directory
您应该将此行更改为SimpleFSDirectory d = new SimpleFSDirectory(INDEX_DIRECTORY);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.