简体   繁体   English

从 Lucene 中的子目录索引文件

[英]Indexing files from sub directories in Lucene

I need to index files from two sub directory inside a main directory using Lucene.我需要使用 Lucene 从主目录内的两个子目录中索引文件。

Folder Structure文件夹结构

Main Folder主文件夹

|---SubDirectory1 |---子目录1

|---SubDirectory2 |---子目录2

Tried this试过这个

String dataDir = "src\\\\main\\\\resources\\\\MainFolder";

I thought it will go inside sub directory and index the files in sub folders also but no, zero file indexed.我认为它会进入子目录并索引子文件夹中的文件,但没有,索引零文件。

Is there any way do this/method in Lucene or should I create two indexes for each sub folder?在 Lucene 中有没有办法做到这一点/方法,还是应该为每个子文件夹创建两个索引?

Lucene doesn't crawl through directories and index files for you. Lucene 不会为您抓取目录和索引文件。 How would it know what attributes you want to index?它如何知道您要索引哪些属性? That is something that you must do yourself.这是你必须自己做的事情。 Have a look at the IndexFiles demo class provided by Apache in their tutorials for an example of how to do this.查看 Apache 在其教程中提供的IndexFiles 演示类,了解如何执行此操作的示例。 It might be worth copying the code into an IDE so it's easier to read, because there are a lot of comments in there.可能值得将代码复制到 IDE 中,以便更容易阅读,因为那里有很多注释。

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

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