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 je...@prasahewitt.ch on 2001/12/04 15:59:00 UTC

existing or not existing


Hi there,

I'm testing Lucene after reading a good article on it on JavaWorld.

Lucene seems quite simple and very powerful, but there's something I can't get.
The first time an application uses an index, this one doesn't exist yet, so the
boolean argument of the IndexWriter constructor must be true (creating a new
empty index). Next time the same app is started, I want to use the existing
index, the boolean argument must be false. Here is my question : how do I know
wether the index exists or not ??  Is there a way to create an IndexWriter on a
given index, creating it only if needed ?

It seems like a stupid question, I must have missed something...

Thanks


JCG



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: existing or not existing

Posted by David Spencer <da...@tropo.com>.
I think the 'create' flag really indicates whether it's ok
to *overwrite* the *possibly*existing* index.
Despite the tricky nuance it works great.

http://jakarta.apache.org/lucene/docs/api/org/apache/lucene/index/IndexWriter.html#IndexWriter(org.apache.lucene.store.Directory,%20org.apache.lucene.analysis.Analyzer,%20boolean)

jean-christian.gagne@prasahewitt.ch wrote:

> Hi there,
>
> I'm testing Lucene after reading a good article on it on JavaWorld.
>
> Lucene seems quite simple and very powerful, but there's something I can't get.
> The first time an application uses an index, this one doesn't exist yet, so the
> boolean argument of the IndexWriter constructor must be true (creating a new
> empty index). Next time the same app is started, I want to use the existing
> index, the boolean argument must be false. Here is my question : how do I know
> wether the index exists or not ??  Is there a way to create an IndexWriter on a
> given index, creating it only if needed ?
>
> It seems like a stupid question, I must have missed something...
>
> Thanks
>
> JCG
>
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>

--
http://www.tropo.com/



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: existing or not existing

Posted by Trevor Boicey <tb...@brit.ca>.
Ian Lea wrote:
> 
> Personally, I like to know when I'm creating an index
> so tend to have different code paths, or even different
> classes, for reading and writing indexes.  But how
> about creating the IndexWriter with flag set to false
> and catching the exception it will no doubt throw
> if the index doesn't exist, and reissuing the
> call with the flag set to true?

  This is what I do, but frankly it's a little scary.

  Basically, if your open fails for some other reason, it
blows away your index.

  In my application that's acceptable since my index is
pretty transient, but it's a bit iffy in a lot of situations.

  I think it would make sense to follow the "standard"
of, if that flag is true, to make the index if needed and
use it if it exists.

  The "false" flag could be used to trap exceptions if
the index doesn't exist, and allow the user to perform
other initializations.

  To simply clear the index completely should be another
mechanism that the user would call if they really wanted
to overwrite an index with a new one.

-- 
Trevor Boicey, P. Eng.
Ottawa, Canada, tboicey@brit.ca
ICQ #17432933 http://www.brit.ca/~tboicey/
"There will be no aggressive condiment passing in this house!" - Marge

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: existing or not existing

Posted by Ian Lea <ia...@blackwell.co.uk>.
Personally, I like to know when I'm creating an index
so tend to have different code paths, or even different
classes, for reading and writing indexes.  But how
about creating the IndexWriter with flag set to false
and catching the exception it will no doubt throw 
if the index doesn't exist, and reissuing the
call with the flag set to true?



--
Ian.
ian.lea@blackwell.co.uk


Otis Gospodnetic wrote:
> 
> You could try looking for a segments file in the index directory.
> If it exists, the index exists, else it does not.
> 
> Is there a better way?
> 
> Otis
> 
> --- jean-christian.gagne@prasahewitt.ch wrote:
> >
> >
> > Hi there,
> >
> > I'm testing Lucene after reading a good article on it on JavaWorld.
> >
> > Lucene seems quite simple and very powerful, but there's something I
> > can't get.
> > The first time an application uses an index, this one doesn't exist
> > yet, so the
> > boolean argument of the IndexWriter constructor must be true
> > (creating a new
> > empty index). Next time the same app is started, I want to use the
> > existing
> > index, the boolean argument must be false. Here is my question : how
> > do I know
> > wether the index exists or not ??  Is there a way to create an
> > IndexWriter on a
> > given index, creating it only if needed ?
> >
> > It seems like a stupid question, I must have missed something...
> >
> > Thanks

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: existing or not existing

Posted by Ype Kingma <yk...@xs4all.nl>.
Otis,

>You could try looking for a segments file in the index directory.
>If it exists, the index exists, else it does not.
>
>Is there a better way?

Simply create an indexreader and catch the IOException to handle the non
existing case.

Ype.


>Otis
>
>--- jean-christian.gagne@prasahewitt.ch wrote:
>>
>>
>> Hi there,
>>
>> I'm testing Lucene after reading a good article on it on JavaWorld.
>>
>> Lucene seems quite simple and very powerful, but there's something I
>> can't get.
>> The first time an application uses an index, this one doesn't exist
>> yet, so the
>> boolean argument of the IndexWriter constructor must be true
>> (creating a new
>> empty index). Next time the same app is started, I want to use the
>> existing
>> index, the boolean argument must be false. Here is my question : how
>> do I know
>> wether the index exists or not ??  Is there a way to create an
>> IndexWriter on a
>> given index, creating it only if needed ?
>>
>> It seems like a stupid question, I must have missed something...
>>
>> Thanks
>>
>>
>> JCG
>>
>>
>>
>> --
>> To unsubscribe, e-mail: 
>> <ma...@jakarta.apache.org>
>> For additional commands, e-mail:
>> <ma...@jakarta.apache.org>
>>
>
>
>__________________________________________________
>Do You Yahoo!?
>Buy the perfect holiday gifts at Yahoo! Shopping.
>http://shopping.yahoo.com
>
>--
>To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
>For additional commands, e-mail: <ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: existing or not existing

Posted by Otis Gospodnetic <ot...@yahoo.com>.
You could try looking for a segments file in the index directory.
If it exists, the index exists, else it does not.

Is there a better way?

Otis

--- jean-christian.gagne@prasahewitt.ch wrote:
> 
> 
> Hi there,
> 
> I'm testing Lucene after reading a good article on it on JavaWorld.
> 
> Lucene seems quite simple and very powerful, but there's something I
> can't get.
> The first time an application uses an index, this one doesn't exist
> yet, so the
> boolean argument of the IndexWriter constructor must be true
> (creating a new
> empty index). Next time the same app is started, I want to use the
> existing
> index, the boolean argument must be false. Here is my question : how
> do I know
> wether the index exists or not ??  Is there a way to create an
> IndexWriter on a
> given index, creating it only if needed ?
> 
> It seems like a stupid question, I must have missed something...
> 
> Thanks
> 
> 
> JCG
> 
> 
> 
> --
> To unsubscribe, e-mail:  
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> 


__________________________________________________
Do You Yahoo!?
Buy the perfect holiday gifts at Yahoo! Shopping.
http://shopping.yahoo.com

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>