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 Bruce Cota <br...@vivi.com> on 2003/06/09 18:11:13 UTC
Deleting documents that meet a query
I need to delete all the documents from an index that
satisfy a BooleanQuery.
The only methods I can find (in IndexReader) for deleting
a document are delete(Term) and delete(int).
I tried searching on my Query using IndexSearcher.search(),
iterating over each document in the returned Hits,
and then iterating over Hits deleting each document like this:
for (int i=0; i<hits.length(); +++i) {
ireader.delete(hits.id(i));
}
Hoping here that the value returned by
Hits.id(int) is the "docnum" expected in
IndexReader.delete(int)
But the call to delete throws an IOException.
So, is there any way I can delete all the documents from
an Index that satisfy a general Query?
Thank you for any advice.
Bruce Cota,
Unicon, Inc.
---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-user-help@jakarta.apache.org
Re: Deleting documents that meet a query
Posted by Bruce Cota <br...@vivi.com>.
Thanks. I will restore that code and try to figure out why
it broke :) (Because my alternative solution was way uglier.)
Marie-Hélène Forget wrote:
>Hi,
>
>I confirm to you that delete( hits.id( i ) ) is ok.
>
>Hits.id( int ) returns the docnum that you need.
>
>MHF :)
>
>On Mon, 2003-06-09 at 12:11, Bruce Cota wrote:
>
>
>>I need to delete all the documents from an index that
>>satisfy a BooleanQuery.
>>
>>The only methods I can find (in IndexReader) for deleting
>>a document are delete(Term) and delete(int).
>>
>>I tried searching on my Query using IndexSearcher.search(),
>>iterating over each document in the returned Hits,
>>and then iterating over Hits deleting each document like this:
>>
>>for (int i=0; i<hits.length(); +++i) {
>> ireader.delete(hits.id(i));
>>}
>>
>>Hoping here that the value returned by
>>Hits.id(int) is the "docnum" expected in
>>IndexReader.delete(int)
>>
>>But the call to delete throws an IOException.
>>
>>So, is there any way I can delete all the documents from
>>an Index that satisfy a general Query?
>>
>>Thank you for any advice.
>>
>>Bruce Cota,
>>Unicon, Inc.
>>
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: lucene-user-help@jakarta.apache.org
>>
>>
>>
>>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: lucene-user-help@jakarta.apache.org
>
>
>
Re: Deleting documents that meet a query
Posted by Marie-Hélène Forget <mh...@logient.com>.
Hi,
I confirm to you that delete( hits.id( i ) ) is ok.
Hits.id( int ) returns the docnum that you need.
MHF :)
On Mon, 2003-06-09 at 12:11, Bruce Cota wrote:
> I need to delete all the documents from an index that
> satisfy a BooleanQuery.
>
> The only methods I can find (in IndexReader) for deleting
> a document are delete(Term) and delete(int).
>
> I tried searching on my Query using IndexSearcher.search(),
> iterating over each document in the returned Hits,
> and then iterating over Hits deleting each document like this:
>
> for (int i=0; i<hits.length(); +++i) {
> ireader.delete(hits.id(i));
> }
>
> Hoping here that the value returned by
> Hits.id(int) is the "docnum" expected in
> IndexReader.delete(int)
>
> But the call to delete throws an IOException.
>
> So, is there any way I can delete all the documents from
> an Index that satisfy a general Query?
>
> Thank you for any advice.
>
> Bruce Cota,
> Unicon, Inc.
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: lucene-user-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-user-help@jakarta.apache.org