I receive these kinds of errors when multiple threads are searching/writing to the index at the same time. So far, I have had to resort to .NET locks for key locations in code, such as:
Dim hits As Hits = Nothing SyncLock aLock hits = searcher.Search(query, df1, custSort) End SyncLock SyncLock aLock Result = reader.DeleteDocuments(New Term("Id", CStr(Id))) reader.Close() End SyncLock SyncLock aLock writer.AddDocument(doc) writer.Close() End SyncLock This of course kills our scalability, so I am so interested in knowing how to address multi-process/multi-threaded access to any particular index. - Michael -----Original Message----- From: Simon Gartz [mailto:[EMAIL PROTECTED] Sent: Monday, January 15, 2007 6:54 AM To: lucene-net-user@incubator.apache.org Subject: FileNotFoundException, is this code supposed to work? Hi, I've seen this questions before with slightly different approaches, but non with sample code. Is this code supposed to work or not, using Lucene.net v1.9.1.3? I get follwing error executing the code below. Note that it might take some time to crash. System.IO.FileNotFoundException : Could not find file "C:\DOCUME~1\sgartz\LOCALS~1\Temp\lucene\_1ji.frq". at System.IO.__Error.WinIOError(Int32 errorCode, String str) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean useAsync, String msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share) at Lucene.Net.Store.Descriptor..ctor(FSIndexInput enclosingInstance, FileInfo file, FileAccess mode) at Lucene.Net.Store.FSIndexInput..ctor(FileInfo path) at Lucene.Net.Store.FSDirectory.OpenInput(String name) at Lucene.Net.Index.SegmentReader.Initialize(SegmentInfo si) at Lucene.Net.Index.SegmentReader.Get(Directory dir, SegmentInfo si, SegmentInfos sis, Boolean closeDir, Boolean ownDir) at Lucene.Net.Index.SegmentReader.Get(SegmentInfo si) at Lucene.Net.Index.AnonymousClassWith.DoBody() at Lucene.Net.Store.With.Run() at Lucene.Net.Index.IndexReader.Open(Directory directory, Boolean closeDirectory) at Lucene.Net.Index.IndexReader.Open(String path) at Lucene.Net.Search.IndexSearcher..ctor(String path) c:\projects\x\development\x.test\indexingservice\indexingservicetest.cs( 128,0): at x.Test.IndexingService.IndexingServiceTest.LuceneThreadTest() private static readonly string directory = Path.Combine(Path.GetTempPath(), "lucene"); [Test] public void LuceneThreadTest(){ //Create index Lucene.Net.Analysis.Analyzer analyzer = new Lucene.Net.Analysis.SimpleAnalyzer(); Lucene.Net.Index.IndexWriter writer = new Lucene.Net.Index.IndexWriter(directory, analyzer, true); writer.Close(); //Start indexing thread Thread indexThread = new Thread(new ThreadStart(LuceneIndexThread)); indexThread.Start(); while(indexThread.IsAlive){ Console.WriteLine("Searching..."); Lucene.Net.Search.Searcher searcher = new Lucene.Net.Search.IndexSearcher(directory); Lucene.Net.Search.Hits hits = null; Lucene.Net.QueryParsers.QueryParser parser = new Lucene.Net.QueryParsers.QueryParser("contents", analyzer); Lucene.Net.Search.Query query = parser.Parse("put"); Console.WriteLine("Query: " + query.ToString("contents")); hits = searcher.Search(query); Console.WriteLine(hits.Length() + " total results"); for (int i = 0; i < hits.Length() && i < 10; i++) { Lucene.Net.Documents.Document d = hits.Doc(i); Console.WriteLine(i + " " + hits.Score(i) + " " + d.Get("contents").Length + " " + d.Get("contents").Substring(0, 20)); } searcher.Close(); Thread.Sleep(1000); } } private void LuceneIndexThread(){ Console.WriteLine("Start indexing files"); for(int j = 0; j < 100; j++){ Lucene.Net.Analysis.Analyzer analyzer = new Lucene.Net.Analysis.SimpleAnalyzer(); Lucene.Net.Index.IndexWriter writer = new Lucene.Net.Index.IndexWriter(directory, analyzer, false); for (int i = 0; i < 100; i++) { Lucene.Net.Documents.Document d = new Lucene.Net.Documents.Document(); string content = new string('a', (new Random()).Next(100) * 10); d.Add(new Lucene.Net.Documents.Field("contents", "Put contents here " + content, Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.TOKENIZED)); writer.AddDocument(d); } writer.Close(); Console.WriteLine("Indexed 100 documents..."); } Console.WriteLine("Finished indexing files"); } Regards Simon