         (do
           (log-close-err (.getDirectory taxo) e)
           (DirectoryTaxonomyWriter/unlock (.getDirectory taxo)))))))
+
+(defn try-close-manager-taxo [^SearcherManager manager ^DirectoryTaxonomyReader taxo]
+  (try
+    (do
+      (try
+        (.close taxo)
+        (catch Exception e
+          (log/warn (as-str e))))
+      (.close manager))
+    (catch Exception e
+      (log/warn (as-str e)))))
+
 
 (defn use-writer [index callback]
   (let [writer (new-index-writer index)

  (try
    (doseq [dir (sub-directories)]
      (try
        (get-search-manager (.getName dir))
        (catch Exception e
          (log/warn (ex-str e)))))
    (catch Exception e
      (log/warn (ex-str e)))))

(defn get-search-manager ^SearcherManager [index]
  (locking name->smanager*
    (when (nil? (@name->smanager* index))
      (swap! name->smanager* assoc index (SearcherManager. (new-index-directory (root-identifier-path) index)
                                                    nil)))
    (@name->smanager* index)))

(defn refresh-search-managers []
  (bootstrap-indexes)
  (locking name->smanager*
    (doseq [[index ^SearcherManager manager] @name->smanager*]
      (log/debug "refreshing: " index " " manager)
      ;; FIXME - reopen cached taxo readers
      (try
        (.maybeRefresh manager)
        (catch Throwable e
          (do
            (log/info (str index " maybeRefresh exception, closing it. Exception: " (ex-str e)))
            (.close manager)
            (swap! name->smanager* dissoc index)))))))

(defn shutdown []
  (locking name->smanager*
    (log/info "executing shutdown hook, current mapping: " @name->smanager*)
    (reset-search-managers)
    (log/info "mapping after cleanup: " @name->smanager*)))

(defn index-stat []
  (into {} (for [[name searcher] @name->smanager*]
             [name (use-searcher name
                                 (fn [^IndexSearcher searcher ^DirectoryTaxonomyReader taxo-reader]
                                   (let [reader (.getIndexReader searcher)]
                                     {:docs (.numDocs reader)
                                      :has-deletions (.hasDeletions reader)})))])))

             (.toString dir)
             " Got exception while close()ing the writer,and directory is still locked."
             " Unlocking it. "
             "[ should never happen, there is a race between this IndexWriter/unlock "
             " and other process/thread IndexWriter/open ]"
             " Exception: " (ex-str e))))

(defn safe-close-writer [^IndexWriter writer]
