Skip to content

Instantly share code, notes, and snippets.

@amalloy
Created March 14, 2011 02:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amalloy/868661 to your computer and use it in GitHub Desktop.
Save amalloy/868661 to your computer and use it in GitHub Desktop.
(defmacro add-field [document field]
(let [fstr (str field)]
`(.add document (Field. ~fstr ~field
Field$Store/YES Field$Index/ANALYZED))))
(defn create-document
[json]
(let [age (NumericField. "age" Field$Store/YES true)
vintage (NumericField. "vintage" Field$Store/YES true)
document (Document.)
{:keys [age vintage title distillery bottler]} (:value json)]
(when age
(.setIntValue age (int age)))
(when vintage
(.setIntValue vintage (int vintage)))
(doto document
(add-field title)
(add-field distillery)
(add-field bottler)
(.add age)
(.add vintage))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment