         (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)

(defn new-taxo-reader ^DirectoryTaxonomyReader [name]
  (DirectoryTaxonomyReader. (new-index-directory (taxo-dir-prefix name) "__taxo__")))

(defn new-index-reader ^IndexReader [name]
  (with-open [writer (new-index-writer name)]
    (DirectoryReader/open ^IndexWriter writer false)))

(defn sharded [index x-shard]
  (let [shard (int-or-parse x-shard)]
    (str (as-str index) shard-suffix (str shard))))

(defn reset-search-managers []
  (doseq [[name ^SearcherManager manager] @name->smanager*]
    (log/info "\tclosing: " name " " manager)
    (.close manager))
  (reset! name->smanager* {}))

(defn use-taxo-reader [index callback]
  ;; FIXME: reuse
  (let [reader (try
                 (new-taxo-reader index)
                 (catch Throwable e
                   (do
                     (log/warn (ex-str e))
                     nil)))]
    (try
      (callback reader)
      (finally (if reader
                 (.close ^DirectoryTaxonomyReader reader))))))

(defn use-searcher [index callback]
  (let [manager (get-search-manager index)
        searcher ^IndexSearcher (.acquire manager)]
    (try
      (use-taxo-reader index (fn [^DirectoryTaxonomyReader reader] (callback searcher reader)))
      (finally (.release manager searcher)))))

(defn log-close-err [^Directory dir ^Throwable e]

           (org.apache.lucene.facet.taxonomy.directory DirectoryTaxonomyWriter DirectoryTaxonomyReader)
           (org.apache.lucene.index IndexWriter IndexReader IndexWriterConfig DirectoryReader)
           (org.apache.lucene.search Query ScoreDoc SearcherManager IndexSearcher)
           (org.apache.lucene.store NIOFSDirectory Directory NoSuchDirectoryException)))

(declare use-searcher)
(declare use-writer)
(declare bootstrap-indexes)
(declare get-smanager-taxo)
(declare try-close-manager-taxo)

(def root* (atom default-root))
(def identifier* (atom default-identifier))
(def name->smanager-taxo* (atom {}))

(def acceptable-name-pattern (re-pattern "[^a-zA-Z_0-9-]"))
(def shard-suffix "-shard-")
