lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Lars Hammer" <ham...@dezide.com>
Subject Re: IndexReader.delete( term ) bug?
Date Tue, 16 Sep 2003 14:34:43 GMT
Sorry I should have posted som more code the first time around, here is the
whole method that i Use. I make a search for the term first to check if any
documents exists :

private void deleteModelTree( String modelTreeFileID, pathToIndex )
    {
        try
        {
            IndexReader ir = IndexReader.open( pathToIndex );

            Term term = new Term( "modelTreeFileID", modelTreeFileID );

            TermQuery query = new TermQuery( term );
            Searcher searcher = new IndexSearcher( pathToIndex );
            Hits hits = searcher.search( query );

            if( hits.length() != 0 )
            {
                ir.delete( term );
            }

            ir.close();
        }
        catch( Exception e )
        {
            e.printStackTrace();
         }
    }

I catch all Execptions to see if anything goes wrong and so far no
excpetions are thrown ....

-thanks in advance!

/Lars Hammer





> Lars,
>
> The code looks fine.  However, you are not showing how you deal with
> any possible exceptions (IOExceptions, for instance), so it is possible
> that you are ignoring exceptions.
> Thata delete(Term) method returns an int, so you could also capture
> that and see what its value is.
> I assume that you are also closing your IndexReader instance...
>
> Otis
>
>
> --- Lars Hammer <hammer@dezide.com> wrote:
> > Hello
> >
> > I am trying to delete all docs in my index containing a field with a
> > given value. The API says that the delete( term ) method in
> > IndexReader can do that for me. The problem is that it doesn't seem
> > to work properly. When i apply the delete( term ) method to docs
> > where i know that only one document exists with the given ID, the
> > document is deleted as it should be, but when there are more
> > documents with the same ID, nothing happens.
> > It should be said that alle documents have a unique ID and some
> > documents furthermore have another ID field called modelTreeFileID,
> > which indicates membership to a group of documents.
> >
> > This little code snippet is how I am doing it :
> >
> > IndexReader ir = IndexReader.open( pathToIndex );
> > Term term = new Term( "modelTreeFileID", "324i28383gvvb" );
> > ir.delete( term );
> >
> >
> > if only one document was found with the value 324i28383gvvb was
> > found, it is deleted, but if more documents were found they are not
> > :-(
> >
> > Is this a bug in IndexReader or am i doing something wrong.
> >
> > Any help is appreciated.
> >
> > /Lars Hammer
> >
> > http://www.dezide.com
> >
> >
> >
>
>
> __________________________________
> Do you Yahoo!?
> Yahoo! SiteBuilder - Free, easy-to-use web site design software
> http://sitebuilder.yahoo.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: lucene-user-help@jakarta.apache.org
>
>
>



Mime
View raw message