            (org.apache.lucene.store FSDirectory)
            (org.apache.lucene.util Version)
            (org.apache.lucene.queryParser QueryParser$Operator
+                                          QueryParser
                                           MultiFieldQueryParser)
            (java.net ServerSocket InetAddress BindException)
            (java.util Calendar Date SimpleTimeZone Vector Properties)

          ["and" "or" "not"]))


(defn build-query
  "Construct a Lucene query from `querystr'."
  [querystr reader]
  (let [query (BooleanQuery.)
        all-fields (.parse (doto (MultiFieldQueryParser.
                                  Version/LUCENE_30
                                  (into-array (keys parse-rules))
                                  (StandardAnalyzer. Version/LUCENE_30))
                             (.setDefaultOperator QueryParser$Operator/AND))
                           (normalcase querystr))]
    (.setBoost all-fields 20)
    (.add query all-fields BooleanClause$Occur/MUST)

    (when-let [terms (seq (set (map #(.getTerm %)

  (doseq [[field rule] parse-rules]
    (when (:value-fn rule)
      (when-let [value (try ((:value-fn rule) msg)
                            (catch Exception e
                              (error "Warning: missing value for field '%s': %s"
                                     field e)
                              nil))]
        (.add doc (fieldpool/tokenized-field field value))))))

