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 "-\" Goople ;" <go...@gmail.com> on 2014/06/30 07:36:48 UTC

What is the recomendation for reopening MultiReader in Lucene 4.x

Hi,

I'm migrating from Lucene 3.6.1 to 4.3.0.
I used to have indexer for data in each month and wrapped with one
*MultiReader*.
Behind the multireader, I have ScheduledExecutorService thread keep
reopening the sub-readers in certain interval time. And I got one searcher
for the multireader.

IndexSearcher mySearcher = new IndexSearcher(new *MultiReader*(irs));
// irs is an array of non-NRT index readers.

I have been used the following code to reopen the multireader for my
searcher in Lucen3.6 (which is now not valid for 4.x).

*IndexReader newIr =
IndexReader.openIfChanged(mySearcher.getIndexReader());*
if (newIr != null) {
IndexSearcher oldSearcher = mySearcher;
 IndexSearcher newSearcher = new IndexSearcher(newIr);
 mySearcher= newSearcher;
oldSearcher.getIndexReader().decRef();
}

After migration, I have to change from* IndexReader.openIfChanged* to*
DirectoryReader.openIfChanged.*
So I did change it to something like the following code.. but it failed
because MultiReader cannot be casted to DirectoryReader.

DirectoryReader newIr = DirectoryReader.openIfChanged((DirectoryReader)
mySearcher.getIndexReader());

Do you have any suggestion on doing this in the right way?

Thanks in advance. :)
Pannapat C.

RE: What is the recomendation for reopening MultiReader in Lucene 4.x

Posted by Uwe Schindler <uw...@thetaphi.de>.
Hi,

You have to reopen all the underlying DirectoryReaders and then build a new MultiReader. MultiReader has no idea about commit points and therefore cannot reopen. The reopen of MultiReader worked for most cases in 3.6, but it was just buggy.
In any case: I would use ReaderManager to keep the IndexReaders of your subindexes up-to date (for each subindex) and after that create a new MultiReader and IndexSearcher. MultiReader and IndexSearcher are just wrapper objects that are cheap to create.

Uwe

-----
Uwe Schindler
H.-H.-Meier-Allee 63, D-28213 Bremen
http://www.thetaphi.de
eMail: uwe@thetaphi.de


> -----Original Message-----
> From: -" Goople ; [mailto:goooople@gmail.com]
> Sent: Monday, June 30, 2014 7:37 AM
> To: java-user@lucene.apache.org
> Subject: What is the recomendation for reopening MultiReader in Lucene 4.x
> 
> Hi,
> 
> I'm migrating from Lucene 3.6.1 to 4.3.0.
> I used to have indexer for data in each month and wrapped with one
> *MultiReader*.
> Behind the multireader, I have ScheduledExecutorService thread keep
> reopening the sub-readers in certain interval time. And I got one searcher for
> the multireader.
> 
> IndexSearcher mySearcher = new IndexSearcher(new *MultiReader*(irs));
> // irs is an array of non-NRT index readers.
> 
> I have been used the following code to reopen the multireader for my
> searcher in Lucen3.6 (which is now not valid for 4.x).
> 
> *IndexReader newIr =
> IndexReader.openIfChanged(mySearcher.getIndexReader());*
> if (newIr != null) {
> IndexSearcher oldSearcher = mySearcher;
>  IndexSearcher newSearcher = new IndexSearcher(newIr);  mySearcher=
> newSearcher; oldSearcher.getIndexReader().decRef();
> }
> 
> After migration, I have to change from* IndexReader.openIfChanged* to*
> DirectoryReader.openIfChanged.*
> So I did change it to something like the following code.. but it failed because
> MultiReader cannot be casted to DirectoryReader.
> 
> DirectoryReader newIr = DirectoryReader.openIfChanged((DirectoryReader)
> mySearcher.getIndexReader());
> 
> Do you have any suggestion on doing this in the right way?
> 
> Thanks in advance. :)
> Pannapat C.


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org