Skip to content

Instantly share code, notes, and snippets.

@c-spencer
Created August 11, 2010 21:45
Show Gist options
  • Save c-spencer/519833 to your computer and use it in GitHub Desktop.
Save c-spencer/519833 to your computer and use it in GitHub Desktop.
(defn register-classed-indices [classes]
(transaction-handler
(afterCommit [_ data state] nil)
(beforeCommit [_ data]
(let [remnodes (into {} (map (fn [^Node node] [(.getId node) {}]) (.deletedNodes data)))
rnodes (reduce (fn [props ^PropertyEntry removal] (update-in props [(.getId ^Node (.entity removal))] assoc (.key removal) (.previouslyCommitedValue removal))) remnodes (filter #(contains? remnodes (.getId ^Node (.entity ^PropertyEntry %))) (.removedNodeProperties data)))]
(doseq [^PropertyEntry removal (.removedNodeProperties data)]
(let [entity ^Node (.entity removal)
key (.key removal)
entity-id (.getId entity)
class (if (contains? remnodes entity-id) ((rnodes entity-id) "__CLASS") (if (.hasProperty entity "__CLASS") (.getProperty entity "__CLASS")))]
(when (and class (contains? (classes class) key))
(.removeIndex *lucene* entity (str class "__" key))))))
(doseq [^PropertyEntry assign (.assignedNodeProperties data)]
(let [entity ^Node (.entity assign)
key (.key assign)
class (if (.hasProperty entity "__CLASS") (.getProperty entity "__CLASS"))
previous-value (.previouslyCommitedValue assign)]
(when (and class (contains? (classes class) key))
(when previous-value
(.removeIndex *lucene* entity (str class "__" key )))
(.index *lucene* entity (str class "__" key) (.value assign))))))
(afterRollback [_ data state] nil)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment