Created
March 14, 2011 02:12
-
-
Save amalloy/868661 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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