You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Mikko Noromaa <mi...@noromaa.fi> on 2005/08/23 09:58:59 UTC

Why is delete() part of IndexREADER?

Hi,

Why IndexReader allows me to do write-operations like delete? I'd think this
should be part of the IndexWriter class instead.

I had created a wrapper class that callers can open for either writing or
searching. It creates either an IndexWriter or an IndexSearches and stores
that inside itself for later use in methods like MyAddDocument and MySearch.
Implementation of MyUpdateDocument, however, became very ugly:

// Open the index for "reading" first.
writer.close();
reader = IndexReader.open(CurrentIndexPath);

// Delete the requested document.
reader.delete(new Term("id", String.valueOf(ID)));
reader.close();

// Re-open the IndexWriter.
writer = new IndexWriter(CurrentIndexPath, analyzer, false);

// Add the new document through normal add-logic.
DoAddDocument (DocText, ID);


Could the delete() method be moved from IndexReader to IndexWriter? Or
perhaps IndexWriter should implement IndexReader, so delete() would be
callable on IndexWriter as well?

--

Mikko Noromaa (mikko@noromaa.fi) - tel. +358 40 7348034
Noromaa Solutions - see http://www.nm-sol.com/
 


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


Re: Why is delete() part of IndexREADER?

Posted by Cheolgoo Kang <ap...@gmail.com>.
It's because of Lucene's index structure. IndexWriter creates a new
segment(one Lucene index is composed of several segments) when a
document added and doesn't care about old indexes already exist. So,
IndexWriter should not have delete() operation for old indexes. And
so, the IndexReader have control of read and delete over all the
documents indexed before.


On 8/23/05, Ray Tsang <sa...@gmail.com> wrote:
> I have come to peace with this problem.  Basically, I think it's
> because you need to read/find what you are deleting first? hehe
> 
> Writer just need to write whatever it's been told to write.
> 
> ray,
> 
> On 8/23/05, Mikko Noromaa <mi...@noromaa.fi> wrote:
> > Hi,
> >
> > Why IndexReader allows me to do write-operations like delete? I'd think this
> > should be part of the IndexWriter class instead.
> >
> > I had created a wrapper class that callers can open for either writing or
> > searching. It creates either an IndexWriter or an IndexSearches and stores
> > that inside itself for later use in methods like MyAddDocument and MySearch.
> > Implementation of MyUpdateDocument, however, became very ugly:
> >
> > // Open the index for "reading" first.
> > writer.close();
> > reader = IndexReader.open(CurrentIndexPath);
> >
> > // Delete the requested document.
> > reader.delete(new Term("id", String.valueOf(ID)));
> > reader.close();
> >
> > // Re-open the IndexWriter.
> > writer = new IndexWriter(CurrentIndexPath, analyzer, false);
> >
> > // Add the new document through normal add-logic.
> > DoAddDocument (DocText, ID);
> >
> >
> > Could the delete() method be moved from IndexReader to IndexWriter? Or
> > perhaps IndexWriter should implement IndexReader, so delete() would be
> > callable on IndexWriter as well?
> >
> > --
> >
> > Mikko Noromaa (mikko@noromaa.fi) - tel. +358 40 7348034
> > Noromaa Solutions - see http://www.nm-sol.com/
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> > For additional commands, e-mail: java-user-help@lucene.apache.org
> >
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
> 
> 


-- 
Regards,
Cheolgoo Kang

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


Re: Why is delete() part of IndexREADER?

Posted by Ray Tsang <sa...@gmail.com>.
I have come to peace with this problem.  Basically, I think it's
because you need to read/find what you are deleting first? hehe

Writer just need to write whatever it's been told to write.

ray,

On 8/23/05, Mikko Noromaa <mi...@noromaa.fi> wrote:
> Hi,
> 
> Why IndexReader allows me to do write-operations like delete? I'd think this
> should be part of the IndexWriter class instead.
> 
> I had created a wrapper class that callers can open for either writing or
> searching. It creates either an IndexWriter or an IndexSearches and stores
> that inside itself for later use in methods like MyAddDocument and MySearch.
> Implementation of MyUpdateDocument, however, became very ugly:
> 
> // Open the index for "reading" first.
> writer.close();
> reader = IndexReader.open(CurrentIndexPath);
> 
> // Delete the requested document.
> reader.delete(new Term("id", String.valueOf(ID)));
> reader.close();
> 
> // Re-open the IndexWriter.
> writer = new IndexWriter(CurrentIndexPath, analyzer, false);
> 
> // Add the new document through normal add-logic.
> DoAddDocument (DocText, ID);
> 
> 
> Could the delete() method be moved from IndexReader to IndexWriter? Or
> perhaps IndexWriter should implement IndexReader, so delete() would be
> callable on IndexWriter as well?
> 
> --
> 
> Mikko Noromaa (mikko@noromaa.fi) - tel. +358 40 7348034
> Noromaa Solutions - see http://www.nm-sol.com/
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
> 
>

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