사이트를 크롤링하고 컨텐츠를 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.Join();
t.Start();
후 추가하는 경우. 하지만 이렇게하면 프로세스가 느려지고 사실상 스레드를 사용하지 않고 얻을 수있는 출력과 같습니다.
Cannot rename /indexes/Segments.new to /indexes/Segments
the file is used by some other process.
사람이 코드를 좀 도와 줄래 : 같은
나는 점점 오전 오류?
어떤 오류가 발생합니까? 사용중인 코드의 작은 예를 볼 수 있습니까? – unholysampler
명확성을 위해 코드가 추가되었습니다. –