 ;; and have the end result attached to the primary index
 ;; somehow
 
+(defn adjunctivize [name-map]
+  (reduce
+   (fn [m [attr tok]]
+     (assoc m attr (make-adjunct-index name-map (:tokenize-tags tok))))
+   {}
+   adjuncts))
+
 ;; XXX async updates have to fit into this somehow eventually
 
-;;;
+(defn query-adjunct [index adjunct-name string]
+  (let [tokenizer (:tokenize-query (get adjuncts adjunct-name))
+        tokens (tokenizer string)
+        adjunct-map (get (:adjuncts index) adjunct-name)
+        matches (map #(get adjunct-map %) tokens)]
+    ;; we want to return a collection of pathnames ordered by the number
+    ;; of elements of matches that each appears within
+    (let [num-matches (fn [file]
+                        (count (filter #(contains? % file) matches)))]
+      (sort-by num-matches (set/union matches)))))
+
+
 ;; the main index maps from pathname to hash of tags
 
 (defn open-index [name]

(ns sledge.db
  (:import [java.util Date])
  (:require [clojure.java.io :as io]
            [clojure.edn :as edn]
            [clojure.string :as str])  )



              (reduce (fn [m [k v]] (assoc m k v))
                      {}
                      (take-while identity forms))))
          {})
        adjunct-maps (adjunctivize name-map)
        ]
    (or (.isDirectory folder) (.mkdir folder))
    (or (.exists logfile) (.createNewFile logfile))
    {:folder folder :log logfile :data (atom name-map) :adjuncts adjunct-maps}
    ))

(defonce the-index (atom nil))
