From acefe212c14a916c67d0af90899ece7c2eb92a10 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Sun, 29 Jan 2012 16:34:57 +0000 Subject: [PATCH] LUCENE-2858: fix modules facet (partially) git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene2858@1237330 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/lucene/facet/search/FacetsCollector.java | 2 +- .../apache/lucene/facet/search/ScoredDocIdCollector.java | 2 +- .../taxonomy/directory/DirectoryTaxonomyReader.java | 7 ++++--- .../taxonomy/directory/DirectoryTaxonomyWriter.java | 9 +++++---- .../src/test/org/apache/lucene/facet/FacetTestUtils.java | 3 ++- .../lucene/facet/search/TestTotalFacetCountsCache.java | 3 ++- .../taxonomy/directory/TestDirectoryTaxonomyWriter.java | 7 ++++--- 7 files changed, 19 insertions(+), 14 deletions(-) diff --git a/modules/facet/src/java/org/apache/lucene/facet/search/FacetsCollector.java b/modules/facet/src/java/org/apache/lucene/facet/search/FacetsCollector.java index af3a57a62a7..aae81386470 100644 --- a/modules/facet/src/java/org/apache/lucene/facet/search/FacetsCollector.java +++ b/modules/facet/src/java/org/apache/lucene/facet/search/FacetsCollector.java @@ -4,7 +4,7 @@ import java.io.IOException; import java.util.List; import org.apache.lucene.index.IndexReader; -import org.apache.lucene.index.IndexReader.AtomicReaderContext; +import org.apache.lucene.index.AtomicIndexReader.AtomicReaderContext; import org.apache.lucene.search.Collector; import org.apache.lucene.search.Scorer; diff --git a/modules/facet/src/java/org/apache/lucene/facet/search/ScoredDocIdCollector.java b/modules/facet/src/java/org/apache/lucene/facet/search/ScoredDocIdCollector.java index 43fdbf14926..38225d55f3c 100644 --- a/modules/facet/src/java/org/apache/lucene/facet/search/ScoredDocIdCollector.java +++ b/modules/facet/src/java/org/apache/lucene/facet/search/ScoredDocIdCollector.java @@ -3,7 +3,7 @@ package org.apache.lucene.facet.search; import java.io.IOException; import org.apache.lucene.index.IndexReader; -import org.apache.lucene.index.IndexReader.AtomicReaderContext; +import org.apache.lucene.index.AtomicIndexReader.AtomicReaderContext; import org.apache.lucene.search.Collector; import org.apache.lucene.search.DocIdSet; import org.apache.lucene.search.DocIdSetIterator; diff --git a/modules/facet/src/java/org/apache/lucene/facet/taxonomy/directory/DirectoryTaxonomyReader.java b/modules/facet/src/java/org/apache/lucene/facet/taxonomy/directory/DirectoryTaxonomyReader.java index 93760c35a5c..cf713a83554 100644 --- a/modules/facet/src/java/org/apache/lucene/facet/taxonomy/directory/DirectoryTaxonomyReader.java +++ b/modules/facet/src/java/org/apache/lucene/facet/taxonomy/directory/DirectoryTaxonomyReader.java @@ -15,6 +15,7 @@ import org.apache.lucene.facet.taxonomy.InconsistentTaxonomyException; import org.apache.lucene.facet.taxonomy.TaxonomyReader; import org.apache.lucene.facet.taxonomy.directory.Consts.LoadFullPathOnly; import org.apache.lucene.index.CorruptIndexException; +import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.DocsEnum; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.MultiFields; @@ -58,7 +59,7 @@ public class DirectoryTaxonomyReader implements TaxonomyReader { private static final Logger logger = Logger.getLogger(DirectoryTaxonomyReader.class.getName()); - private IndexReader indexReader; + private DirectoryReader indexReader; // The following lock is used to allow multiple threads to read from the // index concurrently, while having them block during the very short @@ -126,7 +127,7 @@ public class DirectoryTaxonomyReader implements TaxonomyReader { parentArray.refresh(indexReader); } - protected IndexReader openIndexReader(Directory directory) throws CorruptIndexException, IOException { + protected DirectoryReader openIndexReader(Directory directory) throws CorruptIndexException, IOException { return IndexReader.open(directory); } @@ -353,7 +354,7 @@ public class DirectoryTaxonomyReader implements TaxonomyReader { // safely read indexReader without holding the write lock, because // no other thread can be writing at this time (this method is the // only possible writer, and it is "synchronized" to avoid this case). - IndexReader r2 = IndexReader.openIfChanged(indexReader); + DirectoryReader r2 = DirectoryReader.openIfChanged(indexReader); if (r2 == null) { return false; // no changes, nothing to do } diff --git a/modules/facet/src/java/org/apache/lucene/facet/taxonomy/directory/DirectoryTaxonomyWriter.java b/modules/facet/src/java/org/apache/lucene/facet/taxonomy/directory/DirectoryTaxonomyWriter.java index 89ce05939a4..f18b3d37af8 100644 --- a/modules/facet/src/java/org/apache/lucene/facet/taxonomy/directory/DirectoryTaxonomyWriter.java +++ b/modules/facet/src/java/org/apache/lucene/facet/taxonomy/directory/DirectoryTaxonomyWriter.java @@ -22,6 +22,7 @@ import org.apache.lucene.document.FieldType; import org.apache.lucene.document.StringField; import org.apache.lucene.document.TextField; import org.apache.lucene.index.CorruptIndexException; +import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.DocsEnum; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexWriter; @@ -112,7 +113,7 @@ public class DirectoryTaxonomyWriter implements TaxonomyWriter { * that some of the cached data was cleared). */ private boolean cacheIsComplete; - private IndexReader reader; + private DirectoryReader reader; private int cacheMisses; /** @@ -188,7 +189,7 @@ public class DirectoryTaxonomyWriter implements TaxonomyWriter { throws CorruptIndexException, LockObtainFailedException, IOException { - if (!IndexReader.indexExists(directory) || openMode==OpenMode.CREATE) { + if (!DirectoryReader.indexExists(directory) || openMode==OpenMode.CREATE) { taxoIndexCreateTime = Long.toString(System.nanoTime()); } @@ -281,7 +282,7 @@ public class DirectoryTaxonomyWriter implements TaxonomyWriter { * calling {@link IndexReader#open(IndexWriter, boolean)}. Extending classes can override * this method to return their own {@link IndexReader}. */ - protected IndexReader openReader() throws IOException { + protected DirectoryReader openReader() throws IOException { return IndexReader.open(indexWriter, true); } @@ -618,7 +619,7 @@ public class DirectoryTaxonomyWriter implements TaxonomyWriter { private synchronized void refreshReader() throws IOException { if (reader != null) { - IndexReader r2 = IndexReader.openIfChanged(reader); + DirectoryReader r2 = DirectoryReader.openIfChanged(reader); if (r2 != null) { reader.close(); reader = r2; diff --git a/modules/facet/src/test/org/apache/lucene/facet/FacetTestUtils.java b/modules/facet/src/test/org/apache/lucene/facet/FacetTestUtils.java index 26fac846398..9c60f8d1ef0 100644 --- a/modules/facet/src/test/org/apache/lucene/facet/FacetTestUtils.java +++ b/modules/facet/src/test/org/apache/lucene/facet/FacetTestUtils.java @@ -9,6 +9,7 @@ import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.document.TextField; import org.apache.lucene.index.CorruptIndexException; +import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.IndexWriterConfig; @@ -133,7 +134,7 @@ public class FacetTestUtils { } public static class IndexTaxonomyReaderPair { - public IndexReader indexReader; + public DirectoryReader indexReader; public TaxonomyReader taxReader; public IndexSearcher indexSearcher; diff --git a/modules/facet/src/test/org/apache/lucene/facet/search/TestTotalFacetCountsCache.java b/modules/facet/src/test/org/apache/lucene/facet/search/TestTotalFacetCountsCache.java index 01cb066dda4..a3299e2d819 100644 --- a/modules/facet/src/test/org/apache/lucene/facet/search/TestTotalFacetCountsCache.java +++ b/modules/facet/src/test/org/apache/lucene/facet/search/TestTotalFacetCountsCache.java @@ -9,6 +9,7 @@ import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.analysis.MockTokenizer; import org.apache.lucene.document.Document; import org.apache.lucene.index.CorruptIndexException; +import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.IndexWriterConfig; @@ -299,7 +300,7 @@ public class TestTotalFacetCountsCache extends LuceneTestCase { writers[0].taxWriter.close(); readers[0].taxReader.refresh(); - IndexReader r2 = IndexReader.openIfChanged(readers[0].indexReader); + DirectoryReader r2 = DirectoryReader.openIfChanged(readers[0].indexReader); assertNotNull(r2); // Hold on to the 'original' reader so we can do some checks with it IndexReader origReader = null; diff --git a/modules/facet/src/test/org/apache/lucene/facet/taxonomy/directory/TestDirectoryTaxonomyWriter.java b/modules/facet/src/test/org/apache/lucene/facet/taxonomy/directory/TestDirectoryTaxonomyWriter.java index a9cbf5e7ddd..2fec3dcf8ba 100644 --- a/modules/facet/src/test/org/apache/lucene/facet/taxonomy/directory/TestDirectoryTaxonomyWriter.java +++ b/modules/facet/src/test/org/apache/lucene/facet/taxonomy/directory/TestDirectoryTaxonomyWriter.java @@ -3,6 +3,7 @@ package org.apache.lucene.facet.taxonomy.directory; import java.util.HashMap; import java.util.Map; +import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexWriterConfig.OpenMode; import org.apache.lucene.store.AlreadyClosedException; @@ -54,7 +55,7 @@ public class TestDirectoryTaxonomyWriter extends LuceneTestCase { // commit() wasn't called. Directory dir = newDirectory(); DirectoryTaxonomyWriter ltw = new DirectoryTaxonomyWriter(dir, OpenMode.CREATE_OR_APPEND, new NoOpCache()); - assertFalse(IndexReader.indexExists(dir)); + assertFalse(DirectoryReader.indexExists(dir)); ltw.commit(); // first commit, so that an index will be created ltw.addCategory(new CategoryPath("a")); @@ -70,7 +71,7 @@ public class TestDirectoryTaxonomyWriter extends LuceneTestCase { // Verifies that committed data is retrievable Directory dir = newDirectory(); DirectoryTaxonomyWriter ltw = new DirectoryTaxonomyWriter(dir, OpenMode.CREATE_OR_APPEND, new NoOpCache()); - assertFalse(IndexReader.indexExists(dir)); + assertFalse(DirectoryReader.indexExists(dir)); ltw.commit(); // first commit, so that an index will be created ltw.addCategory(new CategoryPath("a")); ltw.addCategory(new CategoryPath("b")); @@ -78,7 +79,7 @@ public class TestDirectoryTaxonomyWriter extends LuceneTestCase { userCommitData.put("testing", "1 2 3"); ltw.commit(userCommitData); ltw.close(); - IndexReader r = IndexReader.open(dir); + DirectoryReader r = IndexReader.open(dir); assertEquals("2 categories plus root should have been committed to the underlying directory", 3, r.numDocs()); Map readUserCommitData = r.getCommitUserData(); assertTrue("wrong value extracted from commit data",