Index: src/java/org/apache/lucene/facet/taxonomy/lucene/LuceneTaxonomyReader.java
===================================================================
--- src/java/org/apache/lucene/facet/taxonomy/lucene/LuceneTaxonomyReader.java	(revision 1178826)
+++ src/java/org/apache/lucene/facet/taxonomy/lucene/LuceneTaxonomyReader.java	(working copy)
@@ -14,6 +14,7 @@
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.TermDocs;
+import org.apache.lucene.store.AlreadyClosedException;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.store.FSDirectory;
 
@@ -98,6 +99,8 @@
 
   private char delimiter = Consts.DEFAULT_DELIMITER;
 
+  private volatile boolean closed = false;
+  
   /**
    * Open for reading a taxonomy stored in a given {@link Directory}.
    * @param directory
@@ -125,41 +128,16 @@
     return IndexReader.open(directory);
   }
 
-  // convenience constructors... deprecated because they cause confusion
-  // because they use parent directory instead of the actual directory.
-  private Directory ourDirectory = null; // remember directory to close later, but only if we opened it here
   /**
-   * Open for reading a taxonomy stored in a subdirectory of a given
-   * directory on the file system.
-   * @param parentDir The parent directory of the taxonomy's directory
-   * (usually this would be the directory holding the index).
-   * @param name The name of the taxonomy, and the subdirectory holding it. 
-   * @throws CorruptIndexException if the Taxonomy is corrupted.
-   * @throws IOException if another error occurred.
-   */  
-  @Deprecated
-  public LuceneTaxonomyReader(File parentDir, String name)
-  throws CorruptIndexException, IOException {
-    this(FSDirectory.open(new File(parentDir, name)));
-    ourDirectory = indexReader.directory(); // remember to close the directory we opened
+   * @throws AlreadyClosedException if this IndexReader is closed
+   */
+  protected final void ensureOpen() throws AlreadyClosedException {
+    if (closed || indexReader.getRefCount() <= 0) {
+      throw new AlreadyClosedException("this TaxonomyReader is closed");
+    }
   }
-
+  
   /**
-   * Open for reading a taxonomy stored in a subdirectory of a given
-   * directory on the file system.
-   * @param parentDir The parent directory of the taxonomy's directory.
-   * @param name The name of the taxonomy, and the subdirectory holding it. 
-   * @throws CorruptIndexException if the Taxonomy is corrupted.
-   * @throws IOException if another error occurred.
-   */  
-  @Deprecated
-  public LuceneTaxonomyReader(String parentDir, String name)
-  throws CorruptIndexException, IOException {
-    this(FSDirectory.open(new File(parentDir, name)));
-    ourDirectory = indexReader.directory(); // rememebr to close the directory we opened
-  }
-
-  /**
    * setCacheSize controls the maximum allowed size of each of the caches
    * used by {@link #getPath(int)} and {@link #getOrdinal(CategoryPath)}.
    * <P>
@@ -169,6 +147,7 @@
    * @param size the new maximum cache size, in number of entries.
    */
   public void setCacheSize(int size) {
+    ensureOpen();
     synchronized(getCategoryCache) {
       getCategoryCache.setMaxSize(size);
     }
@@ -188,10 +167,12 @@
    * LuceneTaxonomyReader objects you create.
    */
   public void setDelimiter(char delimiter) {
+    ensureOpen();
     this.delimiter = delimiter;
   }
 
   public int getOrdinal(CategoryPath categoryPath) throws IOException {
+    ensureOpen();
     if (categoryPath.length()==0) {
       return ROOT_ORDINAL;
     }
@@ -233,6 +214,7 @@
   }
 
   public CategoryPath getPath(int ordinal) throws CorruptIndexException, IOException {
+    ensureOpen();
     // TODO (Facet): Currently, the LRU cache we use (getCategoryCache) holds
     // strings with delimiters, not CategoryPath objects, so even if
     // we have a cache hit, we need to process the string and build a new
@@ -249,6 +231,7 @@
   }
 
   public boolean getPath(int ordinal, CategoryPath result) throws CorruptIndexException, IOException {
+    ensureOpen();
     String label = getLabel(ordinal);
     if (label==null) {
       return false;
@@ -259,6 +242,7 @@
   }
 
   private String getLabel(int catID) throws CorruptIndexException, IOException {
+    ensureOpen();
     // First try to find the answer in the LRU cache. It is very
     // unfortunate that we need to allocate an Integer object here -
     // it would have been better if we used a hash table specifically
@@ -307,6 +291,7 @@
   }
 
   public int getParent(int ordinal) {
+    ensureOpen();
     // Note how we don't need to hold the read lock to do the following,
     // because the array reference is volatile, ensuring the correct
     // visibility and ordering: if we get the new reference, the new
@@ -337,6 +322,7 @@
    */
 
   public int[] getParentArray() {
+    ensureOpen();
     // Note how we don't need to hold the read lock to do the following,
     // because the array reference is volatile, ensuring the correct
     // visibility and ordering: if we get the new reference, the new
@@ -348,6 +334,7 @@
   // method in this class) to ensure that it never gets called concurrently
   // with itself.
   public synchronized void refresh() throws IOException {
+    ensureOpen();
     /*
      * Since refresh() can be a lengthy operation, it is very important that we
      * avoid locking out all readers for its duration. This is why we don't hold
@@ -409,13 +396,27 @@
   }
 
   public void close() throws IOException {
-    indexReader.close();
-    if (ourDirectory!=null) {
-      ourDirectory.close();
+    if (!closed) {
+      decRef();
+      closed = true;
     }
+    
   }
+  
+  /** Actually close this {@link TaxonomyReader}, free up resources */
+  void doClose() throws IOException {
+    closed = true;
+    indexReader.close();
+    indexReader = null;
 
+    parentArray = null;
+    childrenArrays = null;
+    getCategoryCache.clear();
+    getOrdinalCache.clear();
+  }
+
   public int getSize() {
+    ensureOpen();
     indexReaderLock.readLock().lock();
     try {
       return indexReader.numDocs();
@@ -425,6 +426,7 @@
   }
 
   public Map<String, String> getCommitUserData() {
+    ensureOpen();
     return indexReader.getCommitUserData();
   }
   
@@ -432,6 +434,7 @@
   Object childrenArraysRebuild = new Object();
 
   public ChildrenArrays getChildrenArrays() {
+    ensureOpen();
     // Check if the taxonomy grew since we built the array, and if it
     // did, create new (and larger) arrays and fill them as required.
     // We do all this under a lock, two prevent to concurrent calls to
@@ -485,6 +488,7 @@
   }
 
   public String toString(int max) {
+    ensureOpen();
     StringBuilder sb = new StringBuilder();
     int upperl = Math.min(max, this.indexReader.maxDoc());
     for (int i = 0; i < upperl; i++) {
@@ -530,6 +534,7 @@
    * @return lucene indexReader
    */
   IndexReader getInternalIndexReader() {
+    ensureOpen();
     return this.indexReader;
   }
 
@@ -540,13 +545,19 @@
    * @throws IOException 
    */
   public void decRef() throws IOException {
-    this.indexReader.decRef();
+    ensureOpen();
+    if (indexReader.getRefCount() == 1) {
+      doClose();
+    } else {
+      indexReader.decRef();
+    }
   }
   
   /**
    * Expert: returns the current refCount for this taxonomy reader
    */
   public int getRefCount() {
+    ensureOpen();
     return this.indexReader.getRefCount();
   }
   
@@ -558,6 +569,7 @@
    * otherwise the reader may never be closed. 
    */
   public void incRef() {
+    ensureOpen();
     this.indexReader.incRef();
   }
 }
