Hi Dick,

I agree with you. Now I cannot understand why your
original code didn't work.
If you find the answer, please let me know!

regrads,

Koji


> -----Original Message-----
> From: Dick de Jong [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, January 10, 2006 6:41 PM
> To: java-user@lucene.apache.org
> Subject: Re: Basic question on opening 2 IndexWriters on same
> Directory - I do not get IOException ...
>
>
> Hi Koji,
>
> I might not agree with you ... I did the following: I create new function
> which invokes FSDirectory.getDirectory(dir,true) twice . The result I
> compare (fs1==fs2). In my situation the (fs1==fs2) = true. So even in my
> situation, i have two references to the <b>same</b> Directory object.
>
> If I look in the FSDirectory constructor, this is also what happens. The
> FSDirectory.getDirectory(path,create) method invokese the
> FSDirectory.getDirectory(file, create) method and this checks the
> hashtable
> DIRECTORIES whether an object is already created for that
> directory. If so,
> it returns the existing reference, if not it creates a new
> directory object.
>
> So, I still think the difference is in the closeDir parameter difference
> (true/false).
>
> Do you agree with me sofar?
>
> New function added to java class:
>     private void openDirectoryTwiceAndCompareObjects()
>     {
>         try
>         {
>             Directory fs1 = FSDirectory.getDirectory(this.indexDir,
> true);
>             Directory fs2 = FSDirectory.getDirectory(this.indexDir, true);
>             if (fs1 == fs2)    {
>                 System.out.println("Two references to identical object");
>             }
>             else {
>                 System.out.println("Two different directory objects");
>             }
>         }
>         catch (IOException e)
>         {
>             System.out.println("Error in creating directory : " +
> e.getMessage());
>         }
>     }
>
> And change main to invoke this method:
>     public static void main(String[] args)
>     {
>         TestIndexWriter tw = new TestIndexWriter();
>         tw.openDirectoryTwiceAndCompareObjects();
>         //tw.testOpenIndexWriters(true, true);
>         //tw.testOpenIndexWriters(true, false);
>     }
>
>
>
>
>
>
>
> On 1/10/06, Koji Sekiguchi <[EMAIL PROTECTED]> wrote:
> >
> > Hi Dick,
> >
> > > I only see one difference in the constructor of the IndexWriter class:
> > > "closeDir" is 'true' in my scenario and 'false' in your scenario. What
> > is
> > > reason for this difference? And if there is a valid reason,
> it might be
> > > useful to add this to the javaDoc of the IndexWriter class.
> >
> > The important difference is:
> >
> > > >     private Directory getDirectory() throws IOException {
> > > >         if( directory == null ){
> > > >             directory = FSDirectory.getDirectory( indexDir, true );
> > > >         }
> > > >         return directory;
> > > >     }
> >
> > this method instantiates FSDirectory object only once.
> > But in your original code, calling IndexWriter( String,Analyzer,boolean)
> > version with create=true:
> >
> > >            public IndexWriter(String path, Analyzer a, boolean create)
> > > throws IOException {
> > >                   this(FSDirectory.getDirectory(path, create), a,
> > create,
> > > true);
> > >            }
> >
> > it always makes new FSDirectory object.
> >
> > regards,
> >
> > Koji
> >
> >
> >
> >
> >
>



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to