lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Otis Gospodnetic <otis_gospodne...@yahoo.com>
Subject Re: Deleting document in IndexWriter
Date Fri, 17 Dec 2004 07:30:43 GMT
Hm, what happens if one of the other index-modifying operations (e.g.
optimize, addDocument, addIndexer) is invoked at the same time by
another thread that uses the same IndexWriter instance?
// close IndexWriter
// open IndexReader
// delete via IndexReader
// close IndexReader
// open and return new IndexWriter
public IndexWriter delete(int docNum) throws IOException {
  this.close();
  IndexReader ireader = IndexReader.open(directory);
  ireader.deleteIngoreLock(docNum);
  ireader.close();
  return new IndexWriter(reuse dir, analyzer, create flag);
}

One ugly API perhaps (returning IndexWriter like this), but it doesn't
mess with (no)locks.  Oh, I didn't synchronize on anything.  Maybe on
directory?

Otis

--- Daniel Naber <daniel.naber@t-online.de> wrote:

> Hi,
> 
> the request to delete documents in IndexWriter instead of IndexReader
> comes 
> up regularly. What if we implement a delete() method in IndexWriter
> like 
> this:
> 
>   public synchronized void delete(int docNum) throws IOException {
>     IndexReader ireader = IndexReader.open(directory);
>     ireader.deleteIngoreLock(docNum);
>     ireader.close();
>   }
> 
> deleteIngoreLock would be a new method just like delete, but that
> doesn't 
> create a lock -- it uses the IndexWriter's lock which exists all the
> time. 
> Would this work and would this be safe?
> 
> I'm well aware that this can be slow, but it makes deleting documents
> so 
> much easier for many people who don't have huge indices. We could
> document 
> the fact that it's slow and use an array of document IDs to encourage
> 
> people to delete more than one document at once, so the overhead of 
> opening the reader becomes less.
> 
> Regards
>  Daniel
> 
> -- 
> http://www.danielnaber.de
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: lucene-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: lucene-dev-help@jakarta.apache.org
> 
> 


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


Mime
View raw message