サイトをクロールしてコンテンツをluceneインデックスファイルとして物理ディレクトリに書き込むアプリケーションがあります。Luceneインデックスファイルへのスレッドセーフ書き込み
この目的のためにスレッドを使用すると、ロックによって書き込みエラーまたはエラーが発生します。
私は、複数のスレッドを使用して、スレッドのタスクを失うことなくインデックスファイルに書き込みたいと思っています。上記のクラスに
public class WriteDocument
{
private static Analyzer _analyzer;
private static IndexWriter indexWriter;
private static string Host;
public WriteDocument(string _Host)
{
Host = _Host;
Lucene.Net.Store.Directory _directory = FSDirectory.GetDirectory(Host, false);
_analyzer = new StandardAnalyzer();
bool indexExists = IndexReader.IndexExists(_directory);
bool createIndex = !indexExists;
indexWriter = new IndexWriter(_directory, _analyzer, true);
}
public void AddDocument(object obj)
{
DocumentSettings doc = (DocumentSettings)obj;
Field urlField = new Field("Url", doc.downloadedDocument.Uri.ToString(), Field.Store.YES, Field.Index.TOKENIZED);
document.Add(urlField);
indexWriter.AddDocument(document);
document = null;
doc.downloadedDocument = null;
indexWriter.Optimize();
indexWriter.Close();
}
}
、私はこのような値を渡しています:
DocumentSettings writedoc = new DocumentSettings()
{
Host = Host,
downloadedDocument = downloadDocument
};
Thread t = new Thread(() =>
{
doc.AddDocument(writedoc);
});
t.Start();
私はt.Start();
後t.Join();
を追加した場合、コードがエラーなし私の作品を。しかし、これは私のプロセスを遅くし、事実上、これはスレッドを使用せずに得られる出力と同じです。
私のようなエラーを取得しています:誰もがこのコードで私を助けることができる
Cannot rename /indexes/Segments.new to /indexes/Segments
the file is used by some other process.
?
どのようなエラーが表示されますか?あなたが使用しているコードの小さな例を見ることができますか? – unholysampler
明快にするためにコードを追加しました –