約 500 個のファイルを含むフォルダー (MY_FILES) があり、毎日新しいファイルが到着し、そこに配置されます。各ファイルのサイズは約 4Mb です。
これらのファイルで特定のワイルドカードを検索できるかどうかをテストするために、単純な「void main」を開発しました。それはうまく動作します。
問題は、古い indexed_folder を削除して、再度インデックスを作成していることです。これには多くの時間がかかり、明らかに非効率的です。私が探しているのは「増分インデックス」です。つまり、インデックスが既に存在する場合は、新しいファイルをインデックスに追加するだけです。
インデックスを作成する前に、「ドキュメント」にインデックスが作成されているかどうかを確認するメカニズムが Lucene にあるかどうか疑問に思っていました。writer.isDocExists のようなものですか?
ありがとう!
私のコードは次のようになります。
// build the writer
IndexWriter writer;
IndexWriterConfig indexWriter = new IndexWriterConfig(Version.LUCENE_36, analyzer);
writer = new IndexWriter(fsDir, indexWriter);
writer.deleteAll(); //must - otherwise it will return duplicated result
//build the docs and add to writer
File dir = new File(MY_FILES);
File[] files = dir.listFiles();
int counter = 0;
for (File file : files)
{
String path = file.getCanonicalPath();
FileReader reader = new FileReader(file);
Document doc = new Document();
doc.add(new Field("filename", file.getName(), Field.Store.YES, Field.Index.ANALYZED));
doc.add(new Field("path", path, Field.Store.YES, Field.Index.ANALYZED));
doc.add(new Field("content", reader));
writer.addDocument(doc);
System.out.println("indexing "+file.getName()+" "+ ++counter+"/"+files.length);
}