title: Lucene 3.0.3 does not delete document
body: <p>We use Lucene to index some internal documents. Sometimes we need to remove documents. These documents have an unique id and are represented by a class DocItem as follows (ALL THE CODE IS A SIMPLIFIED VERSION WITH ONLY SIGNIFICANT (I hope) PARTS):</p>
  
  <pre><code>public final class DocItem {
  
    public static final String fID = "id";
    public static final String fTITLE = "title";
  
    private Document doc = new Document();
    private Field id = new Field(fID, "", Field.Store.YES, Field.Index.ANALYZED);
    private Field title = new Field(fTITLE, "", Field.Store.YES, Field.Index.ANALYZED);
  
    public DocItem() {
      doc.add(id);
      doc.add(title);
    }
  
    ... getters &amp; setters
  
    public getDoc() {
      return doc;
    }
  }
  </code></pre>
  
  <p>So, to index a document, a new DocItem is created and passed to an indexer class as follows:</p>
  
  <pre><code>public static void index(DocItem docitem) {
    File file = new File("indexdir");
    Directory dir= new SimpleFSDirectory(file);
    IndexWriter idxWriter = new IndexWriter(dir, new StandardAnalyzer(Version.LUCENE_30), IndexWriter.MaxFieldLength.UNLIMITED);
    idxWriter.addDocument(docitem.getDoc());
    idxWriter.close();
  }
  </code></pre>
  
  <p>We created an auxiliary method to iterate over the index directory:</p>
  
  <pre><code>public static void listAll() {
    File file = new File("indexdir");
    Directory dir = new SimpleFSDirectory(file);
    IndexReader reader = IndexReader.open(dir);
  
    for (int i = 0; i &lt; reader.maxDoc(); i++) {
      Document doc = reader.document(i);
      System.out.println(doc.get(DocItem.fID));
    }
  }
  </code></pre>
  
  <p>Running the listAll, we can see that our docs are being indexed properly. At least, we can see the id and other attributes.</p>
  
  <p>We retrieve the document using IndexSearcher as follows:</p>
  
  <pre><code>public static DocItem search(String id) {
    File file = new File("indexdir");
    Directory dir = new SimpleFSDirectory(file);
    IndexSearcher searcher = new IndexSearcher(index, true);
    Query q = new QueryParser(Version.LUCENE_30, DocItem.fID, new StandardAnalyzer(Version.LUCENE_30)).parse(id);
    TopDocs td = searcher.search(q, 1);
    ScoreDoc[] hits = td.scoreDocs;
    searcher.close();
    return hits[0];
  }
  </code></pre>
  
  <p>So after retrieving it, we are trying to delete it with:</p>
  
  <pre><code>public static void Delete(DocItem docitem) {
    File file = new File("indexdir");
    Directory dir= new SimpleFSDirectory(file);
    IndexWriter idxWriter = new IndexWriter(dir, new StandardAnalyzer(Version.LUCENE_30), IndexWriter.MaxFieldLength.UNLIMITED);
    idxWriter.deleteDocuments(new Term(DocItem.fID, docitem.getId()));
    idxWriter.commit();
    idxWriter.close();
  }
  </code></pre>
  
  <p>The problem is that it doesn't work. The document is never deleted. If I run the listAll() after the deletion, the document is still there. We tried to use IndexReader, with no lucky.</p>
  
  <p>By this <a href="https://stackoverflow.com/questions/3728901/lucene-delete-record-depreciated">post</a> and this <a href="https://stackoverflow.com/questions/3710941/deleting-document-by-term-from-lucene">post</a>, We think that we are using it accordinlgy.</p>
  
  <p>What we are doing wrong? Any advice? We are using lucene 3.0.3 and java 1.6.0_24.</p>
  
  <p>TIA,</p>
  
  <p>Bob</p>