Skip to content

Instantly share code, notes, and snippets.

@c-spencer
Created July 14, 2010 21:29
Show Gist options
  • Save c-spencer/476114 to your computer and use it in GitHub Desktop.
Save c-spencer/476114 to your computer and use it in GitHub Desktop.
(def *tx* nil)
(def *lucene*) ; def'd during startup
(defmacro with-tx [& body]
`(binding [*tx* (.beginTx *neo*)]
(try
(let [val# (do ~@body)]
(.success *tx*)
val#)
(finally (.finish *tx*)))))
(defn neo-lookup [index-service index-name search]
"neo-lookup takes an index name and a search term and returns a sequence of nodes."
(iterator-seq (.getNodes index-service (name-or-str index-name) (name-or-str search))))
; Basic query
(with-tx
(iterator-seq (.getNodes *lucene* "class" "Person")))
; "Out of transaction" error.
; Without the iterator-seq
(with-tx
(.getNodes *lucene* "class" "Person"))
; org.neo4j.index.impl.SimpleIndexHits@2e71207
; With an into, gives expected result.
(with-tx
(into () (.getNodes *lucene* "class" "Person")))
;(#<NodeProxy Node[12]> ... #<NodeProxy Node[1]>)
; Original also now gives the expected.
(with-tx
(iterator-seq (.getNodes *lucene* "class" "Person")))
; (#<NodeProxy Node[12]> ... #<NodeProxy Node[1]>)
; Seems to work in general now.
(with-tx
(iterator-seq (.getNodes *lucene* "class" "Test")))
; (#<NodeProxy Node[15]> ... #<NodeProxy Node[18]>)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment