lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kadlabalu, Hareesh" <hareesh.kadlab...@fatwire.com>
Subject RE: Indexes auto creation
Date Mon, 13 Jun 2005 16:37:42 GMT
I ran into a related problem; when I create an IndexWriter with a
FSDirectory created with create=true, an existing index would somehow get
corrupted (Luke would come back with a message saying that the index is
corrupt). IndexWriter will tell you that it has 0 documents at that stage
even though the index had several documents prior to creating this instance
of IndexWriter. It is interesting that the sizes of the index files remain
same. It seems that, creating an IndexWriter with a FSDirectory with
create=true on an existing index somehow corrupts the index. 

I figured there must be a bug here (I am using 1.4.3), has anyone run into
this? I had to fall back on an inelegant solution. First check if a
directory exists, if not create a dummy index and close it. After that
always create IndexWriter with create=false.

Thanks
-Hareesh




-----Original Message-----
From: Stephane Bailliez [mailto:sbailliez@apache.org] 
Sent: Monday, June 13, 2005 11:48 AM
To: java-user@lucene.apache.org
Subject: Indexes auto creation

I have a very stupid question that puzzles me so far in the API. (I'm 
using Lucene 1.4.3)

There is a boolean flag over the creation of the Directory which is 
basically: use it as is or delete the storage area

Same for the index, the IndexWriter use a flag 'use the existing or 
create a new one'.

If you're creating an indexwriter with 'create' set to false. It could 
blow up with an IOException because the index does not exist.
But it could also blow up for other reasons with an IOException..which 
does not help much in identifying the source problem.


What I would like to is something like: if the index does not exist, 
then create one for me, otherwise use it.

I could do that with something like

try {
    writer = new IndexWriter(directory, analyzer, false)
} catch (IOException e){
     writer = new IndexWriter(directory, analyzer, true);
}

but this is not exactly true, and I could possibly delete an existing 
index if an IOException happens which is not due to a non-existing index.

Apparently a way to check there is an existing index would be (based on 
the Lucene source code) to do something like:

try {
    writer = new IndexWriter(directory, analyzer, false)
} catch (IOException e){
    if ( !directory.exists(IndexFileNames.SEGMENTS) ) {
        // the index really does not exists, so create it
        writer = new IndexWriter(directory, analyzer, true);
    } else {
        throw e;
    }
}

Is this correct or is there something even more simpler that I'm missing ?

Ideally I would have liked a subclassed IOException on the IndexWriter 
to differentiate the cases (like FileNotFoundException for example) but 
maybe I'm missing some trivial thing.


---------------------------------------------------------------------
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


Mime
View raw message