lucene-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From SEAN MCELROY <sean.mcel...@btinternet.com>
Subject Deleting Documents
Date Tue, 17 Jun 2008 10:33:13 GMT
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,
IOException
  {
      IndexReader indexReader = IndexReader.open(writer.getDirectory());
      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?
   
  All help welcome.
   
  Regards,
  
Sean
   
   
   

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