title: Unit test for Lucene indices
body: <p>I'm working on legacy code that builds an index of popular terms in another index. There are no unit tests in place, and the indexing process is a pain to wait for because the first index takes so long to build. </p>
  
  <p>I want to structure the second (popular term) index differently. Is there a best practice for testing to see if a Lucene index is being created properly?</p>
  
  <p><strong>EDIT>></strong> Per @Pascal's advice I'm using a RAMDirectory, then to test the index I just wrote I set up an indexReader and iterate through the term results, printing out each term to make sure the data looks alright.</p>
  
  <p>Code:</p>
  
  <pre><code>IndexReader reader = IndexReader.open(dir2);
  TermEnum terms = reader.terms();
  System.out.println("Here come the terms!");
  while (terms.next()){
      if (terms.term().field().equals("FULLTEXT")){
          System.out.println(terms.term());
      }
  }
  int numDocs = reader.maxDoc();
  System.out.println("Number of Docs: " + numDocs);
  </code></pre>
  
  <p>If the index is really large I let it run for a bit then just stop it midway through.</p>
  
  <p>Also, <a href="http://code.google.com/p/luke/" rel="nofollow noreferrer">Luke</a> is a great tool for inspecting the index if you want to be more thorough... I'm just looking for something fast.</p>
  
  <p>Any other ideas are welcome!</p>