lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cfow...@jwpepper.com
Subject deleteDocuments being ingnored
Date Mon, 09 Oct 2006 16:06:57 GMT
Hello,

        I'm brand new to this, so hopefully you can help me. I'm 
attempting to use the IndexReader object in lucene v2 to delete and readd 
documents. I very easily set up an index and my documents are added. Now 
I'm trying to update the same index by deleting the document before 
readding. The problem is that it appears that my deleteDocument() 
instruction is being ignored. I've tried using the IndexModifier object 
and the IndexReader and both have the same behavior. If anyone can point 
out my error, or help me debug this I'll be forever in your debt. Here is 
the jist of the code. 

This is the main section:
                IndexWriter writer = new IndexWriter(indexDir,new 
StandardAnalyzer(), false);
                writer.setUseCompoundFile(false);
                indexDirectory(writer, dataDir);
                int numIndexed = writer.docCount();
                writer.optimize();
                writer.close();

Down at the point just before readding my document I have the following 
code (i know batch is better, just doing it this for now):
                IndexReader ir = IndexReader.open(indexDir);
                System.out.println(">>>" + ir.numDocs());
                ir.delete(new Term("filename",f.getAbsolutePath()));
                System.out.println("deletes?" + ir.hasDeletions());
                ir.close();
                if (deleted > 0) {
                        System.out.println("deleted old index of " + 
f.getAbsolutePath());
                }
                System.out.println("Indexing " + f.getAbsolutePath());
                Document doc = new Document();
                doc.add(new Field("contents",loadContents
(doc),Field.Store.NO,Field.Index.TOKENIZED));
                doc.add(new Field("filename", 
f.getAbsolutePath(),Field.Store.YES,Field.Index.TOKENIZED));  
writer.addDocument(doc);

Thanks,

Chris
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message