lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Cam Bazz" <camb...@gmail.com>
Subject more on isDeleted
Date Mon, 15 Sep 2008 19:05:19 GMT
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: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Mime
View raw message