mirror of https://github.com/apache/lucene.git
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:
parent
52ab4cb9a8
commit
23de4c514b
|
@ -76,14 +76,13 @@ import org.apache.lucene.facet.taxonomy.writercache.lru.LruTaxonomyWriterCache;
|
||||||
* algorithm used.
|
* algorithm used.
|
||||||
* <p>
|
* <p>
|
||||||
* This class offers some hooks for extending classes to control the
|
* This class offers some hooks for extending classes to control the
|
||||||
* {@link IndexWriter} instance that is used. See {@link #openIndexWriter} and
|
* {@link IndexWriter} instance that is used. See {@link #openIndexWriter}.
|
||||||
* {@link #closeIndexWriter()} .
|
|
||||||
*
|
*
|
||||||
* @lucene.experimental
|
* @lucene.experimental
|
||||||
*/
|
*/
|
||||||
public class DirectoryTaxonomyWriter implements TaxonomyWriter {
|
public class DirectoryTaxonomyWriter implements TaxonomyWriter {
|
||||||
|
|
||||||
protected IndexWriter indexWriter;
|
private IndexWriter indexWriter;
|
||||||
private int nextID;
|
private int nextID;
|
||||||
private char delimiter = Consts.DEFAULT_DELIMITER;
|
private char delimiter = Consts.DEFAULT_DELIMITER;
|
||||||
private SinglePositionTokenStream parentStream = new SinglePositionTokenStream(Consts.PAYLOAD_PARENT);
|
private SinglePositionTokenStream parentStream = new SinglePositionTokenStream(Consts.PAYLOAD_PARENT);
|
||||||
|
@ -171,7 +170,7 @@ public class DirectoryTaxonomyWriter implements TaxonomyWriter {
|
||||||
throws CorruptIndexException, LockObtainFailedException,
|
throws CorruptIndexException, LockObtainFailedException,
|
||||||
IOException {
|
IOException {
|
||||||
|
|
||||||
openIndexWriter(directory, openMode);
|
indexWriter = openIndexWriter(directory, openMode);
|
||||||
reader = null;
|
reader = null;
|
||||||
|
|
||||||
FieldType ft = new FieldType(TextField.TYPE_UNSTORED);
|
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
|
* {@link org.apache.lucene.index.IndexDeletionPolicy}, different RAM size
|
||||||
* etc.<br>
|
* etc.<br>
|
||||||
* <b>NOTE:</b> the instance this method returns will be closed upon calling
|
* <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
|
* to {@link #close()}.
|
||||||
* override {@link #closeIndexWriter()}.
|
|
||||||
*
|
*
|
||||||
* @param directory
|
* @param directory
|
||||||
* the {@link Directory} on top of which an {@link IndexWriter}
|
* the {@link Directory} on top of which an {@link IndexWriter}
|
||||||
|
@ -221,7 +219,7 @@ public class DirectoryTaxonomyWriter implements TaxonomyWriter {
|
||||||
* @param openMode
|
* @param openMode
|
||||||
* see {@link OpenMode}
|
* see {@link OpenMode}
|
||||||
*/
|
*/
|
||||||
protected void openIndexWriter(Directory directory, OpenMode openMode)
|
protected IndexWriter openIndexWriter(Directory directory, OpenMode openMode)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
// Make sure we use a MergePolicy which merges segments in-order and thus
|
// 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
|
// 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,
|
IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_40,
|
||||||
new KeywordAnalyzer()).setOpenMode(openMode).setMergePolicy(
|
new KeywordAnalyzer()).setOpenMode(openMode).setMergePolicy(
|
||||||
new LogByteSizeMergePolicy());
|
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
|
// Currently overridden by a unit test that verifies that every index we open
|
||||||
|
@ -279,7 +277,11 @@ public class DirectoryTaxonomyWriter implements TaxonomyWriter {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public synchronized void close() throws CorruptIndexException, IOException {
|
public synchronized void close() throws CorruptIndexException, IOException {
|
||||||
closeIndexWriter();
|
if (indexWriter != null) {
|
||||||
|
indexWriter.close();
|
||||||
|
indexWriter = null;
|
||||||
|
}
|
||||||
|
|
||||||
closeResources();
|
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,
|
* 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
|
* returning the category's ordinal, or a negative number in case the
|
||||||
|
|
|
@ -130,8 +130,8 @@ public class TestIndexClose extends LuceneTestCase {
|
||||||
return new InstrumentedIndexReader(super.openReader());
|
return new InstrumentedIndexReader(super.openReader());
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
protected void openIndexWriter (Directory directory, OpenMode openMode) throws IOException {
|
protected IndexWriter openIndexWriter (Directory directory, OpenMode openMode) throws IOException {
|
||||||
indexWriter = new InstrumentedIndexWriter(directory,
|
return new InstrumentedIndexWriter(directory,
|
||||||
newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random, MockTokenizer.KEYWORD, false))
|
newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random, MockTokenizer.KEYWORD, false))
|
||||||
.setOpenMode(openMode));
|
.setOpenMode(openMode));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue