lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Anshum <ansh...@gmail.com>
Subject Re: about RAMDirectory based B/S plantform problem
Date Tue, 17 Aug 2010 06:17:24 GMT
Hi Hilly,
Seems like you are trying to use an already closed writer. Could you keep
the writer open and continue writing to the same indexdirectory using a
'shared' indexwriter 'instance'. To put it as pseudo code
Something like a singleton/static indexwriter instance.. almost.
--
Open indexwriter and keep open.

accept data from thread1 and write to index using indexwriter [DO NOT CLOSE
THE INDEXWRITER HERE]
accept data from thread2 and write to index using indexwriter [DO NOT CLOSE
THE INDEXWRITER HERE]
.
.

Close IndexWriter
--

Would this work/be implementable for your application?

--
Anshum Gupta
http://ai-cafe.blogspot.com


2010/8/17 xiaoyan Zheng <hillyzheng@gmail.com>

> the question is like this:
>
> when one user is using IndexWirter.addDocument(doc), and another user has
> already finished adding part and have closed IndexWirter, then, the first
> user embraces the error "ERROR: this IndexWriter is closed", cause both of
> them creat the IndexWriter based on RAM by the same sever.
>
> I followed the error to the lucene source, there is ensureOpen(); in
> IndexWirter.addDocument( ), and the error is there,
>
> protected synchronized final void ensureOpen(boolean includePendingClose)
> throws AlreadyClosedException {
>    if (!isOpen(includePendingClose)) {
>      throw new AlreadyClosedException("this IndexWriter is closed");
>    }
>  }
> how to avoid these kind of error? could lucene check this kind of sitation
> by itself?
>
>
> 2010/8/17 xiaoyan Zheng <hillyzheng@gmail.com>
>
> >
> >  about RAMDirectory based B/S plantform problem
> >
> > hello, I just start to use lucene and become confused about RAMDirectory
> > based lucene index establishment, the problem is one user use this RAM to
> > establish index is ok, but, when it comes to multi user, the results is
> not
> > correct. when i use synchronized{ writer.writeIndex (...)}, all go
> alright.
> > but users have to wait. i mean, is that RAM can only be used in single
> > thread, esp. writing the index? how to solve it in a B/S plantform?
> >
> > ============================
> > the detailed test code is like these, very simple, just use jsp:
> >
> >
> > RAMDirectory idx=new RAMDirectory();
> >
> > LuceneIndexWriterImpl writer=null;
> > writer=LuceneIndexWriterImpl.getInstance();
> >
> > //RAM-based lucene index establishment
> >
> > synchronized(wirter){
> > //if no synchronized the result is not correct
> > writer.writeIndex(idx);
> >
> > }
> >
> > LuceneIndexReaderImpl luceneReader=new LuceneIndexReaderImpl(idx);
> > ....
> > ....
> >
> > out.println("****");
> > for(Integer id :documents.keySet())
> > out.println(id);
> > out.println("****");
> >
> > ===========================
> > result:
> > if only one user: out put is correct 7,3
> >
> > but two users(if no synchronized): out put may be 0,0 and 4, 0 or other
> > unexpected result.
> >
> >
> > Regards
> > Hilly
> >
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message