mirror of https://github.com/apache/lucene.git
LUCENE-4898: openIfChange now allows targeting an IndexCommit from an NRT reader
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1464437 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
8b573c413d
commit
c18676ed4f
|
@ -160,6 +160,10 @@ New Features
|
||||||
* LUCENE-4645: Added support for the "Contains" spatial predicate for
|
* LUCENE-4645: Added support for the "Contains" spatial predicate for
|
||||||
RecursivePrefixTreeStrategy. (David Smiley)
|
RecursivePrefixTreeStrategy. (David Smiley)
|
||||||
|
|
||||||
|
* LUCENE-4898: DirectoryReader.openIfChanged now allows opening a reader
|
||||||
|
on an IndexCommit starting from a near-real-time reader (previously
|
||||||
|
this would throw IllegalArgumentException). (Mike McCandless)
|
||||||
|
|
||||||
Optimizations
|
Optimizations
|
||||||
|
|
||||||
* LUCENE-4839: SorterTemplate.merge can now be overridden in order to replace
|
* LUCENE-4839: SorterTemplate.merge can now be overridden in order to replace
|
||||||
|
|
|
@ -260,7 +260,7 @@ final class StandardDirectoryReader extends DirectoryReader {
|
||||||
|
|
||||||
private DirectoryReader doOpenFromWriter(IndexCommit commit) throws IOException {
|
private DirectoryReader doOpenFromWriter(IndexCommit commit) throws IOException {
|
||||||
if (commit != null) {
|
if (commit != null) {
|
||||||
throw new IllegalArgumentException("a reader obtained from IndexWriter.getReader() cannot currently accept a commit");
|
return doOpenFromCommit(commit);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (writer.nrtIsCurrent(segmentInfos)) {
|
if (writer.nrtIsCurrent(segmentInfos)) {
|
||||||
|
@ -293,6 +293,10 @@ final class StandardDirectoryReader extends DirectoryReader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return doOpenFromCommit(commit);
|
||||||
|
}
|
||||||
|
|
||||||
|
private DirectoryReader doOpenFromCommit(IndexCommit commit) throws IOException {
|
||||||
return (DirectoryReader) new SegmentInfos.FindSegmentsFile(directory) {
|
return (DirectoryReader) new SegmentInfos.FindSegmentsFile(directory) {
|
||||||
@Override
|
@Override
|
||||||
protected Object doBody(String segmentFileName) throws IOException {
|
protected Object doBody(String segmentFileName) throws IOException {
|
||||||
|
|
|
@ -594,4 +594,28 @@ public class TestDirectoryReaderReopen extends LuceneTestCase {
|
||||||
r.close();
|
r.close();
|
||||||
dir.close();
|
dir.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testOpenIfChangedNRTToCommit() throws Exception {
|
||||||
|
Directory dir = newDirectory();
|
||||||
|
|
||||||
|
// Can't use RIW because it randomly commits:
|
||||||
|
IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())));
|
||||||
|
Document doc = new Document();
|
||||||
|
doc.add(newStringField("field", "value", Field.Store.NO));
|
||||||
|
w.addDocument(doc);
|
||||||
|
w.commit();
|
||||||
|
List<IndexCommit> commits = DirectoryReader.listCommits(dir);
|
||||||
|
assertEquals(1, commits.size());
|
||||||
|
w.addDocument(doc);
|
||||||
|
DirectoryReader r = DirectoryReader.open(w, true);
|
||||||
|
|
||||||
|
assertEquals(2, r.numDocs());
|
||||||
|
IndexReader r2 = DirectoryReader.openIfChanged(r, commits.get(0));
|
||||||
|
assertNotNull(r2);
|
||||||
|
r.close();
|
||||||
|
assertEquals(1, r2.numDocs());
|
||||||
|
w.close();
|
||||||
|
r2.close();
|
||||||
|
dir.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue