lucene-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject Re: Deleting Documents
Date Fri, 20 Jun 2008 11:03:50 GMT
I have changed my code to use the delete function of the writer and this doesn't work either.
Here's my code:
  private void indexDocument(IndexWriter writer, Document document, File file) throws CorruptIndexException,
  writer.deleteDocuments(new Term(IDHConstants.FILE_ID,FileNameUtil.getFileId(file)));
  document.add(new Field(IDHConstants.DATE_LAST_INDEX, DateUtil.formatDate(new Date()), Field.Store.YES,

Devashish <> wrote:
  On Tue, 2008-06-17 at 16:03 +0530, SEAN MCELROY wrote:
> Hello,
> I'm having difficulty deleting documents from an index. I am using lucene 2.3.1
> The program that I have created recursively searches a directory and indexes the documents
that it finds. The first thing I do is open the index for writing:
> writer = new IndexWriter(indexDir,analyzer);
> I then search the directory for certain types of files: text, pdf, doc, etc. I have a
basic algorithm that creates a unique id for each document and checks the index to see if
this file exists. If the file exists I then compare the date the file was last update against
the date it was last indexed. If the file has been updated since it was last indexed I try
to remove the file and re-index. I can successfully retrieve existing documents from the index
using the file id but I cannot remove a file. This is the code I use to remove the file.
> private void removeDocument(IndexWriter writer, File file) throws CorruptIndexException,
> {
> IndexReader indexReader =;
> indexReader.deleteDocuments(new Term(IDHConstants.FILE_ID,FileNameUtil.getFieId(file)));
> indexReader.close();
> }
> This code doesn't work. I have tried IndexWriter.updateDocument and it also does not
work. Is is because I have an IndexWriter open when I try to delete the document?

Yes it is because you have IndexWriter open while you are trying to
delete using the IndexReader. You should close the IndexWriter first and
then delete using IndexReader, or else use the delete() function of the
IndexWriter itself... 

> All help welcome.
> Regards,
> Sean
Naukri Tech

  • Unnamed multipart/alternative (inline, 8-Bit, 0 bytes)
View raw message