lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Uwe Schindler <...@thetaphi.de>
Subject Re: Lucene 4.0-BETA : MultiReader isCurrent openIfChanged
Date Sun, 26 Aug 2012 18:59:50 GMT
1. getRefCount()
2. No



Mossaab Bagdouri <bagdouri_mossaab@yahoo.fr> schrieb:

>Hi,
>
>I've just migrated my webapp from Lucene 3.6 to 4.0-BETA. My 2 indexes
>are
>updated every couple of minutes by a batch. The webapp searcher needs
>to
>get refreshed whenever this happens. In 3.6, I was doing it this way:
>
>private IndexSearcher getIndexSearcher() {
>        try {
>            if (is == null || !is.getIndexReader().isCurrent()) {
>                if (is != null) {
>                    is.close();
>                }
>                IndexReader readers[] = new IndexReader[2];
>                for (int i = 0; i < 2; i++) {
>                 readers[i] = IndexReader.open(MyFSDirectories.get(i));
>                }
>                is = new IndexSearcher(new MultiReader(readers));
>            }
>        } catch (Exception e) {
>            e.printStackTrace();
>        }
>        return is;
>    }
>
>Now that the API changed in 4.0-BETA. I'm doing it this odd way:
>
>private IndexSearcher getIndexSearcher() {
>        try {
>            boolean refresh = false;
>            if (is == null) {
>                refresh = true;
>            } else {
>                MultiReader ir = ((MultiReader) is.getIndexReader());
>                List<DirectoryReader> list = (List<DirectoryReader>)
>ir.getSequentialSubReaders();
>                try {
>                    if (!list.get(0).isCurrent() ||
>!list.get(1).isCurrent()) {
>                        refresh = true;
>                    }
>                } catch (Exception e) {
>                    e.printStackTrace();
>                    refresh = true;
>                }
>
>            }
>            if (refresh) {
>                if (is != null) {
>                    ((MultiReader) is.getIndexReader()).close();
>                }
>                DirectoryReader readers[] = new DirectoryReader[2];
>                for (int i = 0; i < 2; i++) {
>                    readers[i] =
>DirectoryReader.open(MyFSDirectories.get(i));
>                }
>                is = new IndexSearcher(new MultiReader(readers));
>            }
>        } catch (Exception e) {
>            e.printStackTrace();
>        }
>        return is;
>    }
>
>The problem is that sometimes isCurrent() returns an exception
>indicating
>that the underlying IndexReader is closed.
>
>My questions are:
>1. How can I verify of the IndexReader is open before calling
>isCurrent();
>2. Is there a better way to deal with MultiReaders?
>
>Regards,
>Mossaab

--
Uwe Schindler
H.-H.-Meier-Allee 63, 28213 Bremen
http://www.thetaphi.de
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message