 (defn- number-processor []
   (.availableProcessors (Runtime/getRuntime)))
 
-(defn- get-root-path ^String []
+(defn- root-path ^String []
   (.getSourceRootPath env))
 
-(defn- get-data-root-path ^String []
+(defn- data-root-path ^String []
   (.getDataRootFile env))
 
 (defn- hits-per-page []
   (.getHitsPerPage env))
 
-(defn- get-sort ^Sort [opts]
+(defn- get-sort [opts]
   (let [sort (:sort opts)]
     (cond
       (= sort "date") (Sort. (SortField. "date" SortField$Type/STRING true))
       (= sort "path") (Sort. (SortField. "fullpath" SortField$Type/STRING))
       :else (Sort/RELEVANCE))))
 
-(defn- query-builder ^QueryBuilder [opts]
+(defn- query-builder [opts]
   (let [qb (QueryBuilder.)]
     (doto qb
       (.setDefs (:def opts))

    (doseq [h hit]
      (print-hit h))))

(defn- hits [docs ^Query query ^QueryBuilder qb]
  (remove nil? (flatten (map #(hit % query qb) docs))))

(defn- close [^IndexSearcher searcher]
  (IOUtils/close ^IndexReader (.getIndexReader searcher))
  (when @executor
    (.shutdown ^ExecutorService @executor)))

(defn- search-page [opts]
  (let [qb (query-builder opts)
        query (.build qb)
        searcher (searcher)
        fdocs (fdocs searcher query opts)
        total-page (total-page fdocs)
        documents (documents searcher fdocs
                             (assoc opts :total-page total-page))
        hits (hits documents query qb)
        close (close searcher)]
    {:total-page total-page :page (:page opts)}))

(defn search [opts]
  (read-configuration (:conf opts))
  (let [context (search-page (assoc opts :page 1))
        total-page (:total-page context)]
    (doseq [page (range 2 (inc total-page))]
      (search-page (assoc opts :page page)))))

      (when (= "p" (.get doc "t"))
        (.getContext scontext
                     (InputStreamReader.
                      (FileInputStream. (str (root-path) file)))
                     nil nil nil file nil false false hit))

      (not (.isEmpty hcontext))
      (.getContext hcontext
                   (str (root-path) file) file hit)

      :else
      (.add hit (Hit. file "..." "1" false true)))
