mirror of https://github.com/apache/lucene.git
LUCENE-5242: DirectoryTaxonomyWriter.replaceTaxonomy did not fully reset its state
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1525894 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
89eb9397c7
commit
84f6e500b3
|
@ -85,6 +85,10 @@ Bug Fixes
|
||||||
* LUCENE-4998: Fixed a few places to pass IOContext.READONCE instead
|
* LUCENE-4998: Fixed a few places to pass IOContext.READONCE instead
|
||||||
of IOContext.READ (Shikhar Bhushan via Mike McCandless)
|
of IOContext.READ (Shikhar Bhushan via Mike McCandless)
|
||||||
|
|
||||||
|
* LUCENE-5242: DirectoryTaxonomyWriter.replaceTaxonomy did not fully reset
|
||||||
|
its state, which could result in exceptions being thrown, as well as
|
||||||
|
incorrect ordinals returned from getParent. (Shai Erera)
|
||||||
|
|
||||||
API Changes:
|
API Changes:
|
||||||
|
|
||||||
* LUCENE-5222: Add SortField.needsScores(). Previously it was not possible
|
* LUCENE-5222: Add SortField.needsScores(). Previously it was not possible
|
||||||
|
|
|
@ -981,12 +981,14 @@ public class DirectoryTaxonomyWriter implements TaxonomyWriter {
|
||||||
initReaderManager(); // ensure that it's initialized
|
initReaderManager(); // ensure that it's initialized
|
||||||
refreshReaderManager();
|
refreshReaderManager();
|
||||||
nextID = indexWriter.maxDoc();
|
nextID = indexWriter.maxDoc();
|
||||||
|
taxoArrays = null; // must nullify so that it's re-computed next time it's needed
|
||||||
|
|
||||||
// need to clear the cache, so that addCategory won't accidentally return
|
// need to clear the cache, so that addCategory won't accidentally return
|
||||||
// old categories that are in the cache.
|
// old categories that are in the cache.
|
||||||
cache.clear();
|
cache.clear();
|
||||||
cacheIsComplete = false;
|
cacheIsComplete = false;
|
||||||
shouldFillCache = true;
|
shouldFillCache = true;
|
||||||
|
cacheMisses.set(0);
|
||||||
|
|
||||||
// update indexEpoch as a taxonomy replace is just like it has be recreated
|
// update indexEpoch as a taxonomy replace is just like it has be recreated
|
||||||
++indexEpoch;
|
++indexEpoch;
|
||||||
|
|
|
@ -469,4 +469,27 @@ public class TestDirectoryTaxonomyWriter extends FacetTestCase {
|
||||||
|
|
||||||
IOUtils.close(indexDir, taxoDir);
|
IOUtils.close(indexDir, taxoDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testReplaceTaxoWithLargeTaxonomy() throws Exception {
|
||||||
|
Directory srcTaxoDir = newDirectory(), targetTaxoDir = newDirectory();
|
||||||
|
|
||||||
|
// build source, large, taxonomy
|
||||||
|
DirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(srcTaxoDir);
|
||||||
|
int ord = taxoWriter.addCategory(new CategoryPath("A/1/1/1/1/1/1", '/'));
|
||||||
|
taxoWriter.close();
|
||||||
|
|
||||||
|
taxoWriter = new DirectoryTaxonomyWriter(targetTaxoDir);
|
||||||
|
int ordinal = taxoWriter.addCategory(new CategoryPath("B/1", '/'));
|
||||||
|
assertEquals(1, taxoWriter.getParent(ordinal)); // call getParent to initialize taxoArrays
|
||||||
|
taxoWriter.commit();
|
||||||
|
|
||||||
|
taxoWriter.replaceTaxonomy(srcTaxoDir);
|
||||||
|
assertEquals(ord - 1, taxoWriter.getParent(ord));
|
||||||
|
taxoWriter.close();
|
||||||
|
|
||||||
|
srcTaxoDir.close();
|
||||||
|
targetTaxoDir.close();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue