lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Vanlerberghe, Luc" <>
Subject RE: Bug or Stupid: deleting (some) query results while iterating over query results
Date Fri, 25 Nov 2005 16:17:04 GMT
Wild guess:
Under the hood, Hits gets the first 100 results when it is constructed.
If you get result number 101, the search is executed again and 200
results buffered (this doubles each time).
However, since you have modified the underlying reader, the second and
subsequent searches will not return the same first 100 results.

Perhaps try again by opening two IndexReader on the same index, verify
that they are looking at the same version (a property added in Lucene
1.9) and use one for searching, the other for deleting.  That should

Perhaps the documentation should indicate that you can get unexpected
results when you delete documents in an IndexReader that is also used as
by a Searcher (or throw an IllegalStateException or something)


-----Original Message-----
From: carlo walentiny [] 
Sent: vrijdag 25 november 2005 17:01
Subject: Bug or Stupid: deleting (some) query results while iterating
over query results

The below test case does a query and, while iterating over the query
deletes some of the hits.

This works for some values "number of query results" and "number of
deleted docs",
but reliably fails for some other settings, for example those in the
testcase below.

I've verified it (to fail) under 1.4.3 and 1.9 (a checkout done a few
days ago).

Any ideas welcome.


  public void test() throws Exception
      Directory iD = new RAMDirectory();
      IndexWriter w = new IndexWriter(iD,new SimpleAnalyzer(),true);

      w = new IndexWriter(iD,new SimpleAnalyzer(),false);
      final int INIT_UIDS = 573; // leave like this
      for(int uid=0; uid<INIT_UIDS; uid++)
          Document d = new Document();
          // use obsolete form to work under lucene 1.4.3 & 1.9:
          d.add(new Field("fieldname", "fieldval", true, true, false));


      IndexReader r =;
      IndexSearcher s = new IndexSearcher(r);

      TermQuery q = new TermQuery(new Term("fieldname", "fieldval"));
      Hits hits =;
      System.out.println("hits: " + hits.length() );
      if(hits!=null && hits.length()>0)
        for(int di = 0; di<hits.length(); di++)
            System.out.println("  di: " + di);
            Document d = hits.doc(di);



To unsubscribe, e-mail:
For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message