You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by "Danny Lade (JIRA)" <ji...@apache.org> on 2011/06/08 08:59:58 UTC

[jira] [Created] (LUCENE-3180) Can't delete a document using deleteDocument(int docID) if using IndexWriter AND IndexReader

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


[jira] [Updated] (LUCENE-3180) Can't delete a document using deleteDocument(int docID) if using IndexWriter AND IndexReader

Posted by "Danny Lade (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LUCENE-3180?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Danny Lade updated LUCENE-3180:
-------------------------------

    Description: 
It is impossible to delete a document with "reader.deleteDocument(docID)" if using an IndexWriter too.

using:
{code:java}
writer = new IndexWriter(directory, config);
reader = IndexReader.open(writer, true);
{code}

results in:
{code:java}
  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)
{code}

and using:
{code:java}
writer = new IndexWriter(directory, config);
reader = IndexReader.open(directory, false);
{code}
  
results in:
{code:java}
  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)
{code}


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

using:
{code:java}
writer = new IndexWriter(directory, config);
reader = IndexReader.open(writer, true);
{code}

results in:
{code:java}
  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)
{code}

and using:
{code:java}
writer = new IndexWriter(directory, config);
reader = IndexReader.open(directory, false);
{code}
  
results in:
{code:java}
  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)
{code}



> 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
>         Attachments: ImpossibleLuceneCode.java
>
>
> It is impossible to delete a document with "reader.deleteDocument(docID)" if using an IndexWriter too.
> using:
> {code:java}
> writer = new IndexWriter(directory, config);
> reader = IndexReader.open(writer, true);
> {code}
> results in:
> {code:java}
>   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)
> {code}
> and using:
> {code:java}
> writer = new IndexWriter(directory, config);
> reader = IndexReader.open(directory, false);
> {code}
>   
> results in:
> {code:java}
>   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)
> {code}

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


[jira] [Updated] (LUCENE-3180) Can't delete a document using deleteDocument(int docID) if using IndexWriter AND IndexReader

Posted by "Danny Lade (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LUCENE-3180?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Danny Lade updated LUCENE-3180:
-------------------------------

    Attachment: ImpossibleLuceneCode.java

> 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
>         Attachments: ImpossibleLuceneCode.java
>
>
> 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


[jira] [Updated] (LUCENE-3180) Can't delete a document using deleteDocument(int docID) if using IndexWriter AND IndexReader

Posted by "Danny Lade (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LUCENE-3180?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Danny Lade updated LUCENE-3180:
-------------------------------

    Attachment: ImpossibleLuceneCode.java

example code

> 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
>         Attachments: ImpossibleLuceneCode.java
>
>
> 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


[jira] [Commented] (LUCENE-3180) Can't delete a document using deleteDocument(int docID) if using IndexWriter AND IndexReader

Posted by "Danny Lade (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LUCENE-3180?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13046415#comment-13046415 ] 

Danny Lade commented on LUCENE-3180:
------------------------------------

Hello Simon,

I will add an ID to my documents, that should do the trick.

Thanks for the help. 
:-)


> 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
>         Attachments: ImpossibleLuceneCode.java
>
>
> It is impossible to delete a document with "reader.deleteDocument(docID)" if using an IndexWriter too.
> using:
> {code:java}
> writer = new IndexWriter(directory, config);
> reader = IndexReader.open(writer, true);
> {code}
> results in:
> {code:java}
>   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)
> {code}
> and using:
> {code:java}
> writer = new IndexWriter(directory, config);
> reader = IndexReader.open(directory, false);
> {code}
>   
> results in:
> {code:java}
>   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)
> {code}

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


[jira] [Commented] (LUCENE-3180) Can't delete a document using deleteDocument(int docID) if using IndexWriter AND IndexReader

Posted by "Simon Willnauer (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LUCENE-3180?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13045846#comment-13045846 ] 

Simon Willnauer commented on LUCENE-3180:
-----------------------------------------

Danny, this is all expected behavior. I am going to close this issue now since there is no bug here whatsoever. Please can you phrase quickly what you are trying to do and I am happy to explain best practice on the user list. Thanks.

> 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
>         Attachments: ImpossibleLuceneCode.java
>
>
> It is impossible to delete a document with "reader.deleteDocument(docID)" if using an IndexWriter too.
> using:
> {code:java}
> writer = new IndexWriter(directory, config);
> reader = IndexReader.open(writer, true);
> {code}
> results in:
> {code:java}
>   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)
> {code}
> and using:
> {code:java}
> writer = new IndexWriter(directory, config);
> reader = IndexReader.open(directory, false);
> {code}
>   
> results in:
> {code:java}
>   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)
> {code}

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


[jira] [Updated] (LUCENE-3180) Can't delete a document using deleteDocument(int docID) if using IndexWriter AND IndexReader

Posted by "Danny Lade (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LUCENE-3180?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Danny Lade updated LUCENE-3180:
-------------------------------

    Attachment:     (was: ImpossibleLuceneCode.java)

> 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
>         Attachments: ImpossibleLuceneCode.java
>
>
> 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


[jira] [Commented] (LUCENE-3180) Can't delete a document using deleteDocument(int docID) if using IndexWriter AND IndexReader

Posted by "Danny Lade (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LUCENE-3180?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13045817#comment-13045817 ] 

Danny Lade commented on LUCENE-3180:
------------------------------------

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

      writer.addDocument(document);
  }

  writer.deleteDocuments(query);
{code}

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.


> 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
>         Attachments: ImpossibleLuceneCode.java
>
>
> It is impossible to delete a document with "reader.deleteDocument(scoreDoc.doc)" yet.
> using:
> {code:java}
> writer = new IndexWriter(directory, config);
> reader = IndexReader.open(writer, true);
> {code}
> results in:
> {code:java}
>   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)
> {code}
> and using:
> {code:java}
> writer = new IndexWriter(directory, config);
> reader = IndexReader.open(directory, false);
> {code}
>   
> results in:
> {code:java}
>   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)
> {code}

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


[jira] [Commented] (LUCENE-3180) Can't delete a document using deleteDocument(int docID) if using IndexWriter AND IndexReader

Posted by "Danny Lade (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LUCENE-3180?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13045866#comment-13045866 ] 

Danny Lade commented on LUCENE-3180:
------------------------------------

I tried to update some documents got by a query. The main problem ist, that not all documents I found has to be updated (because the information to the changes is calculated outside the index).

It looks like in the appended example:

{code:java}
for (ScoreDoc scoreDoc : hits) {
    Document document = reader.document(scoreDoc.doc);

    // calculate changes, if no changes, than ignore it
    if (!hasChanged) {
        continue;
    }
    
    // update document
    // - remove / add fields
    // - etc
    
    // update at index
    reader.deleteDocument(scoreDoc.doc);
    writer.addDocument(document);
}
{code}

So how do I "update" (or "delete and add") a collection of documents without a query or term given?


> 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
>         Attachments: ImpossibleLuceneCode.java
>
>
> It is impossible to delete a document with "reader.deleteDocument(docID)" if using an IndexWriter too.
> using:
> {code:java}
> writer = new IndexWriter(directory, config);
> reader = IndexReader.open(writer, true);
> {code}
> results in:
> {code:java}
>   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)
> {code}
> and using:
> {code:java}
> writer = new IndexWriter(directory, config);
> reader = IndexReader.open(directory, false);
> {code}
>   
> results in:
> {code:java}
>   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)
> {code}

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


[jira] [Commented] (LUCENE-3180) Can't delete a document using deleteDocument(int docID) if using IndexWriter AND IndexReader

Posted by "Simon Willnauer (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LUCENE-3180?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13046120#comment-13046120 ] 

Simon Willnauer commented on LUCENE-3180:
-----------------------------------------

Hey Danny,

you can/should modify the lucene index only with one writer at the same time. in your example the IndexReader needs to acquire the lock on the index which is hold by the IndexWriter already. In order to modify the index via IndexReader you need to open it writeable too (pass false to readOnly).

Usually to update a document you use some kind of Unique ID field and pass the ID term plus the document to IndexWriter#updateDocument. This will delete all previous documents with the same ID term indexed.  

Hope that helps. You should get some help on the user list too.

> 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
>         Attachments: ImpossibleLuceneCode.java
>
>
> It is impossible to delete a document with "reader.deleteDocument(docID)" if using an IndexWriter too.
> using:
> {code:java}
> writer = new IndexWriter(directory, config);
> reader = IndexReader.open(writer, true);
> {code}
> results in:
> {code:java}
>   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)
> {code}
> and using:
> {code:java}
> writer = new IndexWriter(directory, config);
> reader = IndexReader.open(directory, false);
> {code}
>   
> results in:
> {code:java}
>   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)
> {code}

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


[jira] [Resolved] (LUCENE-3180) Can't delete a document using deleteDocument(int docID) if using IndexWriter AND IndexReader

Posted by "Simon Willnauer (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LUCENE-3180?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Simon Willnauer resolved LUCENE-3180.
-------------------------------------

    Resolution: Invalid

> 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
>         Attachments: ImpossibleLuceneCode.java
>
>
> It is impossible to delete a document with "reader.deleteDocument(docID)" if using an IndexWriter too.
> using:
> {code:java}
> writer = new IndexWriter(directory, config);
> reader = IndexReader.open(writer, true);
> {code}
> results in:
> {code:java}
>   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)
> {code}
> and using:
> {code:java}
> writer = new IndexWriter(directory, config);
> reader = IndexReader.open(directory, false);
> {code}
>   
> results in:
> {code:java}
>   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)
> {code}

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


[jira] [Updated] (LUCENE-3180) Can't delete a document using deleteDocument(int docID) if using IndexWriter AND IndexReader

Posted by "Danny Lade (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LUCENE-3180?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Danny Lade updated LUCENE-3180:
-------------------------------

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

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

results in:
{code:java}
  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)
{code}

and using:
{code:java}
  Directory directory = FSDirectory.open(new File("lucene"));
  
  writer = new IndexWriter(directory, config);
  reader = IndexReader.open(directory, false);
{code}
  
results in:
{code:java}
  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)
{code}

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

      writer.addDocument(document);
  }

  writer.deleteDocuments(query);
{code}

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.


  was:
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.



> 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
>         Attachments: ImpossibleLuceneCode.java
>
>
> It is impossible to delete a document with "reader.deleteDocument(scoreDoc.doc)" yet.
> using:
> {code:java}
>   Directory directory = FSDirectory.open(new File("lucene"));
>   
>   writer = new IndexWriter(directory, config);
>   reader = IndexReader.open(writer, true);
> {code}
> results in:
> {code:java}
>   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)
> {code}
> and using:
> {code:java}
>   Directory directory = FSDirectory.open(new File("lucene"));
>   
>   writer = new IndexWriter(directory, config);
>   reader = IndexReader.open(directory, false);
> {code}
>   
> results in:
> {code:java}
>   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)
> {code}
> A workaround is:
> {code:java}
>   for (ScoreDoc scoreDoc : hits) {
>       Document document = reader.document(scoreDoc.doc);
>       writer.addDocument(document);
>   }
>   writer.deleteDocuments(query);
> {code}
> 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


[jira] [Updated] (LUCENE-3180) Can't delete a document using deleteDocument(int docID) if using IndexWriter AND IndexReader

Posted by "Danny Lade (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LUCENE-3180?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Danny Lade updated LUCENE-3180:
-------------------------------

    Comment: was deleted

(was: example code)

> 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
>         Attachments: ImpossibleLuceneCode.java
>
>
> It is impossible to delete a document with "reader.deleteDocument(scoreDoc.doc)" yet.
> using:
> {code:java}
> writer = new IndexWriter(directory, config);
> reader = IndexReader.open(writer, true);
> {code}
> results in:
> {code:java}
>   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)
> {code}
> and using:
> {code:java}
> writer = new IndexWriter(directory, config);
> reader = IndexReader.open(directory, false);
> {code}
>   
> results in:
> {code:java}
>   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)
> {code}

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


[jira] [Updated] (LUCENE-3180) Can't delete a document using deleteDocument(int docID) if using IndexWriter AND IndexReader

Posted by "Danny Lade (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LUCENE-3180?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Danny Lade updated LUCENE-3180:
-------------------------------

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

using:
{code:java}
writer = new IndexWriter(directory, config);
reader = IndexReader.open(writer, true);
{code}

results in:
{code:java}
  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)
{code}

and using:
{code:java}
writer = new IndexWriter(directory, config);
reader = IndexReader.open(directory, false);
{code}
  
results in:
{code:java}
  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)
{code}


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

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

results in:
{code:java}
  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)
{code}

and using:
{code:java}
  Directory directory = FSDirectory.open(new File("lucene"));
  
  writer = new IndexWriter(directory, config);
  reader = IndexReader.open(directory, false);
{code}
  
results in:
{code:java}
  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)
{code}

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

      writer.addDocument(document);
  }

  writer.deleteDocuments(query);
{code}

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.



> 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
>         Attachments: ImpossibleLuceneCode.java
>
>
> It is impossible to delete a document with "reader.deleteDocument(scoreDoc.doc)" yet.
> using:
> {code:java}
> writer = new IndexWriter(directory, config);
> reader = IndexReader.open(writer, true);
> {code}
> results in:
> {code:java}
>   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)
> {code}
> and using:
> {code:java}
> writer = new IndexWriter(directory, config);
> reader = IndexReader.open(directory, false);
> {code}
>   
> results in:
> {code:java}
>   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)
> {code}

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