 (ns clucy
   (:use clojure.contrib.java-utils)
+  (:import java.io.File)
   (:import org.apache.lucene.document.Document)
   (:import (org.apache.lucene.document Field, Field$Store, Field$Index))
   (:import (org.apache.lucene.index IndexWriter, IndexWriter$MaxFieldLength))
   (:import org.apache.lucene.analysis.standard.StandardAnalyzer)
   (:import org.apache.lucene.queryParser.QueryParser)
   (:import org.apache.lucene.search.IndexSearcher)
-  (:import org.apache.lucene.store.RAMDirectory)
+  (:import (org.apache.lucene.store RAMDirectory, NIOFSDirectory))
   (:import org.apache.lucene.util.Version))
 
 (def *version*  Version/LUCENE_30)

(defn- document->map
  "Turn a Document object into a map."
  [document]
  (into {}
    (for [f (.getFields document)]
      [(keyword (.name f)) (.stringValue f)])))

(defn search
  "Search the supplied index with a query string."
  [index query max-results default-field]
  (with-open [searcher (IndexSearcher. index)]
    (let [parser (QueryParser. *version* (as-str default-field) *analyzer*)
          query  (.parse parser query)
          hits   (.search searcher query max-results)]
      (doall
        (for [hit (.scoreDocs hits)]
          (document->map (.doc searcher (.doc hit))))))))

  "Create a new index in RAM."
  []
  (RAMDirectory.))

(defn disk-index
  "Create a new index in a directory on disk."
  [dir-path]
  (NIOFSDirectory. (File. dir-path)))

(defn- index-writer
  "Create an IndexWriter."
