lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From carlo walentiny <carlo.walent...@gmail.com>
Subject Bug or Stupid: deleting (some) query results while iterating over query results
Date Fri, 25 Nov 2005 16:00:50 GMT
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


Mime
View raw message