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 Derya Kasapoglu <do...@gmx.de> on 2005/08/29 20:29:50 UTC

IndexReader delete(int i)

Hi,

if i delete a document from index, what does the it do?
I want to know because if i delete documents from index which are
not anymore in the dokument directories like that:

IndexReader reader = IndexReader.open(dir);

for (int i=0; i<reader.numDocs(); i++) {

        Document doc =reader.document(i);
        String path = doc.get("path");
	File file = new File(path);

        if (!file.exists()) reader.delete(i); 
}

reader.close();

the IndexReader doesn't delete all dokuments by the first run!!!!

I mean if i say  
if (!file.exists()) System.out.println(path);
i get all documents which are not in the directory  but if i say reader.delete(i)
it deletes only a part of the documents which are not exists!!!
If i start the application again it delets the rest, sometimes not all of the rest,
but if i start it again and again it deletes all documents which are not exists.

But why it doen't do it by the first run?
Does delete() do something  with the document IDs? Or something else?




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


Re: IndexReader delete(int i)

Posted by do...@gmx.de.
Hi Yonik,

thank you very much!!
Now it works very well!! 
The formula "numDocs() == maxDocs() - numer_of_deleted_docs" should be stand
in the API! :)

Thank you again!
Bye Derya

> --- Ursprüngliche Nachricht ---
> Von: Yonik Seeley <ys...@gmail.com>
> An: java-user@lucene.apache.org
> Betreff: Re: IndexReader delete(int i)
> Datum: Mon, 29 Aug 2005 15:55:26 -0400
> 
> Perhaps because you are not iterating over all the documents?
> numDocs() == maxDocs() - numer_of_deleted_docs
> So first try replacing numDocs() with maxDocs()
> 
> -Yonik
> 
> 
> On 8/29/05, Derya Kasapoglu <do...@gmx.de> wrote:
> > Hi,
> > 
> > if i delete a document from index, what does the it do?
> > I want to know because if i delete documents from index which are
> > not anymore in the dokument directories like that:
> > 
> > IndexReader reader = IndexReader.open(dir);
> > 
> > for (int i=0; i<reader.numDocs(); i++) {
> > 
> >         Document doc =reader.document(i);
> >         String path = doc.get("path");
> >         File file = new File(path);
> > 
> >         if (!file.exists()) reader.delete(i);
> > }
> > 
> > reader.close();
> > 
> > the IndexReader doesn't delete all dokuments by the first run!!!!
> > 
> > I mean if i say
> > if (!file.exists()) System.out.println(path);
> > i get all documents which are not in the directory  but if i say
> reader.delete(i)
> > it deletes only a part of the documents which are not exists!!!
> > If i start the application again it delets the rest, sometimes not all
> of the rest,
> > but if i start it again and again it deletes all documents which are not
> exists.
> > 
> > But why it doen't do it by the first run?
> > Does delete() do something  with the document IDs? Or something else?
> > 
> > 
> > 
> > 
> > ---------------------------------------------------------------------
> > 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
> 

-- 
5 GB Mailbox, 50 FreeSMS http://www.gmx.net/de/go/promail
+++ GMX - die erste Adresse für Mail, Message, More +++

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


Re: IndexReader delete(int i)

Posted by Yonik Seeley <ys...@gmail.com>.
Perhaps because you are not iterating over all the documents?
numDocs() == maxDocs() - numer_of_deleted_docs
So first try replacing numDocs() with maxDocs()

-Yonik


On 8/29/05, Derya Kasapoglu <do...@gmx.de> wrote:
> Hi,
> 
> if i delete a document from index, what does the it do?
> I want to know because if i delete documents from index which are
> not anymore in the dokument directories like that:
> 
> IndexReader reader = IndexReader.open(dir);
> 
> for (int i=0; i<reader.numDocs(); i++) {
> 
>         Document doc =reader.document(i);
>         String path = doc.get("path");
>         File file = new File(path);
> 
>         if (!file.exists()) reader.delete(i);
> }
> 
> reader.close();
> 
> the IndexReader doesn't delete all dokuments by the first run!!!!
> 
> I mean if i say
> if (!file.exists()) System.out.println(path);
> i get all documents which are not in the directory  but if i say reader.delete(i)
> it deletes only a part of the documents which are not exists!!!
> If i start the application again it delets the rest, sometimes not all of the rest,
> but if i start it again and again it deletes all documents which are not exists.
> 
> But why it doen't do it by the first run?
> Does delete() do something  with the document IDs? Or something else?
> 
> 
> 
> 
> ---------------------------------------------------------------------
> 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