【问题标题】:Lucene indexwriter destination folderLucene 索引器目标文件夹
【发布时间】:2011-07-07 07:44:12
【问题描述】:

我正在开发一个小型 lucene 项目,我必须在其中索引一堆文本文件。到目前为止,我已经设法创建了索引,我想。代码运行,我得到一堆名为 0_.* fdt/fdx/fnm 等的文件。

我想知道的是,我可以选择一个目标文件夹来创建索引吗?

我正在关注这个Guide,我定义了一个索引文件夹和一个索引文件夹的文件,但我在索引编写器构造函数中找不到任何可以实现这一点的参数。

这是我创建索引的代码

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

【问题讨论】:

    标签: java lucene indexing


    【解决方案1】:

    其实你是用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);

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-02-05
      • 2013-06-24
      • 2011-12-13
      • 2012-09-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多