A problem with add-to-index

28 views
Skip to first unread message

Andy Dwelly

unread,
Dec 11, 2013, 11:14:09 AM12/11/13
to clojur...@googlegroups.com
My group made the very recent decision to start using clojure with the Neo4j database and the Neocons library, and we've managed to make significant progress despite less than 3 days effort. I mention this because the problem that I'm about to describe may be rather naive. That said, any guidance would be welcome.

To put the example in a nutshell, assuming that the index email-idx does not exist in the neo4j database, the following example returns () for me:

(ns example.core
  (:require [clojurewerkz.neocons.rest       :as nr]
            [clojurewerkz.neocons.rest.nodes :as nn]))

(defn -main [& args]
  (let [node (nn/create {:email "fer...@example.com" :name "Andy"})]
    (nn/add-to-index node "email-idx" "email" node)
    (nn/find "email-idx" "email" "fer...@example.com")))

This is supposed to connect to the database, create a map with :email and :name keywords, create a node from that using nn/create, adds it to an index "email-idx" and then immediately tries to find the node via the index.

What's wrong here ?


Michael Hunger

unread,
Dec 15, 2013, 7:28:50 PM12/15/13
to clojur...@googlegroups.com
Andy,

you can see that you use add-to-index incorrectly: it should be (nn/add-to-index node-id index-name key value)

Michael

To add a node to an index, use clojurewerkz.neocons.rest.nodes/add-to-index. To remove a node from an index, use clojurewerkz.neocons.rest.nodes/delete-from-index.

(ns neocons.docs.examples

  (:require [clojurewerkz.neocons.rest :as nr]
            [clojurewerkz.neocons.rest.nodes :as nn]))

(defn -main
  [& args]
  (nr/connect! "http://localhost:7474/db/data/")

  (let [idx  (nn/create-index "by-username")
        node (nn/create {:username "joe"})]
    (nn/add-to-index (:id node) (:name idx) "username" "joe")))

--
Documentation: http://clojureneo4j.info
Issues: https://github.com/michaelklishin/neocons/issues
 
More Clojure libraries: http://clojurewerkz.org
---
You received this message because you are subscribed to the Google Groups "clojure-neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure-neo4...@googlegroups.com.
Visit this group at http://groups.google.com/group/clojure-neo4j.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages