lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Joseph Ottinger <j...@enigmastation.com>
Subject IndexReader.delete(int) not working for me
Date Wed, 05 Mar 2003 16:59:11 GMT
I've got a versioning content system where I want to replace documents in
a lucene repository. To do so, according to the FAQ and the mailing list
archives, I need to open an IndexReader, look for the document in
question, delete it via the IndexReader, and then add it.

This shouldn't replace the document per se - it should, however, free the
index entry (for reuse by documents added later) as I understand it. It
should also mark the document as deleted. A query still may return the
document (again, as I understand it), requiring a filter to make sure
deleted documents aren't returned.

If I'm offbase in my understanding, I apologize - this is the best I can
tell.

In my removeDocument() method (names and parameters are obscured to remove
cruft not germane to the problem at hand), I iterate through the
IndexReader's documents (because there are non-indexed identifiers used).
When I hit a document that contains the correct identifiers, I use
ir.delete(idx), and output a log message that I'm deleting the document.

This part works as expected. (A log message for one entry is spit out.)

Now, however, when I search for documents, things go awry. I'm using the
standard analyzer (StandardAnalyzer, I should say), and
IndexSearcher(String). I then use code like the following:

Hits hits=searcher.search(query, new Filter() {
  public BitSet bits(IndexReader ir) throws IOException {
    BitSet bs=new BitSet();
    for(int idx=0;idx<ir.maxDoc();idx++) {
      boolean deleted=ir.isDeleted(idx);
      bs.set(idx, !deleted);
    }
    return bs;
  }
});

(I also have a log message to output the salient information about the
document and whether it's been deleted.)

Here's where the problem evinces itself: *every* document here says that
it's not deleted, even though the removeDocument() method mentioned above
doesn't show all of the documents returned here. It's almost like there
are two IndexReaders in action, one noting the deleted documents, and the
other not. It's very confusing to me. Can anyone give me any pointers?

---------------------------------------------------------
Joseph B. Ottinger                 joeo@enigmastation.com
http://enigmastation.com                    IT Consultant


---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-user-help@jakarta.apache.org


Mime
View raw message