lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Danny Lade (JIRA)" <j...@apache.org>
Subject [jira] [Created] (LUCENE-3180) Can't delete a document using deleteDocument(int docID) if using IndexWriter AND IndexReader
Date Wed, 08 Jun 2011 06:59:58 GMT
Can't delete a document using deleteDocument(int docID) if using IndexWriter AND IndexReader
--------------------------------------------------------------------------------------------

                 Key: LUCENE-3180
                 URL: https://issues.apache.org/jira/browse/LUCENE-3180
             Project: Lucene - Java
          Issue Type: Bug
          Components: core/index
    Affects Versions: 3.2
         Environment: Windows 
            Reporter: Danny Lade


It is impossible to delete a document with "reader.deleteDocument(scoreDoc.doc)" yet.

using:
  Directory directory = FSDirectory.open(new File("lucene"));
  
  writer = new IndexWriter(directory, config);
  reader = IndexReader.open(writer, true);

results in:
  Exception in thread "main" java.lang.UnsupportedOperationException: This IndexReader cannot
make any changes to the index (it was opened with readOnly = true)
      at org.apache.lucene.index.ReadOnlySegmentReader.noWrite(ReadOnlySegmentReader.java:23)
      at org.apache.lucene.index.ReadOnlyDirectoryReader.acquireWriteLock(ReadOnlyDirectoryReader.java:43)
      at org.apache.lucene.index.IndexReader.deleteDocument(IndexReader.java:1067)
      at de.morpheum.morphy.ImpossibleLuceneCode.main(ImpossibleLuceneCode.java:60)

and using:
  Directory directory = FSDirectory.open(new File("lucene"));
  
  writer = new IndexWriter(directory, config);
  reader = IndexReader.open(directory, false);
  
results in:
  org.apache.lucene.store.LockObtainFailedException: Lock obtain timed out: NativeFSLock@S:\Java\Morpheum\lucene\write.lock
      at org.apache.lucene.store.Lock.obtain(Lock.java:84)
      at org.apache.lucene.index.DirectoryReader.acquireWriteLock(DirectoryReader.java:765)
      at org.apache.lucene.index.IndexReader.deleteDocument(IndexReader.java:1067)
      at de.morpheum.morphy.ImpossibleLuceneCode.main(ImpossibleLuceneCode.java:69)

A workaround is:
  for (ScoreDoc scoreDoc : hits) {
      Document document = reader.document(scoreDoc.doc);

      writer.addDocument(document);
  }

  writer.deleteDocuments(query);

But this is using the query twice and may result in inconsistent data (new added documents
may be removed also).
On the other hand I can't use the "writer.deleteDocuments(query)" first because I need the
documents for some updates.


--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

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


Mime
View raw message