lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Vanlerberghe, Luc" <Luc.Vanlerber...@bvdep.com>
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
work...

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)

Luc


-----Original Message-----
From: carlo walentiny [mailto:carlo.walentiny@gmail.com] 
Sent: vrijdag 25 november 2005 17:01
To: java-dev@lucene.apache.org
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
results,
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.

-carlo

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

      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));

          w.addDocument(d);
        }
      w.close();

      IndexReader r = IndexReader.open(iD);
      IndexSearcher s = new IndexSearcher(r);

      TermQuery q = new TermQuery(new Term("fieldname", "fieldval"));
      Hits hits = s.search(q);
      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);
            if(di%2==0)
              {
                r.delete(hits.id(di));
              }
          }

      r.close();
      s.close();

    }

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



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


Mime
View raw message