LUCENE-3556: make DirectoryTaxonomyWriter's indexWriter private

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1196982 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Shai Erera 2011-11-03 07:41:40 +00:00
parent 52ab4cb9a8
commit 23de4c514b
2 changed files with 13 additions and 22 deletions

View File

@ -76,14 +76,13 @@ import org.apache.lucene.facet.taxonomy.writercache.lru.LruTaxonomyWriterCache;
* algorithm used.
* <p>
* This class offers some hooks for extending classes to control the
* {@link IndexWriter} instance that is used. See {@link #openIndexWriter} and
* {@link #closeIndexWriter()} .
* {@link IndexWriter} instance that is used. See {@link #openIndexWriter}.
*
* @lucene.experimental
*/
public class DirectoryTaxonomyWriter implements TaxonomyWriter {
protected IndexWriter indexWriter;
private IndexWriter indexWriter;
private int nextID;
private char delimiter = Consts.DEFAULT_DELIMITER;
private SinglePositionTokenStream parentStream = new SinglePositionTokenStream(Consts.PAYLOAD_PARENT);
@ -171,7 +170,7 @@ public class DirectoryTaxonomyWriter implements TaxonomyWriter {
throws CorruptIndexException, LockObtainFailedException,
IOException {
openIndexWriter(directory, openMode);
indexWriter = openIndexWriter(directory, openMode);
reader = null;
FieldType ft = new FieldType(TextField.TYPE_UNSTORED);
@ -212,8 +211,7 @@ public class DirectoryTaxonomyWriter implements TaxonomyWriter {
* {@link org.apache.lucene.index.IndexDeletionPolicy}, different RAM size
* etc.<br>
* <b>NOTE:</b> the instance this method returns will be closed upon calling
* to {@link #close()}. If you wish to do something different, you should
* override {@link #closeIndexWriter()}.
* to {@link #close()}.
*
* @param directory
* the {@link Directory} on top of which an {@link IndexWriter}
@ -221,7 +219,7 @@ public class DirectoryTaxonomyWriter implements TaxonomyWriter {
* @param openMode
* see {@link OpenMode}
*/
protected void openIndexWriter(Directory directory, OpenMode openMode)
protected IndexWriter openIndexWriter(Directory directory, OpenMode openMode)
throws IOException {
// Make sure we use a MergePolicy which merges segments in-order and thus
// keeps the doc IDs ordered as well (this is crucial for the taxonomy
@ -229,7 +227,7 @@ public class DirectoryTaxonomyWriter implements TaxonomyWriter {
IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_40,
new KeywordAnalyzer()).setOpenMode(openMode).setMergePolicy(
new LogByteSizeMergePolicy());
indexWriter = new IndexWriter(directory, config);
return new IndexWriter(directory, config);
}
// Currently overridden by a unit test that verifies that every index we open
@ -279,7 +277,11 @@ public class DirectoryTaxonomyWriter implements TaxonomyWriter {
*/
@Override
public synchronized void close() throws CorruptIndexException, IOException {
closeIndexWriter();
if (indexWriter != null) {
indexWriter.close();
indexWriter = null;
}
closeResources();
}
@ -312,17 +314,6 @@ public class DirectoryTaxonomyWriter implements TaxonomyWriter {
}
}
/**
* A hook for extending classes to control closing the {@link IndexWriter}
* returned by {@link #openIndexWriter}.
*/
protected void closeIndexWriter() throws CorruptIndexException, IOException {
if (indexWriter != null) {
indexWriter.close();
indexWriter = null;
}
}
/**
* Look up the given category in the cache and/or the on-disk storage,
* returning the category's ordinal, or a negative number in case the

View File

@ -130,8 +130,8 @@ public class TestIndexClose extends LuceneTestCase {
return new InstrumentedIndexReader(super.openReader());
}
@Override
protected void openIndexWriter (Directory directory, OpenMode openMode) throws IOException {
indexWriter = new InstrumentedIndexWriter(directory,
protected IndexWriter openIndexWriter (Directory directory, OpenMode openMode) throws IOException {
return new InstrumentedIndexWriter(directory,
newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random, MockTokenizer.KEYWORD, false))
.setOpenMode(openMode));
}