简体   繁体   English

Lucene 索引器目标文件夹

[英]Lucene indexwriter destination folder

I'm working on a small lucene project, where i have to index a bunch of text files.我正在研究一个小型 lucene 项目,我必须在其中索引一堆文本文件。 so far i've managed to create the index, i think.到目前为止,我已经设法创建了索引,我想。 the code runs and i get a bunch of files called 0_.代码运行,我得到一堆名为 0_ 的文件。 * fdt/fdx/fnm and more. * fdt/fdx/fnm 等。

what i want to know is, can i pick a destination folder, for the index to be created in?我想知道的是,我可以选择一个目标文件夹来创建索引吗?

i'm following this Guide and i define a index folder, and a files to index folder, but i can't find any parameters in the indexwriter constructor, that could achieve this.我正在遵循本指南,我定义了一个索引文件夹和一个索引文件夹的文件,但我在 indexwriter 构造函数中找不到任何可以实现这一点的参数。

here's my code for creating the index这是我创建索引的代码

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();
}

and i'm using type File instead of string for the directories我在目录中使用类型文件而不是字符串

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");

Actually you are setting the destination folder with SimpleFSDirectory d = new SimpleFSDirectory(FILES_TO_INDEX_DIRECTORY);实际上,您正在使用SimpleFSDirectory d = new SimpleFSDirectory(FILES_TO_INDEX_DIRECTORY);设置目标文件夹

Just change SimpleFSDirectory(FILES_TO_INDEX_DIRECTORY);只需更改SimpleFSDirectory(FILES_TO_INDEX_DIRECTORY); to SimpleFSDirectory(INDEX_DIRECTORY);SimpleFSDirectory(INDEX_DIRECTORY); . .

Edit:编辑:

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

You should change this line to SimpleFSDirectory d = new SimpleFSDirectory(INDEX_DIRECTORY);您应该将此行更改为SimpleFSDirectory d = new SimpleFSDirectory(INDEX_DIRECTORY);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM