You'll have to open a new IndexReader after the delete is committed.

An IndexReader (or IndexSearcher) only searches the point-in-time snapshot of the index as of when it was opened.

Mike

Cam Bazz wrote:

Hello,

Here is what I am trying to do:

       dir = FSDirectory.getDirectory("/test");
       writer = new IndexWriter(dir, analyzer, true, new
IndexWriter.MaxFieldLength(2));
       writer.setMaxBufferedDocs(IndexWriter.DISABLE_AUTO_FLUSH);

       Document da = new Document();
       da.add(new Field("word", "a", Field.Store.YES,
Field.Index.NOT_ANALYZED_NO_NORMS));

       Document db = new Document();
       db.add(new Field("word", "b", Field.Store.YES,
Field.Index.NOT_ANALYZED_NO_NORMS));

       writer.addDocument(da);
       writer.addDocument(db);

       writer.commit();

       searcher = new IndexSearcher(dir);

       writer.deleteDocuments(new Term("word", "a"));
       writer.commit();

       TopDocCollector collector = new TopDocCollector(10);
searcher.search(new TermQuery(new Term("word","a")), collector);
       ScoreDoc[] hits = collector.topDocs().scoreDocs;
       for (int i = 0; i < hits.length; i++) {
           int docId = hits[i].doc;
           Document d = searcher.doc(docId);
           System.out.println(writer.hasDeletions());
System.out.println(searcher.getIndexReader().isDeleted(docId));
           System.out.println(d.get("word"));
       }

       searcher.close();
       writer.close();
       dir.close();


well I am trying to check if an document has been deleted without
refreshing the searcher. maybe i should access indexreader in a
different way?
the isDeleted() always returns false. that is the problem right now.

Best.

-C.B.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to