title: Lucene.net intermitantly indexed documents not appearing in the
body: <p>I've got an issue which shows up intermitantly in my unit tests and I can't work out why.</p>
  
  <p>The unit test itself is adding multiple documents to an index, then trying to query the index to get the documents back out again.</p>
  
  <p>So 95% of the time it works without any problems. Then the other 5% of the time it cannot retrieve the documents back out of the index.</p>
  
  <p>My unit test code is as follows:</p>
  
  <pre><code>[Test]
      public void InsertMultipleDocuments()
      {
          string indexPath = null;
          using (LuceneHelper target = GetLuceneHelper(ref indexPath))
          {
              target.InsertOrUpdate(
                      target.MakeDocument(GetDefaultSearchDocument()), 
                      target.MakeDocument(GetSecondSearchDocument()));
  
              var doc = target.GetDocument(_documentID.ToString()).FirstOrDefault();
              Assert.IsNotNull(doc);
              Assert.AreEqual(doc.DocumentID, _documentID.ToString());
  
              doc = target.GetDocument(_document2ID.ToString()).FirstOrDefault();
              Assert.IsNotNull(doc);
              Assert.AreEqual(doc.DocumentID, _document2ID.ToString());
          }
  
          TidyUpTempFolder(indexPath);
      }
  </code></pre>
  
  <p>I won't post the full code from my LuceneHelper, but the basic idea of it is that it holds an IndexSearcher in reference which is closed every time an item is written to the index (so it can be re-opened again with all the of the latest documents).</p>
  
  <p>The actual unit test will often fail when gathering the second document. I assumed it was to do with the searcher not being closed and seeing cached data, however this isn't the case.</p>
  
  <p>Does Lucene have any delay in adding documents to the index? I assumed that once it had added the document to the index it was available immediately as long as you closed any old search indexers and opened a new one.</p>
  
  <p>Any ideas?</p>